1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Tests\Unit\Helper; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use stdClass; |
9
|
|
|
use Yiisoft\Yii\Debug\Helper\BacktraceIgnoreMatcher; |
10
|
|
|
|
11
|
|
|
final class BacktraceIgnoreMatcherTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testClassIgnorance(): void |
14
|
|
|
{ |
15
|
|
|
$backtrace = debug_backtrace(); |
16
|
|
|
|
17
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByClass($backtrace, [self::class])); |
18
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByClass($backtrace, [stdClass::class])); |
19
|
|
|
|
20
|
|
|
$backtrace[3] = $backtrace[0]; |
21
|
|
|
|
22
|
|
|
$this->assertTrue(BacktraceIgnoreMatcher::isIgnoredByClass($backtrace, [self::class])); |
23
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByClass($backtrace, [stdClass::class])); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testFileIgnorance(): void |
27
|
|
|
{ |
28
|
|
|
$backtrace = debug_backtrace(); |
29
|
|
|
$reflection = new \ReflectionClass(TestCase::class); |
30
|
|
|
$file = $reflection->getFileName(); |
31
|
|
|
|
32
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByFile($backtrace, [preg_quote($file)])); |
33
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByFile($backtrace, [preg_quote(__FILE__)])); |
34
|
|
|
|
35
|
|
|
$backtrace[2] = $backtrace[0]; |
36
|
|
|
|
37
|
|
|
$this->assertTrue(BacktraceIgnoreMatcher::isIgnoredByFile($backtrace, [preg_quote($file)])); |
38
|
|
|
$this->assertTrue( |
39
|
|
|
BacktraceIgnoreMatcher::isIgnoredByFile( |
40
|
|
|
$backtrace, |
41
|
|
|
[preg_quote(dirname($file) . DIRECTORY_SEPARATOR) . '*'] |
42
|
|
|
) |
43
|
|
|
); |
44
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByFile($backtrace, [preg_quote(__FILE__)])); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testStringMatches(): void |
48
|
|
|
{ |
49
|
|
|
$this->assertTrue( |
50
|
|
|
BacktraceIgnoreMatcher::doesStringMatchPattern( |
51
|
|
|
'dev/123/456', |
52
|
|
|
['dev/123/456'] |
53
|
|
|
) |
54
|
|
|
); |
55
|
|
|
$this->assertTrue( |
56
|
|
|
BacktraceIgnoreMatcher::doesStringMatchPattern( |
57
|
|
|
'dev/123/456', |
58
|
|
|
['456'] |
59
|
|
|
) |
60
|
|
|
); |
61
|
|
|
$this->assertTrue( |
62
|
|
|
BacktraceIgnoreMatcher::doesStringMatchPattern( |
63
|
|
|
'dev/123/456', |
64
|
|
|
['dev/.*/456'] |
65
|
|
|
) |
66
|
|
|
); |
67
|
|
|
$this->assertTrue( |
68
|
|
|
BacktraceIgnoreMatcher::doesStringMatchPattern( |
69
|
|
|
'dev/123/456', |
70
|
|
|
['dev*/456', 'dev/123/*'] |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testEmptyBacktrace(): void |
76
|
|
|
{ |
77
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::doesStringMatchPattern('dev/123/456', [])); |
78
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByFile([], ['dev/123/456'])); |
79
|
|
|
$this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByClass([], ['dev/123/456'])); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|