Skip to content

Commit 8a86514

Browse files
Merge branch '11.0'
2 parents 0293751 + 697b867 commit 8a86514

File tree

4 files changed

+71
-101
lines changed

4 files changed

+71
-101
lines changed

src/Runner/Filter/ExcludeNameFilterIterator.php

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,13 @@
99
*/
1010
namespace PHPUnit\Runner\Filter;
1111

12-
use function preg_match;
13-
use function sprintf;
14-
use function str_replace;
15-
1612
/**
1713
* @internal This class is not covered by the backward compatibility promise for PHPUnit
1814
*/
1915
final class ExcludeNameFilterIterator extends NameFilterIterator
2016
{
21-
/**
22-
* @psalm-param non-empty-string $filter
23-
*
24-
* @psalm-return array{regularExpression: non-empty-string, dataSetMinimum: ?int, dataSetMaximum: ?int}
25-
*/
26-
protected function prepareFilter(string $filter): array
17+
protected function doAccept(bool $result): bool
2718
{
28-
if (@preg_match($filter, '') === false) {
29-
$filter = sprintf(
30-
'/^(?:(?!%s).)*/i',
31-
str_replace(
32-
'/',
33-
'\\/',
34-
$filter,
35-
),
36-
);
37-
}
38-
39-
return [
40-
'regularExpression' => $filter,
41-
'dataSetMinimum' => null,
42-
'dataSetMaximum' => null,
43-
];
19+
return !$result;
4420
}
4521
}

src/Runner/Filter/IncludeNameFilterIterator.php

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,13 @@
99
*/
1010
namespace PHPUnit\Runner\Filter;
1111

12-
use function preg_match;
13-
use function sprintf;
14-
use function str_replace;
15-
1612
/**
1713
* @internal This class is not covered by the backward compatibility promise for PHPUnit
1814
*/
1915
final class IncludeNameFilterIterator extends NameFilterIterator
2016
{
21-
/**
22-
* @psalm-param non-empty-string $filter
23-
*
24-
* @psalm-return array{regularExpression: non-empty-string, dataSetMinimum: ?int, dataSetMaximum: ?int}
25-
*/
26-
protected function prepareFilter(string $filter): array
17+
protected function doAccept(bool $result): bool
2718
{
28-
$dataSetMinimum = null;
29-
$dataSetMaximum = null;
30-
31-
if (@preg_match($filter, '') === false) {
32-
// Handles:
33-
// * testAssertEqualsSucceeds#4
34-
// * testAssertEqualsSucceeds#4-8
35-
if (preg_match('/^(.*?)#(\d+)(?:-(\d+))?$/', $filter, $matches)) {
36-
if (isset($matches[3]) && $matches[2] < $matches[3]) {
37-
$filter = sprintf(
38-
'%s.*with data set #(\d+)$',
39-
$matches[1],
40-
);
41-
42-
$dataSetMinimum = (int) $matches[2];
43-
$dataSetMaximum = (int) $matches[3];
44-
} else {
45-
$filter = sprintf(
46-
'%s.*with data set #%s$',
47-
$matches[1],
48-
$matches[2],
49-
);
50-
}
51-
} // Handles:
52-
// * testDetermineJsonError@JSON_ERROR_NONE
53-
// * testDetermineJsonError@JSON.*
54-
elseif (preg_match('/^(.*?)@(.+)$/', $filter, $matches)) {
55-
$filter = sprintf(
56-
'%s.*with data set "%s"$',
57-
$matches[1],
58-
$matches[2],
59-
);
60-
}
61-
62-
// Escape delimiters in regular expression. Do NOT use preg_quote,
63-
// to keep magic characters.
64-
$filter = sprintf(
65-
'/%s/i',
66-
str_replace(
67-
'/',
68-
'\\/',
69-
$filter,
70-
),
71-
);
72-
}
73-
74-
return [
75-
'regularExpression' => $filter,
76-
'dataSetMinimum' => $dataSetMinimum,
77-
'dataSetMaximum' => $dataSetMaximum,
78-
];
19+
return $result;
7920
}
8021
}

src/Runner/Filter/NameFilterIterator.php

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
use function end;
1313
use function preg_match;
14+
use function sprintf;
15+
use function str_replace;
1416
use PHPUnit\Framework\Test;
15-
use PHPUnit\Framework\TestCase;
1617
use PHPUnit\Framework\TestSuite;
18+
use PHPUnit\Runner\PhptTestCase;
1719
use RecursiveFilterIterator;
1820
use RecursiveIterator;
1921

@@ -60,7 +62,7 @@ public function accept(): bool
6062
return true;
6163
}
6264

63-
if (!$test instanceof TestCase) {
65+
if ($test instanceof PhptTestCase) {
6466
return false;
6567
}
6668

@@ -73,13 +75,68 @@ public function accept(): bool
7375
$accepted = $set >= $this->dataSetMinimum && $set <= $this->dataSetMaximum;
7476
}
7577

76-
return $accepted;
78+
return $this->doAccept($accepted);
7779
}
7880

