Repository navigation
Expand file tree
/
Copy pathFilterTest.php
More file actions
53 lines (43 loc) · 1.44 KB
/
Copy pathFilterTest.php
File metadata and controls
53 lines (43 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace Codeception\PHPUnit;
use Codeception\PHPUnit\NonFinal\NameFilterIterator;
use Codeception\Test\Descriptor;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\WarningTestCase;
use function end;
use function is_null;
use function preg_match;
/**
* Extended Filter Test from PHPUnit to use Codeception's Descriptor to locate tests.
*
* Class FilterTest
* @package Codeception\PHPUnit
*/
class FilterTest extends NameFilterIterator
{
public function accept(): bool
{
$test = $this->getInnerIterator()->current();
if ($test instanceof TestSuite) {
return true;
}
$name = Descriptor::getTestSignature($test);
$index = Descriptor::getTestDataSetIndex($test);
if (!is_null($index)) {
$name .= " with data set #{$index}";
}
$accepted = preg_match($this->filter, $name, $matches);
// This fix the issue when an invalid DataProvider method generate a warning
// See https://github.com/Codeception/Codeception/issues/4888
if ($test instanceof WarningTestCase) {
$message = $test->getMessage();
$accepted = preg_match($this->filter, $message, $matches);
}
if ($accepted && $this->filterMax !== null) {
$set = end($matches);
$accepted = $set >= $this->filterMin && $set <= $this->filterMax;
}
return (bool) $accepted;
}
}