Reputation: 209
When I run phpunit on my Symfony2 project, the tests always fail at first run:
$ phpunit -c app src/Project/MyBundle/Tests/Controller/SomeTest.php
PHPUnit 3.7.19 by Sebastian Bergmann.
Configuration read from src/main/app/phpunit.xml
E
Time: 1 second, Memory: 24.25Mb
There was 1 error:
1) Project\MyBundle\Tests\Controller\RegistrationTest::testStdRegistration
PHPUnit_Framework_Exception: PHP Fatal error: Interface 'Swift_Events_SendListener' not found in src/main/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Plugins/MessageLogger.php on line 19
PHP Stack trace:
PHP 1. {main}() -:0
PHP 2. require_once() -:542
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
If I then restart the tests, everything passes well. No errors. I figured that it all boils down to the existence of the file cache/test/appTestDebugProjectContainer.php This file does not exist before the tests run the first time. After this run, it is created and used in the following tests. I was always under the impressions that Symfony2 makes sure, all relevant files are created BEFORE the first test runs, but this seems not to be the case. So how can I solve this issue? Should I try to warm up the cache manually before the tests start or do I have to modify my tests in order to wait for the cache files to be created?
Upvotes: 2
Views: 556
Reputation: 52493
Warm up your test environment cache prior to executing the tests in order to avoid this error.
app/console cache:warmup --env=test
Upvotes: 2