81+
abstract protected function doAccept(bool $result): bool;
82+
7983
/**
8084
* @psalm-param non-empty-string $filter
8185
*
8286
* @psalm-return array{regularExpression: non-empty-string, dataSetMinimum: ?int, dataSetMaximum: ?int}
8387
*/
84-
abstract protected function prepareFilter(string $filter): array;
88+
private function prepareFilter(string $filter): array
89+
{
90+
$dataSetMinimum = null;
91+
$dataSetMaximum = null;
92+
93+
if (@preg_match($filter, '') === false) {
94+
// Handles:
95+
// * testAssertEqualsSucceeds#4
96+
// * testAssertEqualsSucceeds#4-8
97+
if (preg_match('/^(.*?)#(\d+)(?:-(\d+))?$/', $filter, $matches)) {
98+
if (isset($matches[3]) && $matches[2] < $matches[3]) {
99+
$filter = sprintf(
100+
'%s.*with data set #(\d+)$',
101+
$matches[1],
102+
);
103+
104+
$dataSetMinimum = (int) $matches[2];
105+
$dataSetMaximum = (int) $matches[3];
106+
} else {
107+
$filter = sprintf(
108+
'%s.*with data set #%s$',
109+
$matches[1],
110+
$matches[2],
111+
);
112+
}
113+
} // Handles:
114+
// * testDetermineJsonError@JSON_ERROR_NONE
115+
// * testDetermineJsonError@JSON.*
116+
elseif (preg_match('/^(.*?)@(.+)$/', $filter, $matches)) {
117+
$filter = sprintf(
118+
'%s.*with data set "%s"$',
119+
$matches[1],
120+
$matches[2],
121+
);
122+
}
123+
124+
// Escape delimiters in regular expression. Do NOT use preg_quote,
125+
// to keep magic characters.
126+
$filter = sprintf(
127+
'/%s/i',
128+
str_replace(
129+
'/',
130+
'\\/',
131+
$filter,
132+
),
133+
);
134+
}
135+
136+
return [
137+
'regularExpression' => $filter,
138+
'dataSetMinimum' => $dataSetMinimum,
139+
'dataSetMaximum' => $dataSetMaximum,
140+
];
141+
}
85142
}

tests/end-to-end/cli/exclude-filter/match.phpt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
phpunit --exclude-filter one tests/FooTest.php
2+
phpunit --exclude-filter testThree ../../_files/groups/tests/FooTest.php
33
--FILE--
44
<?php declare(strict_types=1);
55
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);
@@ -10,7 +10,7 @@ $_SERVER['argv'][] = '--no-output';
1010
$_SERVER['argv'][] = '--log-events-text';
1111
$_SERVER['argv'][] = $traceFile;
1212
$_SERVER['argv'][] = '--exclude-filter';
13-
$_SERVER['argv'][] = 'testone';
13+
$_SERVER['argv'][] = 'testThree';
1414
$_SERVER['argv'][] = __DIR__ . '/../../_files/groups/tests/FooTest.php';
1515

1616
require_once __DIR__ . '/../../../bootstrap.php';
@@ -27,9 +27,9 @@ Test Suite Loaded (3 tests)
2727
Event Facade Sealed
2828
Test Runner Started
2929
Test Suite Sorted
30-
Test Suite Filtered (3 tests)
31-
Test Runner Execution Started (3 tests)
32-
Test Suite Started (PHPUnit\TestFixture\Groups\FooTest, 3 tests)
30+
Test Suite Filtered (2 tests)
31+
Test Runner Execution Started (2 tests)
32+
Test Suite Started (PHPUnit\TestFixture\Groups\FooTest, 2 tests)
3333
Test Preparation Started (PHPUnit\TestFixture\Groups\FooTest::testOne)
3434
Test Prepared (PHPUnit\TestFixture\Groups\FooTest::testOne)
3535
Test Passed (PHPUnit\TestFixture\Groups\FooTest::testOne)
@@ -38,11 +38,7 @@ Test Preparation Started (PHPUnit\TestFixture\Groups\FooTest::testTwo)
3838
Test Prepared (PHPUnit\TestFixture\Groups\FooTest::testTwo)
3939
Test Passed (PHPUnit\TestFixture\Groups\FooTest::testTwo)
4040
Test Finished (PHPUnit\TestFixture\Groups\FooTest::testTwo)
41-
Test Preparation Started (PHPUnit\TestFixture\Groups\FooTest::testThree)
42-
Test Prepared (PHPUnit\TestFixture\Groups\FooTest::testThree)
43-
Test Passed (PHPUnit\TestFixture\Groups\FooTest::testThree)
44-
Test Finished (PHPUnit\TestFixture\Groups\FooTest::testThree)
45-
Test Suite Finished (PHPUnit\TestFixture\Groups\FooTest, 3 tests)
41+
Test Suite Finished (PHPUnit\TestFixture\Groups\FooTest, 2 tests)
4642
Test Runner Execution Finished
4743
Test Runner Finished
4844
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)