Open b2p-fred opened 2 years ago
Could it be that phpunit.xml contains invalid configuration for what to include in/exclude from code coverage?
Here is my phpunit.xml.dist 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="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
convertDeprecationsToExceptions="false"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<env name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
<server name="KERNEL_CLASS" value="App\Kernel" />
<!-- Set this variable to avoid many deprecation warning when running the tests:
- weak dumps the warning count
- disabled removes all the messages
Run `SYMFONY_DEPRECATIONS_HELPER= ./vendor/bin/phpunit`
-->
<server name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>
<testsuites>
<testsuite name="Utils tests">
<directory>tests/Utils</directory>
</testsuite>
<testsuite name="Unit tests">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="API tests">
<directory>tests/Api</directory>
</testsuite>
</testsuites>
<coverage includeUncoveredFiles="false" processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<text outputFile="artifacts/phpunit/coverage.txt" showUncoveredFiles="true" showOnlySummary="true"/>
</report>
</coverage>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
</phpunit>
When I run my unit tests with phpunit, I get correct code coverage. Do you have some specific requirements for as phpunit configuration. I did not see any except having correct inclusions ...
Sorry, I have no idea what may be wrong here. I'd recommend step-debugging. Maybe something has changed here: https://github.com/matthiasnoback/live-code-coverage/blob/master/src/LiveCodeCoverage/CodeCoverageFactory.php
This replicates part of PHPUnit itself, but maybe PHPUnit has diverged from this code.
I ran into the same problem, but I was able to solve it by adding the <filter>
and <whitelist>
tags to the phpunit.xml.dist
file. I guess that the coverage whitelist filter is empty by default which means that none of the files would be covered. Here's my phpunit.xml.dist
file for reference in case someone else will encounter the same issue.
<?xml version="1.0" encoding="utf-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<coverage>
<include>
<directory suffix=".php">source</directory>
</include>
</coverage>
<php>
<env name="XDEBUG_MODE" value="coverage"/>
</php>
<filter>
<whitelist>
<directory suffix=".php">source</directory>
</whitelist>
</filter>
</phpunit>
In a fresh Docker container (alpine linux php-fpm 8.0) I executed the following commands :
With this procedure the tests results show no coverage at all !
Note that the problem that I encountered in #20 disappeared!
The application main controller:
One of the .cov produced files (I do not know if it may help?) :
return \unserialize(<<<'END_OF_COVERAGE_SERIALIZATION' O:43:"SebastianBergmann\CodeCoverage\CodeCoverage":15:{s:51:" SebastianBergmann\CodeCoverage\CodeCoverage driver";O:48:"SebastianBergmann\CodeCoverage\Driver\PcovDriver":3:{s:56:" SebastianBergmann\CodeCoverage\Driver\PcovDriver filter";O:37:"SebastianBergmann\CodeCoverage\Filter":2:{s:44:" SebastianBergmann\CodeCoverage\Filter files";a:63:{s:40:"/var/www/src/Action/GetVersionAction.php";b:1;s:50:"/var/www/src/Command/DriverHistoryPurgeCommand.php";b:1;s:43:"/var/www/src/Command/UsersCreateCommand.php";b:1;s:43:"/var/www/src/Command/UsersDeleteCommand.php";b:1;s:41:"/var/www/src/Command/UsersListCommand.php";b:1;s:46:"/var/www/src/Controller/DocumentController.php";b:1;s:44:"/var/www/src/Controller/DriverController.php";b:1;s:42:"/var/www/src/Controller/UserController.php";b:1;s:40:"/var/www/src/DBAL/Types/BaseEnumType.php";b:1;s:39:"/var/www/src/DBAL/Types/ContactType.php";b:1;s:46:"/var/www/src/DBAL/Types/DocumentStatusType.php";b:1;s:40:"/var/www/src/DBAL/Types/DocumentType.php";b:1;s:43:"/var/www/src/DBAL/Types/HumanGenderType.php";b:1;s:40:"/var/www/src/DBAL/Types/LanguageType.php";b:1;s:44:"/var/www/src/DBAL/Types/NotificationType.php";b:1;s:41:"/var/www/src/DataFixtures/AppFixtures.php";b:1;s:46:"/var/www/src/Doctrine/ContactPhoneListener.php";b:1;s:47:"/var/www/src/Doctrine/DocumentAnnexListener.php";b:1;s:50:"/var/www/src/Doctrine/DocumentReceivedListener.php";b:1;s:48:"/var/www/src/Doctrine/DocumentStatusListener.php";b:1;s:45:"/var/www/src/Doctrine/DriverPhoneListener.php";b:1;s:46:"/var/www/src/Doctrine/HashPasswordListener.php";b:1;s:31:"/var/www/src/Entity/Address.php";b:1;s:31:"/var/www/src/Entity/Contact.php";b:1;s:32:"/var/www/src/Entity/Customer.php";b:1;s:32:"/var/www/src/Entity/Document.php";b:1;s:39:"/var/www/src/Entity/DocumentHistory.php";b:1;s:39:"/var/www/src/Entity/DocumentVersion.php";b:1;s:30:"/var/www/src/Entity/Driver.php";b:1;s:37:"/var/www/src/Entity/DriverHistory.php";b:1;s:36:"/var/www/src/Entity/Notification.php";b:1;s:28:"/var/www/src/Entity/Site.php";b:1;s:27:"/var/www/src/Entity/Tag.php";b:1;s:49:"/var/www/src/Entity/Traits/SenderReceiverName.php";b:1;s:28:"/var/www/src/Entity/User.php";b:1;s:45:"/var/www/src/EventListener/KernelListener.php";b:1;s:44:"/var/www/src/Filter/DocumentCustomFilter.php";b:1;s:51:"/var/www/src/Filter/DocumentHistoryCustomFilter.php";b:1;s:40:"/var/www/src/Filter/SiteCustomFilter.php";b:1;s:34:"/var/www/src/Filter/UuidFilter.php";b:1;s:43:"/var/www/src/Handler/UserMessageHandler.php";b:1;s:23:"/var/www/src/Kernel.php";b:1;s:46:"/var/www/src/Manager/ApiInformationManager.php";b:1;s:36:"/var/www/src/Message/UserMessage.php";b:1;s:37:"/var/www/src/OpenApi/JwtDecorator.php";b:1;s:41:"/var/www/src/OpenApi/VersionDecorator.php";b:1;s:45:"/var/www/src/Repository/AddressRepository.php";b:1;s:45:"/var/www/src/Repository/ContactRepository.php";b:1;s:46:"/var/www/src/Repository/CustomerRepository.php";b:1;s:53:"/var/www/src/Repository/DocumentHistoryRepository.php";b:1;s:46:"/var/www/src/Repository/DocumentRepository.php";b:1;s:53:"/var/www/src/Repository/DocumentVersionRepository.php";b:1;s:51:"/var/www/src/Repository/DriverHistoryRepository.php";b:1;s:44:"/var/www/src/Repository/DriverRepository.php";b:1;s:50:"/var/www/src/Repository/NotificationRepository.php";b:1;s:42:"/var/www/src/Repository/SiteRepository.php";b:1;s:41:"/var/www/src/Repository/TagRepository.php";b:1;s:42:"/var/www/src/Repository/UserRepository.php";b:1;s:45:"/var/www/src/Security/ApiKeyAuthenticator.php";b:1;s:47:"/var/www/src/Security/ApiLoginAuthenticator.php";b:1;s:35:"/var/www/src/Security/OAuthUser.php";b:1;s:42:"/var/www/src/Service/FileUploadService.php";b:1;s:35:"/var/www/src/Utils/HydrateTrait.php";b:1;}s:50:" SebastianBergmann\CodeCoverage\Filter isFileCache";a:0:{}}s:74:" SebastianBergmann\CodeCoverage\Driver\Driver collectBranchAndPathCoverage";b:0;s:60:" SebastianBergmann\CodeCoverage\Driver\Driver detectDeadCode";b:0;}s:51:" SebastianBergmann\CodeCoverage\CodeCoverage filter";r:3;s:51:" SebastianBergmann\CodeCoverage\CodeCoverage wizard";O:46:"SebastianBergmann\CodeUnitReverseLookup\Wizard":3:{s:59:" SebastianBergmann\CodeUnitReverseLookup\Wizard lookupTable";a:0:{}s:64:" SebastianBergmann\CodeUnitReverseLookup\Wizard processedClasses";a:0:{}s:66:" SebastianBergmann\CodeUnitReverseLookup\Wizard processedFunctions";a:0:{}}s:79:" SebastianBergmann\CodeCoverage\CodeCoverage checkForUnintentionallyCoveredCode";b:0;s:66:" SebastianBergmann\CodeCoverage\CodeCoverage includeUncoveredFiles";b:0;s:66:" SebastianBergmann\CodeCoverage\CodeCoverage processUncoveredFiles";b:1;s:65:" SebastianBergmann\CodeCoverage\CodeCoverage ignoreDeprecatedCode";b:0;s:54:" SebastianBergmann\CodeCoverage\CodeCoverage currentId";N;s:49:" SebastianBergmann\CodeCoverage\CodeCoverage data";O:56:"SebastianBergmann\CodeCoverage\ProcessedCodeCoverageData":2:{s:70:" SebastianBergmann\CodeCoverage\ProcessedCodeCoverageData lineCoverage";a:0:{}s:74:" SebastianBergmann\CodeCoverage\ProcessedCodeCoverageData functionCoverage";a:0:{}}s:74:" SebastianBergmann\CodeCoverage\CodeCoverage useAnnotationsForIgnoringCode";b:1;s:50:" SebastianBergmann\CodeCoverage\CodeCoverage tests";a:0:{}s:101:" SebastianBergmann\CodeCoverage\CodeCoverage parentClassesExcludedFromUnintentionallyCoveredCodeCheck";a:0:{}s:64:" SebastianBergmann\CodeCoverage\CodeCoverage coveredFileAnalyser";N;s:66:" SebastianBergmann\CodeCoverage\CodeCoverage uncoveredFileAnalyser";N;s:59:" SebastianBergmann\CodeCoverage\CodeCoverage cacheDirectory";N;} END_OF_COVERAGE_SERIALIZATION );