Add events for code coverage
The new event system allows us to write plugins and react to certain events. Even though we already have a lot of useful events, I think there are still a few missing. To be specific, there are currently no events available for code coverage.
It would be nice to have for example
namespace PHPUnit\Event\CodeCoverage\Started;
namespace PHPUnit\Event\CodeCoverage\Stopped;
namespace PHPUnit\Event\CodeCoverage\ReportProcessed;
...
I can think of a lot of useful plugins that could use the code coverage percentage...
PHPUnit itself does not know anything about code coverage data and the data is currently not held/exposed by php-code-coverage (the library that collects and processes code coverage data) in a way that would support what you propose.
Too bad, would be very nice. Nevertheless, thanks for putting a lot of your time into this!
@sebastianbergmann Checked the code, and correct me if I'm wrong, but PHPUnit does know when code coverage started stopped and when the reports have been processed?
Am I missing something here?
EDIT: Although you are right that the events could not contain any data about the coverage result itself...
namespace PHPUnit\TextUI;
final class Application
{
public function run(array $argv): int
{
...
CodeCoverage::instance()->generateReports($printer, $configuration);
}
}
And
namespace PHPUnit\Framework;
final class TestRunner
{
public function run(TestCase $test): void
{
...
if ($collectCodeCoverage) {
CodeCoverage::instance()->start($test);
}
...
CodeCoverage::instance()->stop(
$append,
$linesToBeCovered,
$linesToBeUsed
);
}
}
PHPUnit knows the "when", but not the result(s). I do not see any point in adding events for "code coverage report generation started", "code coverage report generation finished", etc.