mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
fix: preserve explicit coverage report path
This commit is contained in:
+38
-10
@@ -50,12 +50,14 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
*/
|
||||
public bool $showOnlyCovered = false;
|
||||
|
||||
private string $coveragePath;
|
||||
|
||||
/**
|
||||
* Creates a new Plugin instance.
|
||||
*/
|
||||
public function __construct(private readonly OutputInterface $output)
|
||||
{
|
||||
// ..
|
||||
$this->coveragePath = \Pest\Support\Coverage::getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,12 +79,6 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
return false;
|
||||
}))];
|
||||
|
||||
$originals = array_flip($originals);
|
||||
foreach ($arguments as $argument) {
|
||||
unset($originals[$argument]);
|
||||
}
|
||||
$originals = array_flip($originals);
|
||||
|
||||
$inputs = [];
|
||||
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
||||
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
|
||||
@@ -90,10 +86,26 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
$inputs[] = new InputOption(self::ONLY_COVERED_OPTION, null, InputOption::VALUE_NONE);
|
||||
|
||||
$input = new ArgvInput($arguments, new InputDefinition($inputs));
|
||||
$coveragePathProvided = false;
|
||||
|
||||
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
|
||||
$this->coverage = true;
|
||||
$originals[] = '--coverage-php';
|
||||
$originals[] = \Pest\Support\Coverage::getPath();
|
||||
|
||||
foreach ($originals as $index => $original) {
|
||||
if (Str::startsWith($original, '--coverage-php=')) {
|
||||
$this->coveragePath = Str::after($original, '--coverage-php=');
|
||||
$coveragePathProvided = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ($original === '--coverage-php' && isset($originals[$index + 1])) {
|
||||
$this->coveragePath = $originals[$index + 1];
|
||||
$coveragePathProvided = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! \Pest\Support\Coverage::isAvailable()) {
|
||||
if (\Pest\Support\Coverage::usingXdebug()) {
|
||||
@@ -114,6 +126,17 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
}
|
||||
}
|
||||
|
||||
$originals = array_flip($originals);
|
||||
foreach ($arguments as $argument) {
|
||||
unset($originals[$argument]);
|
||||
}
|
||||
$originals = array_flip($originals);
|
||||
|
||||
if ((bool) $input->getOption(self::COVERAGE_OPTION) && ! $coveragePathProvided) {
|
||||
$originals[] = '--coverage-php';
|
||||
$originals[] = $this->coveragePath;
|
||||
}
|
||||
|
||||
if ($input->getOption(self::MIN_OPTION) !== null) {
|
||||
/** @var int|float $minOption */
|
||||
$minOption = $input->getOption(self::MIN_OPTION);
|
||||
@@ -156,7 +179,12 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$coverage = \Pest\Support\Coverage::report($this->output, $this->compact, $this->showOnlyCovered);
|
||||
$coverage = \Pest\Support\Coverage::report($this->output, $this->compact, $this->showOnlyCovered, $this->coveragePath);
|
||||
|
||||
if ($this->coveragePath === \Pest\Support\Coverage::getPath()) {
|
||||
unlink($this->coveragePath);
|
||||
}
|
||||
|
||||
$exitCode = (int) ($coverage < $this->coverageMin);
|
||||
|
||||
if ($exitCode === 0 && $this->coverageExactly !== null) {
|
||||
|
||||
@@ -74,9 +74,9 @@ final class Coverage
|
||||
* Reports the code coverage report to the
|
||||
* console and returns the result in float.
|
||||
*/
|
||||
public static function report(OutputInterface $output, bool $compact = false, bool $showOnlyCovered = false): float
|
||||
public static function report(OutputInterface $output, bool $compact, bool $showOnlyCovered, string $reportPath): float
|
||||
{
|
||||
if (! file_exists($reportPath = self::getPath())) {
|
||||
if (! file_exists($reportPath)) {
|
||||
if (self::usingXdebug()) {
|
||||
$output->writeln(
|
||||
" <fg=black;bg=yellow;options=bold> WARN </> Unable to get coverage using Xdebug. Did you set <href=https://xdebug.org/docs/code_coverage#mode>Xdebug's coverage mode</>?</>",
|
||||
@@ -90,7 +90,6 @@ final class Coverage
|
||||
|
||||
/** @var CodeCoverage $codeCoverage */
|
||||
$codeCoverage = require $reportPath;
|
||||
unlink($reportPath);
|
||||
|
||||
$totalCoverage = $codeCoverage->getReport()->percentageOfExecutedLines();
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
WARN Tests\Features\Coverage
|
||||
✓ it has plugin
|
||||
- it adds coverage if --coverage exist → Coverage is not available
|
||||
- it keeps the explicit coverage path when --coverage exists → Coverage is not available
|
||||
✓ it adds coverage if --min exist
|
||||
✓ it generates coverage based on file input
|
||||
|
||||
@@ -1905,5 +1906,4 @@
|
||||
PASS Testsexternal\Features\Expect\toMatchSnapshot
|
||||
✓ pass with dataset with ('my-datas-set-value')
|
||||
✓ within describe → pass with dataset with ('my-datas-set-value')
|
||||
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1297 passed (2980 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 36 skipped, 1297 passed (2980 assertions)
|
||||
|
||||
@@ -19,6 +19,26 @@ it('adds coverage if --coverage exist', function () {
|
||||
->and($plugin->coverage)->toBeTrue();
|
||||
})->skip(! Coverage::isAvailable() || ! function_exists('xdebug_info') || ! in_array('coverage', xdebug_info('mode'), true), 'Coverage is not available');
|
||||
|
||||
it('keeps the explicit coverage path when --coverage exists', function () {
|
||||
foreach ([
|
||||
['--coverage-php=test.cov'],
|
||||
['--coverage-php', 'test.cov'],
|
||||
] as $coverageArguments) {
|
||||
$plugin = new CoveragePlugin(new ConsoleOutput);
|
||||
|
||||
$arguments = $plugin->handleArguments([
|
||||
'--coverage',
|
||||
'--coverage-text',
|
||||
...$coverageArguments,
|
||||
]);
|
||||
|
||||
expect(array_values($arguments))->toEqual([
|
||||
'--coverage-text',
|
||||
...$coverageArguments,
|
||||
]);
|
||||
}
|
||||
})->skip(! Coverage::isAvailable() || ! function_exists('xdebug_info') || ! in_array('coverage', xdebug_info('mode'), true), 'Coverage is not available');
|
||||
|
||||
it('adds coverage if --min exist', function () {
|
||||
$plugin = new CoveragePlugin(new ConsoleOutput);
|
||||
expect($plugin->coverageMin)->toEqual(0.0)
|
||||
|
||||
Reference in New Issue
Block a user