sebastianbergmann / phpunit

The PHP Unit Testing framework.

Home Page:https://phpunit.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run code coverage without a phpunit.xml

staabm opened this issue · comments

when I don't have a phpunit.xml running a command like
vendor/bin/phpunit tests/library/UrlHelperTest.php --coverage-text

returns "No filter is configured, code coverage will not be processed"

$ vendor/bin/phpunit tests/library/UrlHelperTest.php --coverage-text
PHPUnit 10.5.19 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.12

........                                                            8 / 8 (100%)

Time: 00:00.020, Memory: 12.00 MB

There was 1 PHPUnit test runner warning:

1) No filter is configured, code coverage will not be processed

WARNINGS!
Tests: 8, Assertions: 8, Warnings: 1.

I wonder whether we could/should imply the coverage filter to be the paths which are passed to the CLI command, when no phpunit.xml exists in this case

The --coverage-filter CLI option exists for this purpose. Are you saying that it does not work or that you did not know about it? ;-)

I did not know about this option - thank you.

Also I wondern, when I run only a subset of the test-suite (which I do because I pass concret paths to tests to phpunit), whether it could just create coverage for these tests involved, without asking me to repeat a coverage filter (I already told with --coverage-html=coverage that I wan't coverage). might be helpful from a DX point of view.

whether it could just create coverage for these tests involved, without asking me to repeat a coverage filter

One has nothing to do with the other.

Closing this as the problem was already solved (--coverage-filter exists).

One has nothing to do with the other.

I totally agree. let me re-phrase the idea from a end-user perspective.

I run vendor/bin/phpunit tests/library/UrlHelperTest.php --coverage-text because I want to run this particular test and want a coverage report which code was executed because of this test.

since UrlHelperTest.php declares CoversClass via metadata, I think PHPUnit "could find" via the metadata which classes it needs to generate coverage for, without me additionally adding a filter...?

I do not think that this would be useful, sorry.