Skip to content

Commit 3ef5f62

Browse files
committed
feat(baseline): can ignore deprecations with regex
1 parent 8d195ce commit 3ef5f62

File tree

7 files changed

+105
-19
lines changed

7 files changed

+105
-19
lines changed

composer.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Runner/Baseline/Issue.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function assert;
1414
use function file;
1515
use function is_file;
16+
use function preg_match;
1617
use function sha1;
1718
use PHPUnit\Runner\FileDoesNotExistException;
1819

@@ -112,7 +113,7 @@ public function equals(self $other): bool
112113
return $this->file() === $other->file() &&
113114
$this->line() === $other->line() &&
114115
$this->hash() === $other->hash() &&
115-
$this->description() === $other->description();
116+
($this->description() === $other->description() || preg_match('{' . $this->description() . '}', $other->description()) > 0);
116117
}
117118

118119
/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<files version="1">
3+
<file path="tests/UseBaselineTest.php">
4+
<line number="20" hash="bee8cf8f19af95867fd8c6092e6813ae06cc12a9">
5+
<issue><![CDATA[deprecation \d{3}]]></issue>
6+
</line>
7+
</file>
8+
</files>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
4+
cacheResult="false"
5+
>
6+
<testsuites>
7+
<testsuite name="default">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
12+
<source baseline="baseline.xml">
13+
</source>
14+
</phpunit>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Baseline;
11+
12+
use const E_USER_DEPRECATED;
13+
use function trigger_error;
14+
use PHPUnit\Framework\TestCase;
15+
16+
final class UseBaselineTest extends TestCase
17+
{
18+
public function testOne(): void
19+
{
20+
trigger_error('deprecation 123', E_USER_DEPRECATED);
21+
22+
$this->assertTrue(true);
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
phpunit --configuration ../_files/baseline/use-baseline-with-regex/phpunit.xml
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/../_files/baseline/use-baseline-with-regex/phpunit.xml';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
Configuration: %s
17+
18+
. 1 / 1 (100%)
19+
20+
Time: %s, Memory: %s
21+
22+
OK (1 test, 1 assertion)
23+
24+
1 issue was ignored by baseline.

tests/unit/Runner/Baseline/IssueTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public function testIsComparable(): void
5050
$this->assertFalse($this->issue()->equals($this->anotherIssue()));
5151
}
5252

53+
public function testIsComparableWithRegex(): void
54+
{
55+
$this->assertTrue($this->issueWithRegex()->equals($this->issue()));
56+
}
57+
5358
public function testCannotBeCreatedForFileThatDoesNotExist(): void
5459
{
5560
$this->expectException(FileDoesNotExistException::class);
@@ -84,6 +89,16 @@ private function issue(): Issue
8489
);
8590
}
8691

92+
private function issueWithRegex(): Issue
93+
{
94+
return Issue::from(
95+
realpath(__DIR__ . '/../../../_files/baseline/FileWithIssues.php'),
96+
10,
97+
null,
98+
'(.)*',
99+
);
100+
}
101+
87102
private function anotherIssue(): Issue
88103
{
89104
return Issue::from(

0 commit comments

Comments
 (0)