Passed
Pull Request — master (#227)
by Dmitriy
04:30 queued 01:40
created

BacktraceIgnoreMatcherTest::testFileIgnorance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 16
rs 9.9332
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()
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()
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, [__FILE__]));
34
35
        $backtrace[2] = $backtrace[0];
36
37
        $this->assertTrue(BacktraceIgnoreMatcher::isIgnoredByFile($backtrace, [$file]));
38
        $this->assertTrue(
39
            BacktraceIgnoreMatcher::isIgnoredByFile($backtrace, [dirname($file) . DIRECTORY_SEPARATOR . '*'])
40
        );
41
        $this->assertFalse(BacktraceIgnoreMatcher::isIgnoredByFile($backtrace, [__FILE__]));
42
    }
43
44
    public function testStringMatches()
45
    {
46
        $this->assertTrue(
47
            BacktraceIgnoreMatcher::doesStringMatchPattern(
48
                'dev/123/456',
49
                ['dev/123/456']
50
            )
51
        );
52
        $this->assertTrue(
53
            BacktraceIgnoreMatcher::doesStringMatchPattern(
54
                'dev/123/456',
55
                ['456']
56
            )
57
        );
58
        $this->assertTrue(
59
            BacktraceIgnoreMatcher::doesStringMatchPattern(
60
                'dev/123/456',
61
                ['dev/.*/456']
62
            )
63
        );
64
        $this->assertTrue(
65
            BacktraceIgnoreMatcher::doesStringMatchPattern(
66
                'dev/123/456',
67
                ['dev*/456', 'dev/123/*']
68
            )
69
        );
70
    }
71
}
72