Skip to content

Commit

Permalink
Fix baseline reading (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Aug 8, 2024
1 parent 6f990d0 commit f8feb04
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"ext-pcov": "*",
"ext-posix": "*",
"doctrine/coding-standard": "^12.0.0",
"phpstan/phpstan": "^1.11.9",
"phpstan/phpstan": "^1.11.10",
"phpstan/phpstan-deprecation-rules": "^1.2.0",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-strict-rules": "^1.6.0",
Expand Down
19 changes: 19 additions & 0 deletions src/WrapperRunner/ApplicationForWrapperWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
use PHPUnit\Logging\TeamCity\TeamCityLogger;
use PHPUnit\Logging\TestDox\TestResultCollector;
use PHPUnit\Metadata\Api\CodeCoverage as CodeCoverageMetadataApi;
use PHPUnit\Runner\Baseline\CannotLoadBaselineException;
use PHPUnit\Runner\Baseline\Reader;
use PHPUnit\Runner\CodeCoverage;
use PHPUnit\Runner\ErrorHandler;
use PHPUnit\Runner\Extension\ExtensionBootstrapper;
use PHPUnit\Runner\Extension\Facade as ExtensionFacade;
use PHPUnit\Runner\Extension\PharLoader;
Expand Down Expand Up @@ -205,6 +208,22 @@ private function bootstrap(): void
}

TestResultFacade::init();

if ($this->configuration->source()->useBaseline()) {
$baselineFile = $this->configuration->source()->baseline();
$baseline = null;

try {
$baseline = (new Reader())->read($baselineFile);
} catch (CannotLoadBaselineException $e) {
EventFacade::emitter()->testRunnerTriggeredWarning($e->getMessage());
}

if ($baseline !== null) {
ErrorHandler::instance()->useBaseline($baseline);
}
}

EventFacade::instance()->seal();
EventFacade::emitter()->testRunnerStarted();

Expand Down
22 changes: 22 additions & 0 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,28 @@ public function testCliOptionsThatCouldBeUsedMultipleTimes(): void
Time: %s, Memory: %s MB
OK%a
EOF;
self::assertStringMatchesFormat($expectedOutput, $runnerResult->output);
self::assertEquals(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode);
}

#[Group('github')]
public function testBaselineIsRespected(): void
{
$this->bareOptions['--configuration'] = $this->fixture('github' . DIRECTORY_SEPARATOR . 'GH869' . DIRECTORY_SEPARATOR . 'phpunit.xml');

$runnerResult = $this->runRunner();

$expectedOutput = <<<'EOF'
Processes: %s
Runtime: PHP %s
Configuration: %s
.. 2 / 2 (100%)
Time: %s, Memory: %s MB
OK%a
EOF;
self::assertStringMatchesFormat($expectedOutput, $runnerResult->output);
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/github/GH869/IssueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH869;

use PHPUnit\Framework\TestCase;

/** @internal */
final class IssueTest extends TestCase
{
public function testUnsuppressedButBaselineDeprecated(): void
{
self::assertTrue((new Something())->raiseDeprecated());
}

public function testSuppressedButNotBaselineNotice(): void
{
self::assertTrue((new Something())->raiseNotice());
}
}
28 changes: 28 additions & 0 deletions test/fixtures/github/GH869/Something.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH869;

use function trigger_error;

use const E_USER_DEPRECATED;
use const E_USER_NOTICE;

/** @internal */
final class Something
{
public function raiseDeprecated(): bool
{
@trigger_error('what', E_USER_DEPRECATED);

return true;
}

public function raiseNotice(): bool
{
@trigger_error('what', E_USER_NOTICE);

return true;
}
}
8 changes: 8 additions & 0 deletions test/fixtures/github/GH869/baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<files version="1">
<file path="Something.php">
<line number="17" hash="aa950011fe9480f51290b3dad45f9d052960befd">
<issue><![CDATA[what]]></issue>
</line>
</file>
</files>
19 changes: 19 additions & 0 deletions test/fixtures/github/GH869/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../vendor/phpunit/phpunit/phpunit.xsd"
>
<testsuites>
<testsuite name="Github issue">
<file>IssueTest.php</file>
</testsuite>
</testsuites>
<source
ignoreSuppressionOfDeprecations="true"
baseline="baseline.xml"
>
<include>
<file>Something.php</file>
</include>
</source>
</phpunit>

0 comments on commit f8feb04

Please sign in to comment.