Skip to content

feat(baseline): can ignore deprecations with regex #6287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Runner/Baseline/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function assert;
use function file;
use function is_file;
use function preg_match;
use function sha1;
use PHPUnit\Runner\FileDoesNotExistException;

Expand Down Expand Up @@ -112,7 +113,7 @@ public function equals(self $other): bool
return $this->file() === $other->file() &&
$this->line() === $other->line() &&
$this->hash() === $other->hash() &&
$this->description() === $other->description();
($this->description() === $other->description() || preg_match('{' . $this->description() . '}', $other->description()) > 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<files version="1">
<file path="tests/UseBaselineTest.php">
<line number="20" hash="bee8cf8f19af95867fd8c6092e6813ae06cc12a9">
<issue><![CDATA[deprecation \d{3}]]></issue>
</line>
</file>
</files>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
cacheResult="false"
>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source baseline="baseline.xml">
</source>
</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Baseline;

use const E_USER_DEPRECATED;
use function trigger_error;
use PHPUnit\Framework\TestCase;

final class UseBaselineTest extends TestCase
{
public function testOne(): void
{
trigger_error('deprecation 123', E_USER_DEPRECATED);

$this->assertTrue(true);
}
}
24 changes: 24 additions & 0 deletions tests/end-to-end/baseline/use-baseline-with-regex.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
phpunit --configuration ../_files/baseline/use-baseline-with-regex/phpunit.xml
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/baseline/use-baseline-with-regex/phpunit.xml';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s
Configuration: %s

. 1 / 1 (100%)

Time: %s, Memory: %s

OK (1 test, 1 assertion)

1 issue was ignored by baseline.
15 changes: 15 additions & 0 deletions tests/unit/Runner/Baseline/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function testIsComparable(): void
$this->assertFalse($this->issue()->equals($this->anotherIssue()));
}

public function testIsComparableWithRegex(): void
{
$this->assertTrue($this->issueWithRegex()->equals($this->issue()));
}

public function testCannotBeCreatedForFileThatDoesNotExist(): void
{
$this->expectException(FileDoesNotExistException::class);
Expand Down Expand Up @@ -84,6 +89,16 @@ private function issue(): Issue
);
}

private function issueWithRegex(): Issue
{
return Issue::from(
realpath(__DIR__ . '/../../../_files/baseline/FileWithIssues.php'),
10,
null,
'(.)*',
);
}

private function anotherIssue(): Issue
{
return Issue::from(
Expand Down
Loading