Skip to content

Commit

Permalink
Fix for ignored Ignore attributes (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored May 5, 2023
1 parent 3dc8062 commit 153e68e
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/WrapperRunner/ApplicationForWrapperWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPUnit\Logging\JUnit\JunitXmlLogger;
use PHPUnit\Logging\TeamCity\TeamCityLogger;
use PHPUnit\Logging\TestDox\TestResultCollector;
use PHPUnit\Metadata\Api\CodeCoverage as CodeCoverageMetadataApi;
use PHPUnit\Runner\CodeCoverage;
use PHPUnit\Runner\Extension\ExtensionBootstrapper;
use PHPUnit\Runner\Extension\Facade as ExtensionFacade;
Expand Down Expand Up @@ -65,6 +66,12 @@ public function runTest(string $testPath): int

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

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

EventFacade::emitter()->testRunnerExecutionStarted(
TestSuiteBuilder::from($testSuite),
);
Expand Down
19 changes: 19 additions & 0 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,25 @@ public function testHandleCollisionWithSymfonyOutput(): void
self::assertStringContainsString('<bg=%s>', $runnerResult->output);
}

/** @group github */
#[CoversNothing]
public function testIgnoreAttributes(): void
{
$this->bareOptions['--configuration'] = $this->fixture('github' . DIRECTORY_SEPARATOR . 'GH756' . DIRECTORY_SEPARATOR . 'phpunit.xml');
$this->bareOptions['--processes'] = '1';
$runnerResult = $this->runRunner();

$expectedContains = <<<'EOF'
ParaTest\Tests\fixtures\github\GH756\CoveredOneClass
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 1/ 1)
ParaTest\Tests\fixtures\github\GH756\CoveredTwoClass
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 1/ 1)
EOF;

self::assertEquals(0, $runnerResult->exitCode);
self::assertStringContainsString($expectedContains, $runnerResult->output);
}

public function testProcessIsolation(): void
{
$this->bareOptions['path'] = $this->fixture('process_isolation' . DIRECTORY_SEPARATOR . 'FooTest.php');
Expand Down
18 changes: 18 additions & 0 deletions test/fixtures/github/GH756/CoveredOneClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH756;

final class CoveredOneClass
{
public function m(): bool
{
return $this->n();
}

private function n(): bool
{
return true;
}
}
18 changes: 18 additions & 0 deletions test/fixtures/github/GH756/CoveredOneTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH756;

use PHPUnit\Framework\Attributes\IgnoreMethodForCodeCoverage;
use PHPUnit\Framework\TestCase;

/** @internal */
#[IgnoreMethodForCodeCoverage(CoveredOneClass::class, 'n')]
final class CoveredOneTest extends TestCase
{
public function testOne(): void
{
$this->assertTrue((new CoveredOneClass())->m());
}
}
18 changes: 18 additions & 0 deletions test/fixtures/github/GH756/CoveredTwoClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH756;

final class CoveredTwoClass
{
public function m(): bool
{
return $this->n();
}

private function n(): bool
{
return true;
}
}
18 changes: 18 additions & 0 deletions test/fixtures/github/GH756/CoveredTwoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH756;

use PHPUnit\Framework\Attributes\IgnoreMethodForCodeCoverage;
use PHPUnit\Framework\TestCase;

/** @internal */
#[IgnoreMethodForCodeCoverage(CoveredTwoClass::class, 'n')]
final class CoveredTwoTest extends TestCase
{
public function testOne(): void
{
$this->assertTrue((new CoveredTwoClass())->m());
}
}
19 changes: 19 additions & 0 deletions test/fixtures/github/GH756/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<phpunit cacheDirectory="tmp">
<source>
<include>
<file>CoveredOneClass.php</file>
<file>CoveredTwoClass.php</file>
</include>
</source>
<coverage>
<report>
<text outputFile="php://stdout"/>
</report>
</coverage>
<testsuites>
<testsuite name="Github issue">
<file>CoveredOneTest.php</file>
<file>CoveredTwoTest.php</file>
</testsuite>
</testsuites>
</phpunit>
2 changes: 2 additions & 0 deletions test/fixtures/github/GH756/tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 153e68e

Please sign in to comment.