Skip to content

Commit

Permalink
Fix Code Coverage on custom group with data provider (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Aug 8, 2023
1 parent a310a31 commit 4d7ad5b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/WrapperRunner/ApplicationForWrapperWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public function runTest(string $testPath): int
$testSuite = TestSuite::fromClassReflector($testSuiteRefl);
}

(new TestSuiteFilterProcessor())->process($this->configuration, $testSuite);

if (CodeCoverage::instance()->isActive()) {
CodeCoverage::instance()->ignoreLines(
(new CodeCoverageMetadataApi())->linesToBeIgnored($testSuite),
);
}

(new TestSuiteFilterProcessor())->process($this->configuration, $testSuite);

if ($filter !== null) {
$testSuite->injectFilter($filter);

Expand Down
11 changes: 11 additions & 0 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,17 @@ public function testHandleUnexpectedOutput(): void
self::assertStringMatchesFormat($expectedOutput, $runnerResult->output);
}

/** @group github */
#[CoversNothing]
public function testGroupOptionWithDataProviderAndCodeCoverageEnabled(): void
{
$this->bareOptions['--configuration'] = $this->fixture('github' . DIRECTORY_SEPARATOR . 'GH782' . DIRECTORY_SEPARATOR . 'phpunit.xml');
$this->bareOptions['--group'] = 'default';

$runnerResult = $this->runRunner();
self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode);
}

/**
* \PHPUnit\Runner\Filter\NameFilterIterator uses `preg_match`, and in
* \ParaTest\Tests\fixtures\function_parallelization_tests\FunctionalParallelizationTest::dataProvider2
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/github/GH431/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class IssueTest extends TestCase
public function testFillBuffers(): void
{
// the string is larger than the output buffer.
// if the parent process doesnt read the output buffer, this test will hang forever.
// if the parent process doesn't read the output buffer, this test will hang forever.
echo str_repeat('a', 10000);

$this->assertTrue(true);
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures/github/GH782/IssueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH782;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/** @internal */
final class IssueTest extends TestCase
{
#[DataProvider('provideThings')]
public function testProvider(bool $value): void
{
self::assertTrue((new Something($value))->value);
}

/** @return list<list<bool>> */
public static function provideThings(): array
{
return [
[true],
];
}
}
16 changes: 16 additions & 0 deletions test/fixtures/github/GH782/Something.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH782;

/** @internal */
final class Something
{
public readonly bool $value;

public function __construct(bool $value)
{
$this->value = $value;
}
}
17 changes: 17 additions & 0 deletions test/fixtures/github/GH782/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<phpunit cacheDirectory="tmp">
<testsuites>
<testsuite name="Github issue">
<file>IssueTest.php</file>
</testsuite>
</testsuites>
<coverage>
<report>
<text outputFile="php://stdout"/>
</report>
</coverage>
<source>
<include>
<file>Something.php</file>
</include>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions test/fixtures/github/GH782/tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 4d7ad5b

Please sign in to comment.