99 */
1010namespace SebastianBergmann \CodeCoverage ;
1111
12- use function sort ;
13- use function unserialize ;
12+ use function realpath ;
1413use PHPUnit \Framework \TestCase ;
15- use SebastianBergmann \FileIterator \Facade as FileIteratorFacade ;
1614
1715/**
1816 * @covers \SebastianBergmann\CodeCoverage\Filter
@@ -24,116 +22,73 @@ final class FilterTest extends TestCase
2422 */
2523 private $ filter ;
2624
27- /**
28- * @var array
29- */
30- private $ files = [];
31-
3225 protected function setUp (): void
3326 {
3427 $ this ->filter = new Filter ;
28+ }
3529
36- $ this ->files = [
37- TEST_FILES_PATH . 'BankAccount.php ' ,
38- TEST_FILES_PATH . 'BankAccountTest.php ' ,
39- TEST_FILES_PATH . 'ClassThatUsesAnonymousClass.php ' ,
40- TEST_FILES_PATH . 'ClassWithNameThatIsPartOfItsNamespacesName.php ' ,
41- TEST_FILES_PATH . 'CoverageClassExtendedTest.php ' ,
42- TEST_FILES_PATH . 'CoverageClassTest.php ' ,
43- TEST_FILES_PATH . 'CoverageFunctionParenthesesTest.php ' ,
44- TEST_FILES_PATH . 'CoverageFunctionParenthesesWhitespaceTest.php ' ,
45- TEST_FILES_PATH . 'CoverageFunctionTest.php ' ,
46- TEST_FILES_PATH . 'CoverageMethodOneLineAnnotationTest.php ' ,
47- TEST_FILES_PATH . 'CoverageMethodParenthesesTest.php ' ,
48- TEST_FILES_PATH . 'CoverageMethodParenthesesWhitespaceTest.php ' ,
49- TEST_FILES_PATH . 'CoverageMethodTest.php ' ,
50- TEST_FILES_PATH . 'CoverageNoneTest.php ' ,
51- TEST_FILES_PATH . 'CoverageNotPrivateTest.php ' ,
52- TEST_FILES_PATH . 'CoverageNotProtectedTest.php ' ,
53- TEST_FILES_PATH . 'CoverageNotPublicTest.php ' ,
54- TEST_FILES_PATH . 'CoverageNothingTest.php ' ,
55- TEST_FILES_PATH . 'CoveragePrivateTest.php ' ,
56- TEST_FILES_PATH . 'CoverageProtectedTest.php ' ,
57- TEST_FILES_PATH . 'CoveragePublicTest.php ' ,
58- TEST_FILES_PATH . 'CoverageTwoDefaultClassAnnotations.php ' ,
59- TEST_FILES_PATH . 'CoveredClass.php ' ,
60- TEST_FILES_PATH . 'CoveredFunction.php ' ,
61- TEST_FILES_PATH . 'NamespaceCoverageClassExtendedTest.php ' ,
62- TEST_FILES_PATH . 'NamespaceCoverageClassTest.php ' ,
63- TEST_FILES_PATH . 'NamespaceCoverageCoversClassPublicTest.php ' ,
64- TEST_FILES_PATH . 'NamespaceCoverageCoversClassTest.php ' ,
65- TEST_FILES_PATH . 'NamespaceCoverageMethodTest.php ' ,
66- TEST_FILES_PATH . 'NamespaceCoverageNotPrivateTest.php ' ,
67- TEST_FILES_PATH . 'NamespaceCoverageNotProtectedTest.php ' ,
68- TEST_FILES_PATH . 'NamespaceCoverageNotPublicTest.php ' ,
69- TEST_FILES_PATH . 'NamespaceCoveragePrivateTest.php ' ,
70- TEST_FILES_PATH . 'NamespaceCoverageProtectedTest.php ' ,
71- TEST_FILES_PATH . 'NamespaceCoveragePublicTest.php ' ,
72- TEST_FILES_PATH . 'NamespaceCoveredClass.php ' ,
73- TEST_FILES_PATH . 'NamespacedBankAccount.php ' ,
74- TEST_FILES_PATH . 'NotExistingCoveredElementTest.php ' ,
75- TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php ' ,
76- TEST_FILES_PATH . 'source_with_class_and_fqcn_constant.php ' ,
77- TEST_FILES_PATH . 'source_with_empty_class.php ' ,
78- TEST_FILES_PATH . 'source_with_ignore.php ' ,
79- TEST_FILES_PATH . 'source_with_interface.php ' ,
80- TEST_FILES_PATH . 'source_with_namespace.php ' ,
81- TEST_FILES_PATH . 'source_with_oneline_annotations.php ' ,
82- TEST_FILES_PATH . 'source_with_use_statements.php ' ,
83- TEST_FILES_PATH . 'source_without_ignore.php ' ,
84- TEST_FILES_PATH . 'source_without_namespace.php ' ,
85- ];
30+ public function testIsInitiallyEmpty (): void
31+ {
32+ $ this ->assertTrue ($ this ->filter ->isEmpty ());
8633 }
8734
8835 public function testSingleFileCanBeAdded (): void
8936 {
90- $ this ->filter ->includeFile ($ this ->files [0 ]);
37+ $ file = realpath (__DIR__ . '/../_files/filter/a.php ' );
38+
39+ $ this ->filter ->includeFile ($ file );
40+
41+ $ this ->assertFalse ($ this ->filter ->isEmpty ());
9142
92- $ this ->assertEquals (
93- [$ this ->files [0 ]],
43+ $ this ->assertSame (
44+ [
45+ $ file ,
46+ ],
9447 $ this ->filter ->files ()
9548 );
9649 }
9750
9851 public function testMultipleFilesCanBeAdded (): void
9952 {
100- $ files = ( new FileIteratorFacade )-> getFilesAsArray (
101- TEST_FILES_PATH ,
102- $ suffixes = ' . php '
103- ) ;
53+ $ files = [
54+ realpath ( __DIR__ . ' /../_files/filter/a.php ' ) ,
55+ realpath ( __DIR__ . ' /../_files/filter/b. php '),
56+ ] ;
10457
10558 $ this ->filter ->includeFiles ($ files );
10659
107- $ files = $ this ->filter ->files ();
108- sort ($ files );
109-
110- $ this ->assertEquals ($ this ->files , $ files );
60+ $ this ->assertSame ($ files , $ this ->filter ->files ());
11161 }
11262
11363 public function testDirectoryCanBeAdded (): void
11464 {
115- $ this ->filter ->includeDirectory (TEST_FILES_PATH );
116-
117- $ files = $ this ->filter ->files ();
118- sort ($ files );
65+ $ this ->filter ->includeDirectory (__DIR__ . '/../_files/filter ' );
11966
120- $ this ->assertEquals ($ this ->files , $ files );
67+ $ this ->assertSame (
68+ [
69+ realpath (__DIR__ . '/../_files/filter/a.php ' ),
70+ realpath (__DIR__ . '/../_files/filter/b.php ' ),
71+ ],
72+ $ this ->filter ->files ()
73+ );
12174 }
12275
12376 public function testSingleFileCanBeRemoved (): void
12477 {
125- $ this ->filter ->includeFile ($ this -> files [ 0 ] );
126- $ this ->filter ->excludeFile ($ this -> files [ 0 ] );
78+ $ this ->filter ->includeFile (realpath ( __DIR__ . ' /../_files/filter/a.php ' ) );
79+ $ this ->filter ->excludeFile (realpath ( __DIR__ . ' /../_files/filter/a.php ' ) );
12780
128- $ this ->assertEquals ([], $ this ->filter ->files ());
81+ $ this ->assertTrue ($ this ->filter ->isEmpty ());
82+ $ this ->assertSame ([], $ this ->filter ->files ());
12983 }
13084
13185 public function testDirectoryCanBeRemoved (): void
13286 {
133- $ this ->filter ->includeDirectory (TEST_FILES_PATH );
134- $ this ->filter ->excludeDirectory (TEST_FILES_PATH );
87+ $ this ->filter ->includeDirectory (__DIR__ . ' /../_files/filter ' );
88+ $ this ->filter ->excludeDirectory (__DIR__ . ' /../_files/filter ' );
13589
136- $ this ->assertEquals ([], $ this ->filter ->files ());
90+ $ this ->assertTrue ($ this ->filter ->isEmpty ());
91+ $ this ->assertSame ([], $ this ->filter ->files ());
13792 }
13893
13994 public function testDeterminesWhetherStringContainsNameOfRealFileThatExists (): void
@@ -144,21 +99,21 @@ public function testDeterminesWhetherStringContainsNameOfRealFileThatExists(): v
14499 $ this ->assertFalse ($ this ->filter ->isFile ('runtime-created function ' ));
145100 $ this ->assertFalse ($ this ->filter ->isFile ('assert code ' ));
146101 $ this ->assertFalse ($ this ->filter ->isFile ('regexp code ' ));
147- $ this ->assertTrue ($ this ->filter ->isFile (__FILE__ ));
102+ $ this ->assertTrue ($ this ->filter ->isFile (__DIR__ . ' /../_files/filter/a.php ' ));
148103 }
149104
150105 public function testIncludedFileIsNotFiltered (): void
151106 {
152- $ this ->filter ->includeFile ($ this -> files [ 0 ] );
107+ $ this ->filter ->includeFile (realpath ( __DIR__ . ' /../_files/filter/a.php ' ) );
153108
154- $ this ->assertFalse ($ this ->filter ->isExcluded ($ this -> files [ 0 ] ));
109+ $ this ->assertFalse ($ this ->filter ->isExcluded (realpath ( __DIR__ . ' /../_files/filter/a.php ' ) ));
155110 }
156111
157112 public function testNotIncludedFileIsFiltered (): void
158113 {
159- $ this ->filter ->includeFile ($ this -> files [ 0 ] );
114+ $ this ->filter ->includeFile (realpath ( __DIR__ . ' /../_files/filter/a.php ' ) );
160115
161- $ this ->assertTrue ($ this ->filter ->isExcluded ($ this -> files [ 1 ] ));
116+ $ this ->assertTrue ($ this ->filter ->isExcluded (realpath ( __DIR__ . ' /../_files/filter/b.php ' ) ));
162117 }
163118
164119 public function testNonFilesAreFiltered (): void
@@ -176,10 +131,9 @@ public function testNonFilesAreFiltered(): void
176131 */
177132 public function testTryingToAddFileThatDoesNotExistDoesNotChangeFilter (): void
178133 {
179- $ filter = new Filter ;
180-
181- $ filter ->includeFile ('does_not_exist ' );
134+ $ this ->filter ->includeFile ('does_not_exist ' );
182135
183- $ this ->assertEmpty ($ filter ->files ());
136+ $ this ->assertTrue ($ this ->filter ->isEmpty ());
137+ $ this ->assertSame ([], $ this ->filter ->files ());
184138 }
185139}
0 commit comments