I am trying to test my symfony2 application using PHPUnit. I got one project where everything works as expected, but on my other project I have this strange behaviour that PHPUnit either stops executing the Test Suite randomly near the end of all tests and restarts or restarts the tests after finishing the Test Suite and writing the code coverage. Other times it runs normally.
Here is some output to make visible what is happening ( Test is restarting over and over):
PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ................................................................. 65 / 83 ( 78%) ...........PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ................................................................. 65 / 83 ( 78%) ...PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ................................................................. 65 / 83 ( 78%) ............PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ................................................................. 65 / 83 ( 78%) ............PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ................................................................. 65 / 83 ( 78%) .................. Time: 01:03, Memory: 43.00Mb OK (83 tests, 145 assertions) Writing code coverage data to XML file, this may take a moment. Generating code coverage report, this may take a moment.
Here is an example of the Test Suite restarting after executing all tests:
PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ................................................................. 65 / 83 ( 78%) .................. Time: 01:29, Memory: 53.25Mb OK (83 tests, 145 assertions) Writing code coverage data to XML file, this may take a moment. Generating code coverage report, this may take a moment. PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ................................................................. 65 / 83 ( 78%) ............PHPUnit 3.6.10 by Sebastian Bergmann.
As my other project runs without any problems, there must be some problem within my code. But I cannot figure out what possibly triggers this behaviour! The logs don't show nothing unexpected/strange.
EDIT
Yesterday, I noticed something strange: I decided to switch from MongoDB to MySQL because of some unrelated reasons. After the transition was done, all tests run without any problems. I tried it many times and I'm not able to reproduce it anymore. As this only happened with my functional tests, I tend to think that the problem was my WebTestCase class, which runs some commands to clear and rebuild the database. Maybe someone who also uses MongoDB can reproduce this behaviour?
PHPUnit is by default strict about tests that do not test anything. This check can be disabled by using the --dont-report-useless-tests option on the command line or by setting beStrictAboutTestsThatDoNotTestAnything="false" in PHPUnit’s configuration file.
PHPUnit can be strict about output during tests. This check can be enabled by using the --disallow-test-output option on the command line or by setting beStrictAboutOutputDuringTests="true" in PHPUnit’s configuration file.
A test that does not perform an assertion will be marked as risky when this check is enabled. Expectations on mock objects count as an assertion. PHPUnit can be strict about unintentionally covered code.
If the pattern is not enclosed in delimiters, PHPUnit will enclose the pattern in /delimiters. The test names to match will be in one of the following formats: TestNamespace\TestCaseClass::testMethod The default test name format is the equivalent of using the __METHOD__magic constant inside the test method.
I'd suggest to check the database servers connection limits and pools.
For example if you've got a max limit of 100 connections, and some of the tests leaves connections open ("leaks"), you'd hit the limits there.
That would also explain why sometimes it works and sometimes it hits the limit, as your database could handle other tasks simultaneously, so sometimes you hit the ceiling, other times when nothing else runs, you can successfully run your tests.
Check for persistent network connections and other external resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With