I have a symfony2 application and I'm using phpunit.
I have some unit tests where I use mocks to mock the AppKernel and functional tests which make "real" requests to the application. When running the unit tests or the functional tests alone, everything works fine.
It get's nasty when I want to run all tests at once. As soon as the unit tests are finished, phpunit stops, telling me:
Fatal error: Cannot redeclare class AppKernel in C:\Users\sebastian\workspace\ppInterface\app\AppKernel.php on line 35
PHPUnit does not reset everything by default, although it's possible.
Includes - the problem in your case - are not resetted (and cannot in one single process). A solution would be to use
require_once instead of
require, or to use process isolation either in your
phpunit.xml file or in the test case (
@runTestsInSeparateProcesses) or test method (
You can also influence the what is resetted between tests: