Closed mrodikov closed 1 year ago
It's been more than a year and still no feedback on this one. I have exactly same issue, but for me it may not happen for some tests I get coverage report for. I've been trying to understand the difference between the OK and failing coverages but still no luck.
I managed to identify a more specific context for the error, when using phpcov's merge command. It seems the error is not related with the fact a "custom" autoloader is used, since I use the default composer's one.
Basically, if a file with a class is completely uncovered and when CodeCoverage::processUncoveredFilesFromFilter() takes care of including these, it just does include_once on the file. If a class defined in the file uses a trait, the trait inclusion will fail leading to "Fatal error: Trait 'Foo\Bar' not found in ...".
This might be caused by the fact that phpcov relies on its own spl_autoload_register() handler which has no knowledge of the user code base. When a trait is included by a class with "use Bar;" obviously it can't be found among the classes known to phpcov's autoloader.
@sebastianbergmann FYI
Had a similar experience. In my case I took a shortcut: added phpcov as a composer --dev dependency and afterwards all namespaces were resolved correctly.
@llupa how did you add it through Composer?
@swarrenwecareconnectorg regular composer require --dev phpunit/phpcov
and then call it via vendor/bin/phpcov merge [options and arguments]
Any update on this one? I have the same issue with the not found file.
/app # phpcov patch-coverage --path-prefix /app var/unit.cov var/patch.txt
phpcov 8.2.1 by Sebastian Bergmann.
Fatal error: Uncaught Error: Class "Symfony\Component\Console\Command\Command" not found in /app/src/Command/BackgroundTasksDaemonCommand.php:12
Stack trace:
#0 phar:///usr/local/bin/phpcov/phpunit/php-code-coverage/src/CodeCoverage.php(547): include_once()
#1 phar:///usr/local/bin/phpcov/phpunit/php-code-coverage/src/CodeCoverage.php(159): SebastianBergmann\CodeCoverage\CodeCoverage->processUncoveredFilesFromFilter()
#2 phar:///usr/local/bin/phpcov/src/PatchCoverage.php(39): SebastianBergmann\CodeCoverage\CodeCoverage->getData()
#3 phar:///usr/local/bin/phpcov/src/cli/PatchCoverageCommand.php(41): SebastianBergmann\PHPCOV\PatchCoverage->execute('var/unit.cov', 'var/patch.txt', '/app/')
#4 phar:///usr/local/bin/phpcov/src/cli/Application.php(51): SebastianBergmann\PHPCOV\PatchCoverageCommand->run(Object(SebastianBergmann\PHPCOV\Arguments))
#5 /usr/local/bin/phpcov(852): SebastianBergmann\PHPCOV\Application->run(Array)
#6 {main}
thrown in /app/src/Command/BackgroundTasksDaemonCommand.php on line 12
Superseded by #109, see https://github.com/sebastianbergmann/phpcov/issues/109#issuecomment-944345050.
(PHAR doesn't work for me with the above PHPUnit & PHPCov versions, coverage file produced by PHPUnit is loaded as "Incomplete" class in PHPCov)
Summary
When using a custom class loader and processUncoveredFiles="true", an error occurs in PHPCov due to inability to find the class.
Current behavior
How to reproduce
Expected behavior
HTML coverage report generated
Notes
The problem is that the custom autoloader is used, which can load Path_To_My_Real_Class classes from Path/To/My/Real/Class.php (obviously, the includePath option will not work here). PHPUnit uses a custom autoloader since I explicitly included it in bootstrap.php. PHPCov knows nothing about phpunit.xml or bootstrap.php, so it cannot find the class.