sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.68k stars 2.2k forks source link

make the output from --list-tests usable as a --filter parameter when there is a data provider #4129

Open joachim-n opened 4 years ago

joachim-n commented 4 years ago

If I use --list-tests, I get a list of all the data sets from the data provider:

$ vendor/bin/phpunit Test/Unit/ComponentPHPFile8Test.php --list-tests
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

Available test(s):
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"nothing"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"PHPStorm type var first"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"PHPStorm type class first"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"parameter typehint"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"static call"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"class"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"new"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"repeated"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"current"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"docblock param"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"comment"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"quoted class name"
 - DrupalCodeBuilder\Test\Unit\ComponentPHPFile8Test::testQualifiedClassNameExtraction"double quoted class name"

However, these are not in a format that (AFAIK) can be used with the --filter option. That needs an @ before the quote marks (and the quote marks are only needed if there are spaces in the data set name):

$ vendor/bin/phpunit Test/Unit/ComponentPHPFile8Test.php --filter=testQualifiedClassNameExtraction@"parameter typehint"

Proposed improvement: print the '@' between the method name and the dataset name in the output, so it's easier to copy-paste it to run a test.

perk11 commented 3 years ago

I'm looking for a way to run tests in parallel, invoking --filter to run phpunit with just a single test, and currently there is no easy way to get a list of tests in a test suite that could be passed back to --filter.

mfn commented 3 years ago

@perk11 you may be interested in https://github.com/sebastianbergmann/phpunit/pull/4449

perk11 commented 3 years ago

Thanks, that looks like it can work. I found that paratest can already do what I need, but for something more custom or even to make building something like paratest possible that doesn't depend on PHPUnit internals, #4449 would be a useful change.