phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

Filter test case by #<number> does not work with custom data provider key name

Open alexander-schranz opened this issue 3 years ago • 1 comments

Q A
PHPUnit version 9.5.20
PHP version 8.1.4
Installation Method Composer

Summary

I want to filter (--filter) by a specific name. But don't want lost the way to filter by --filter="#2" for example. For this I added #<counter> as a prefix to my key of the data provider validator. But it seems like filter by # is handled specially and does not work in this case.

Current behavior

No tests found for --filter="#5"

How to reproduce

Generator like here: https://github.com/rectorphp/rector-src/pull/2356/files

        $counter = 0;
        foreach (StaticFixtureFinder::yieldDirectoryExclusivelyWithRelativePathname($directory, $suffix) as $name => $parameters) {
            yield '#' . $counter . ' ' . $name => $parameters;

            ++$counter;
        }

Expected behavior

When filtering by vendor/bin/phpunit --filter="#5" the test case with #5 name should be executed.

alexander-schranz avatar May 25 '22 10:05 alexander-schranz

It looks like you need another syntax: --filter "testTrimTrims@#5*"

It may not work with dynamic data though.

Source: https://blog.martinhujer.cz/how-to-use-data-providers-in-phpunit/#tip-%232%3A-you-can-run-single-data-set-from-data-provider

alexislefebvre avatar Jun 08 '22 11:06 alexislefebvre