forked from sebastianbergmann/php-code-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterTest.php
More file actions
119 lines (93 loc) · 3.55 KB
/
Copy pathFilterTest.php
File metadata and controls
119 lines (93 loc) · 3.55 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage;
use function realpath;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\Ticket;
use PHPUnit\Framework\TestCase;
#[CoversClass(Filter::class)]
#[Small]
final class FilterTest extends TestCase
{
public function testIsInitiallyEmpty(): void
{
$filter = new Filter;
$this->assertTrue($filter->isEmpty());
}
public function testSingleFileCanBeAdded(): void
{
$filter = new Filter;
$file = realpath(__DIR__ . '/../_files/filter/a.php');
$filter->includeFile($file);
$this->assertFalse($filter->isEmpty());
$this->assertSame(
[
$file,
],
$filter->files(),
);
}
public function testMultipleFilesCanBeAdded(): void
{
$filter = new Filter;
$files = [
realpath(__DIR__ . '/../_files/filter/a.php'),
realpath(__DIR__ . '/../_files/filter/b.php'),
];
$filter->includeFiles($files);
$this->assertSame($files, $filter->files());
}
public function testDeterminesWhetherStringContainsNameOfRealFileThatExists(): void
{
$filter = new Filter;
$this->assertFalse($filter->isFile('vfs://root/a/path'));
$this->assertFalse($filter->isFile('xdebug://debug-eval'));
$this->assertFalse($filter->isFile('eval()\'d code'));
$this->assertFalse($filter->isFile('runtime-created function'));
$this->assertFalse($filter->isFile('assert code'));
$this->assertFalse($filter->isFile('regexp code'));
$this->assertTrue($filter->isFile(__DIR__ . '/../_files/filter/a.php'));
}
public function testIncludedFileIsNotFiltered(): void
{
$filter = new Filter;
$filter->includeFile(realpath(__DIR__ . '/../_files/filter/a.php'));
$this->assertFalse($filter->isExcluded(realpath(__DIR__ . '/../_files/filter/a.php')));
/**
* Assertion is performed twice to test the is-cached path.
*/
$this->assertFalse($filter->isExcluded(realpath(__DIR__ . '/../_files/filter/a.php')));
}
public function testNotIncludedFileIsFiltered(): void
{
$filter = new Filter;
$filter->includeFile(realpath(__DIR__ . '/../_files/filter/a.php'));
$this->assertTrue($filter->isExcluded(realpath(__DIR__ . '/../_files/filter/b.php')));
}
public function testNonFilesAreFiltered(): void
{
$filter = new Filter;
$this->assertTrue($filter->isExcluded('vfs://root/a/path'));
$this->assertTrue($filter->isExcluded('xdebug://debug-eval'));
$this->assertTrue($filter->isExcluded('eval()\'d code'));
$this->assertTrue($filter->isExcluded('runtime-created function'));
$this->assertTrue($filter->isExcluded('assert code'));
$this->assertTrue($filter->isExcluded('regexp code'));
}
#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/664')]
public function testTryingToAddFileThatDoesNotExistDoesNotChangeFilter(): void
{
$filter = new Filter;
$filter->includeFile('does_not_exist');
$this->assertTrue($filter->isEmpty());
$this->assertSame([], $filter->files());
}
}