I have a symfony 6 project, which runs in a docker container with php 8.2. I use phpunit version 10.5
When I run my tests I get this output:
$ bin/phpunit
PHPUnit 10.5.5 by Sebastian Bergmann and contributors.
Runtime: PHP 8.2.12
Configuration: /var/www/phpunit.xml
............................................................... 63 / 222 ( 28%)
............................................................... 126 / 222 ( 56%)
.EEE........................................................... 189 / 222 ( 85%)
................................. 222 / 222 (100%)
Time: 00:20.429, Memory: 120.00 MB
Auth Data Extractor (App\Tests\UnitTests\Security\AuthDataExtractor)
✔ Get credentials admin 1 house
✔ Get credentials edit 2 house
[....]
Witness Service (App\Tests\UnitTests\Domain\WitnessService)
✔ Create
✔ Create no witness
✔ Update no previous witnesses
✔ Update replace previous witnesses
✔ Get collection
ERRORS!
Tests: 222, Assertions: 1866, Errors: 3.
All my test results are shown green as passed, but the EEE and the summary say, that I have three errors. Ok, but where are they?!
Before (I restarted that project after several weeks) when I had errors, phpunit gave me an output in which methods the problem was.
Even worse: if I run the tests by folders I get either no error or a single one. But when I narrow it down to single test files everything is green and no error is shown.
I did a composer update and even built the container from scratch but there is always at least on red E.
How can I find out in which test the errors occur?
This is my phpunit.xml configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php"
cacheResult="false"
executionOrder="default"
testdox="true"
displayDetailsOnTestsThatTriggerErrors="true"
cacheDirectory=".phpunit.cache">
<coverage/>
<php>
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="KERNEL_CLASS" value="App\Kernel"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<!--env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" /-->
<!-- ###+ nelmio/cors-bundle ### -->
<env name="CORS_ALLOW_ORIGIN" value="^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$"/>
</php>
<extensions>
<bootstrap class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
</extensions>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
I could find the errors, but I still cannot explain the behaviour.
I run phpstan and phpstan did show me my errors and after fixing then, they were also gone with phpunit.
Which still doesn't explain why phpunit didn't at least tell me the classes which had problems. Is that the correct behaviour?
Here is the phpstan output, which lead me to the errors:
$ bin/phpstan
Note: Using configuration file /var/www/phpstan.neon.
271/271 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------ --------------------------------------------------------------------------------------------------------------
Line src/Repository/ChargeRepository.php
------ --------------------------------------------------------------------------------------------------------------
111 Method App\Repository\ChargeRepository::createQueryForCriteria() should return Doctrine\ORM\QueryBuilder but
return statement is missing.
------ --------------------------------------------------------------------------------------------------------------
------ ----------------------------------------------------------------------------------------------
Line tests/UnitTests/Domain/SapService/CurrencyExchangeServiceTest.php
------ ----------------------------------------------------------------------------------------------
47 Instantiated class App\Serializer\CurrencyExchangeService not found.
💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
47 Property App\Tests\UnitTests\Domain\SapService\CurrencyExchangeServiceTest::$exchangeService
(App\Domain\SapService\CurrencyExchangeServiceInterface) does not accept
App\Serializer\CurrencyExchangeService.
------ ----------------------------------------------------------------------------------------------