|
19 | 19 | #[Small] |
20 | 20 | final class FilterTest extends TestCase |
21 | 21 | { |
22 | | - private Filter $filter; |
23 | | - |
24 | | - protected function setUp(): void |
25 | | - { |
26 | | - $this->filter = new Filter; |
27 | | - } |
28 | | - |
29 | 22 | public function testIsInitiallyEmpty(): void |
30 | 23 | { |
31 | | - $this->assertTrue($this->filter->isEmpty()); |
| 24 | + $filter = new Filter; |
| 25 | + |
| 26 | + $this->assertTrue($filter->isEmpty()); |
32 | 27 | } |
33 | 28 |
|
34 | 29 | public function testSingleFileCanBeAdded(): void |
35 | 30 | { |
| 31 | + $filter = new Filter; |
| 32 | + |
36 | 33 | $file = realpath(__DIR__ . '/../_files/filter/a.php'); |
37 | 34 |
|
38 | | - $this->filter->includeFile($file); |
| 35 | + $filter->includeFile($file); |
39 | 36 |
|
40 | | - $this->assertFalse($this->filter->isEmpty()); |
| 37 | + $this->assertFalse($filter->isEmpty()); |
41 | 38 |
|
42 | 39 | $this->assertSame( |
43 | 40 | [ |
44 | 41 | $file, |
45 | 42 | ], |
46 | | - $this->filter->files(), |
| 43 | + $filter->files(), |
47 | 44 | ); |
48 | 45 | } |
49 | 46 |
|
50 | 47 | public function testMultipleFilesCanBeAdded(): void |
51 | 48 | { |
| 49 | + $filter = new Filter; |
| 50 | + |
52 | 51 | $files = [ |
53 | 52 | realpath(__DIR__ . '/../_files/filter/a.php'), |
54 | 53 | realpath(__DIR__ . '/../_files/filter/b.php'), |
55 | 54 | ]; |
56 | 55 |
|
57 | | - $this->filter->includeFiles($files); |
| 56 | + $filter->includeFiles($files); |
58 | 57 |
|
59 | | - $this->assertSame($files, $this->filter->files()); |
| 58 | + $this->assertSame($files, $filter->files()); |
60 | 59 | } |
61 | 60 |
|
62 | 61 | public function testDeterminesWhetherStringContainsNameOfRealFileThatExists(): void |
63 | 62 | { |
64 | | - $this->assertFalse($this->filter->isFile('vfs://root/a/path')); |
65 | | - $this->assertFalse($this->filter->isFile('xdebug://debug-eval')); |
66 | | - $this->assertFalse($this->filter->isFile('eval()\'d code')); |
67 | | - $this->assertFalse($this->filter->isFile('runtime-created function')); |
68 | | - $this->assertFalse($this->filter->isFile('assert code')); |
69 | | - $this->assertFalse($this->filter->isFile('regexp code')); |
70 | | - $this->assertTrue($this->filter->isFile(__DIR__ . '/../_files/filter/a.php')); |
| 63 | + $filter = new Filter; |
| 64 | + |
| 65 | + $this->assertFalse($filter->isFile('vfs://root/a/path')); |
| 66 | + $this->assertFalse($filter->isFile('xdebug://debug-eval')); |
| 67 | + $this->assertFalse($filter->isFile('eval()\'d code')); |
| 68 | + $this->assertFalse($filter->isFile('runtime-created function')); |
| 69 | + $this->assertFalse($filter->isFile('assert code')); |
| 70 | + $this->assertFalse($filter->isFile('regexp code')); |
| 71 | + $this->assertTrue($filter->isFile(__DIR__ . '/../_files/filter/a.php')); |
71 | 72 | } |
72 | 73 |
|
73 | 74 | public function testIncludedFileIsNotFiltered(): void |
74 | 75 | { |
75 | | - $this->filter->includeFile(realpath(__DIR__ . '/../_files/filter/a.php')); |
| 76 | + $filter = new Filter; |
| 77 | + |
| 78 | + $filter->includeFile(realpath(__DIR__ . '/../_files/filter/a.php')); |
76 | 79 |
|
77 | | - $this->assertFalse($this->filter->isExcluded(realpath(__DIR__ . '/../_files/filter/a.php'))); |
| 80 | + $this->assertFalse($filter->isExcluded(realpath(__DIR__ . '/../_files/filter/a.php'))); |
78 | 81 | } |
79 | 82 |
|
80 | 83 | public function testNotIncludedFileIsFiltered(): void |
81 | 84 | { |
82 | | - $this->filter->includeFile(realpath(__DIR__ . '/../_files/filter/a.php')); |
| 85 | + $filter = new Filter; |
83 | 86 |
|
84 | | - $this->assertTrue($this->filter->isExcluded(realpath(__DIR__ . '/../_files/filter/b.php'))); |
| 87 | + $filter->includeFile(realpath(__DIR__ . '/../_files/filter/a.php')); |
| 88 | + |
| 89 | + $this->assertTrue($filter->isExcluded(realpath(__DIR__ . '/../_files/filter/b.php'))); |
85 | 90 | } |
86 | 91 |
|
87 | 92 | public function testNonFilesAreFiltered(): void |
88 | 93 | { |
89 | | - $this->assertTrue($this->filter->isExcluded('vfs://root/a/path')); |
90 | | - $this->assertTrue($this->filter->isExcluded('xdebug://debug-eval')); |
91 | | - $this->assertTrue($this->filter->isExcluded('eval()\'d code')); |
92 | | - $this->assertTrue($this->filter->isExcluded('runtime-created function')); |
93 | | - $this->assertTrue($this->filter->isExcluded('assert code')); |
94 | | - $this->assertTrue($this->filter->isExcluded('regexp code')); |
| 94 | + $filter = new Filter; |
| 95 | + |
| 96 | + $this->assertTrue($filter->isExcluded('vfs://root/a/path')); |
| 97 | + $this->assertTrue($filter->isExcluded('xdebug://debug-eval')); |
| 98 | + $this->assertTrue($filter->isExcluded('eval()\'d code')); |
| 99 | + $this->assertTrue($filter->isExcluded('runtime-created function')); |
| 100 | + $this->assertTrue($filter->isExcluded('assert code')); |
| 101 | + $this->assertTrue($filter->isExcluded('regexp code')); |
95 | 102 | } |
96 | 103 |
|
97 | 104 | #[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/664')] |
98 | 105 | public function testTryingToAddFileThatDoesNotExistDoesNotChangeFilter(): void |
99 | 106 | { |
100 | | - $this->filter->includeFile('does_not_exist'); |
| 107 | + $filter = new Filter; |
| 108 | + |
| 109 | + $filter->includeFile('does_not_exist'); |
101 | 110 |
|
102 | | - $this->assertTrue($this->filter->isEmpty()); |
103 | | - $this->assertSame([], $this->filter->files()); |
| 111 | + $this->assertTrue($filter->isEmpty()); |
| 112 | + $this->assertSame([], $filter->files()); |
104 | 113 | } |
105 | 114 | } |
0 commit comments