Passed
Pull Request — master (#227)
by Dmitriy
02:52
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, [$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
    public function testStringMatches()
44
    {
45
        $this->assertTrue(
46
            BacktraceIgnoreMatcher::doesStringMatchPattern(
47
                'dev/123/456',
48
                ['dev/123/456']
49
            )
50
        );
51
        $this->assertTrue(
52
            BacktraceIgnoreMatcher::doesStringMatchPattern(
53
                'dev/123/456',
54
                ['456']
55
            )
56
        );
57
        $this->assertTrue(
58
            BacktraceIgnoreMatcher::doesStringMatchPattern(
59
                'dev/123/456',
60
                ['dev/.*/456']
61
            )
62
        );
63
        $this->assertTrue(
64
            BacktraceIgnoreMatcher::doesStringMatchPattern(
65
                'dev/123/456',
66
                ['dev*/456', 'dev/123/*']
67
            )
68
        );
69
    }
70
}
71