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