Run phpunit code coverage only without running all the tests?

You can’t do it because PHPUnit needs to run the tests in order to know which lines of code were touched by the tests. But there’s a workaround: merging code coverage reports.

Example: You run your full test suite, and the report says you have 72% of you code covered. Then you add a few more tests. You run only these new tests, ending up with, let’s say, 3% of code coverage. After that you can merge the two reports in order to have 75% coverage.

One way to do it is using PHPUnit parameter --coverage-php and phpcov:

You run your full test suite once:

phpunit --coverage-php coverage/fulltest.cov

After a while you write a new test and run only that one

phpunit tests/SomeClassTest --filter testNewMethod --coverage-php coverage/testNewMethod.cov

You merge the reports into a coverage.html file in order to get full code coverage

phpcov merge --html coverage.html /coverage

If your tests really take a long time to run, this can be an option, as now you will need to run only the new tests to update the code coverage. Of course, doing this process manually every time is a pain, but you can create a script to automatize it.