When I activate Xdebug and run a PHPUnit unittest this error occurs: ❌
Warning: assert(): assert($iterator instanceof FilterIterator) failed in [...]/vendor/phpunit/phpunit/src/Runner/Filter/Factory.php on line 57
[... some stack trace information ...]
Return value of PHPUnit\Runner\Filter\Factory::factory() must be an instance of FilterIterator, instance of PHPUnit\Framework\TestSuiteIterator returned
I'm using
PHPUnit 9.5.6 by Sebastian Bergmann and contributors.
Runtime: PHP 7.4.21 with Xdebug 2.8.0
The PHPUnit execution call (clued together with PhpStorm) looks like:
/usr/bin/php74.bin.cli
-dzend_extension=/usr/local/php74/lib/php/extensions/xdebug.so
-dxdebug.collect_params=5
-dxdebug.profiler_enable=on
-dxdebug.auto_trace=1 -dxdebug.trace_format=1
-dxdebug.collect_return=1 -ddisplay_errors=1
-ddisplay_startup_errors=1 -derror_reporting=E_ALL
-dmemory_limit=512M
[...]/vendor/phpunit/phpunit/phpunit
--coverage-filter [...]/src/
--bootstrap [...]/utils/unittest/bootstrap.php
--configuration [...]/utils/unittest/phpunit.xml
--filter "/(BasicsTest::testReturnBytes)( .*)?$/"
--test-suffix BasicsTest.php [...]/utils/unittest/basics --teamcity
Calling a simple php script with Xdebug activated works well. ✔️
/usr/bin/php74.bin.cli
-dzend_extension=/usr/local/php74/lib/php/extensions/xdebug.so
-dxdebug.collect_params=5
-dxdebug.profiler_enable=on -dxdebug.auto_trace=1
-dxdebug.trace_format=1 -dxdebug.collect_return=1
-ddisplay_errors=1 -ddisplay_startup_errors=1
-derror_reporting=E_ALL -dmemory_limit=512M ./test.php
Calling the unittests without Xdebug activated works well. ✔️
/usr/bin/php74.bin.cli
-dallow_url_fopen=1
[...]/vendor/phpunit/phpunit/phpunit
--no-coverage
--bootstrap [...]/utils/unittest/bootstrap.php
--configuration [...]/utils/unittest/phpunit.xml
--filter "/(BasicsTest::testReturnBytes)( .*)?$/"
--test-suffix BasicsTest.php [...]/utils/unittest/basics --teamcity
My phpunit.xml
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="bootstrap.php"
colors="true"
verbose="true">
<coverage>
<include>
<directory suffix=".php">../../../src/*</directory>
<directory suffix=".php">../../../some other dirs/*</directory>
</include>
<exclude>
<directory suffix=".php">../../../some other dirs/*</directory>
</exclude>
<report>
<html outputDirectory="./x_testresults" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<php>
<ini name="allow_url_fopen" value="On"/>
<ini name="memory_limit" value="5G"/>
<ini name="include_path" value="."/>
</php>
</phpunit>
The unittest
<?php
declare(strict_types = 1);
class BasicsTest extends PHPUnit\Framework\TestCase
{
function testReturnBytes(): void {
$this->assertSame(1, 1);
}
}
The docs say in https://phpunit.readthedocs.io/en/9.5/code-coverage-analysis.html#including-files that
It is mandatory to configure a filter for telling PHPUnit which source code files to include in the code coverage report. This can either be done using the --coverage-filter command line option or via the configuration file (see The Element).
This is what I did, see above. Also without setting a --coverage-filter parameter PHPUnit complains about missing filter information, so I added it.
For me it feels like the issue is related to the --coverage-filter parameter. The error message (see first code paragraph) says FilterIterator should be instance of PHPUnit\Framework\TestSuiteIterator but I don't know where to adjust this.
*in the XML? It looks like it breaks the syntax highlighting here on SO but I also think its not needed.