phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

FilterIterator should be instance of PHPUnit\Framework\TestSuiteIterator

Open powtac opened this issue 3 years ago • 1 comments

Q A
PHPUnit version 9.5.6
PHP version 7.4.21
Installation Method Composer

Summary

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.

The composer info:

algolia/algoliasearch-client-php     1.28.1    Algolia Search API Client for PHP
cache/adapter-common                 1.2.0     Common classes for PSR-6 adapters
cache/hierarchical-cache             1.1.0     A helper trait and interface to your PSR-6 cache to support hierarchical keys.
cache/tag-interop                    1.0.1     Framework interoperable interfaces for tags
cache/void-adapter                   1.1.0     A PSR-6 cache implementation using Void. This implementation supports tags
composer/package-versions-deprecated 1.11.99.2 Composer plugin that provides efficient querying for installed package versions (no runtime IO)
contentful/contentful                5.0.2     SDK for the Contentful Content Delivery API
contentful/core                      2.2.8     Foundation library for Contentful PHP SDKs
contentful/rich-text                 2.0.0     Utilities for the Contentful Rich Text
cunheise/phpqrcode                   v1.0.2    phpqrcode 1.1.4 version for composer, from http://phpqrcode.sourceforge.net/
doctrine/instantiator                1.4.0     A small, lightweight utility to instantiate objects in PHP without invoking their constructors
guzzlehttp/guzzle                    6.5.5     Guzzle is a PHP HTTP client library
guzzlehttp/promises                  1.4.1     Guzzle promises library
guzzlehttp/psr7                      1.8.2     PSR-7 message implementation that also provides common utility methods
hubspot/hubspot-php                  2.0.7     HubSpot PHP API client
jean85/pretty-package-versions       1.6.0     A wrapper for ocramius/package-versions to get pretty versions strings
khanamiryan/qrcode-detector-decoder  1.0.5.1   QR code decoder / reader
league/commonmark                    1.5.7     Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and Github-Flavored Markdown (GFM)
mailchimp/transactional              1.0.19
myclabs/deep-copy                    1.10.2    Create deep copies (clones) of your objects
netresearch/jsonmapper               v1.6.0    Map nested JSON structures onto PHP classes
nikic/php-parser                     v4.10.5   A PHP parser written in PHP
phar-io/manifest                     2.0.1     Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                      3.1.0     Library for handling version information and constraints
phpdocumentor/reflection-common      2.2.0     Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock    5.2.2     With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver          1.4.0     A PSR-5 based resolver of Class names, Types and Structural Element Names
phploc/phploc                        7.0.2     A tool for quickly measuring the size of a PHP project.
phpspec/prophecy                     1.13.0    Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage            9.2.6     Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator            3.0.5     FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                  3.1.1     Invoke callables with a timeout
phpunit/php-text-template            2.0.4     Simple template engine.
phpunit/php-timer                    5.0.3     Utility class for timing
phpunit/phpunit                      9.5.6     The PHP Unit Testing framework.
picqer/php-barcode-generator         v2.1.0    An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.
psr/cache                            1.0.1     Common interface for caching libraries
psr/container                        1.1.1     Common Container Interface (PHP FIG PSR-11)
psr/http-message                     1.0.1     Common interface for HTTP messages
psr/log                              1.1.4     Common interface for logging libraries
psr/simple-cache                     1.0.1     Common interfaces for simple caching
ralouphie/getallheaders              3.0.3     A polyfill for getallheaders.
sebastian/cli-parser                 1.0.1     Library for parsing CLI options
sebastian/code-unit                  1.0.8     Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup   2.0.3     Looks up which function or method a line of code belongs to
sebastian/comparator                 4.0.6     Provides the functionality to compare PHP values for equality
sebastian/complexity                 2.0.2     Library for calculating the complexity of PHP code units
sebastian/diff                       4.0.4     Diff implementation
sebastian/environment                5.1.3     Provides functionality to handle HHVM/PHP environments
sebastian/exporter                   4.0.3     Provides the functionality to export PHP variables for visualization
sebastian/global-state               5.0.3     Snapshotting of global state
sebastian/lines-of-code              1.0.3     Library for counting the lines of code in PHP source code
sebastian/object-enumerator          4.0.4     Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector           2.0.4     Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context          4.0.4     Provides functionality to recursively process PHP variables
sebastian/resource-operations        3.0.3     Provides a list of PHP built-in functions that operate on resources
sebastian/type                       2.3.4     Collection of value objects that represent the types of the PHP type system
sebastian/version                    3.0.2     Library that helps with managing the version number of Git-hosted PHP projects
setasign/fpdf                        1.8.2     FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your...
smarty/smarty                        v3.1.39   Smarty - the compiling PHP template engine
symfony/console                      v4.4.26   Eases the creation of beautiful and testable command line interfaces
symfony/filesystem                   v4.4.26   Provides basic utilities for the filesystem
symfony/polyfill-ctype               v1.23.0   Symfony polyfill for ctype functions
symfony/polyfill-intl-idn            v1.23.0   Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer     v1.23.0   Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring            v1.23.0   Symfony polyfill for the Mbstring extension
symfony/polyfill-php72               v1.23.0   Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73               v1.23.0   Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80               v1.23.0   Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/service-contracts            v2.4.0    Generic abstractions related to writing services
theseer/tokenizer                    1.2.0     A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert                     1.10.0    Assertions to validate method input/output with nice error messages.
zf1/zend-cache                       1.12.20   Zend Framework 1 Cache package
zf1/zend-currency                    1.12.20   Zend Framework 1 Currency package
zf1/zend-date                        1.12.20   Zend Framework 1 Date package
zf1/zend-exception                   1.12.20   Zend Framework 1 Exception package
zf1/zend-locale                      1.12.20   Zend Framework 1 Locale package
zf1/zend-log                         1.12.20   Zend Framework 1 Log package
zf1/zend-registry                    1.12.20   Zend Framework 1 Registry package
zf1/zend-xml                         1.12.20   Zend Framework 1 Xml package

powtac avatar Jul 15 '21 11:07 powtac

I cannot reproduce this. And I do not know what Xdebug would have to do with assert() statements.

sebastianbergmann avatar Jul 15 '21 12:07 sebastianbergmann