44
55namespace Codeception \Module ;
66
7- use Codeception \Util \FileSystem as Util ;
8- use Symfony \Component \Finder \Finder ;
7+ use Codeception \Configuration ;
98use Codeception \Module ;
9+ use Codeception \PHPUnit \TestCase ;
1010use Codeception \TestInterface ;
11- use Codeception \Configuration ;
11+ use Codeception \Util \FileSystem as Util ;
12+ use PHPUnit \Framework \AssertionFailedError ;
13+ use Symfony \Component \Finder \Finder ;
1214
1315/**
1416 * Module for testing local filesystem.
2426 */
2527class Filesystem extends Module
2628{
27- protected $ file ;
28- /**
29- * @var string|null
30- */
31- protected $ filepath ;
29+ protected string $ file = '' ;
3230
33- /**
34- * @var string
35- */
36- protected $ path = '' ;
31+ protected string $ filePath = '' ;
32+
33+ protected string $ path = '' ;
3734
3835 public function _before (TestInterface $ test ): void
3936 {
@@ -56,6 +53,7 @@ protected function absolutizePath(string $path): string
5653 if (strpos ($ path , '/ ' ) === 0 ) {
5754 return $ path ;
5855 }
56+
5957 // windows
6058 if (strpos ($ path , ': \\' ) === 1 ) {
6159 return $ path ;
@@ -78,7 +76,7 @@ protected function absolutizePath(string $path): string
7876 public function openFile (string $ filename ): void
7977 {
8078 $ this ->file = file_get_contents ($ this ->absolutizePath ($ filename ));
81- $ this ->filepath = $ filename ;
79+ $ this ->filePath = $ filename ;
8280 }
8381
8482 /**
@@ -92,8 +90,9 @@ public function openFile(string $filename): void
9290 public function deleteFile (string $ filename ): void
9391 {
9492 if (!file_exists ($ this ->absolutizePath ($ filename ))) {
95- \ Codeception \ PHPUnit \ TestCase::fail ('file not found ' );
93+ TestCase::fail ('file not found ' );
9694 }
95+
9796 unlink ($ this ->absolutizePath ($ filename ));
9897 }
9998
@@ -162,6 +161,7 @@ public function seeNumberNewLines(int $number): void
162161 "The number of new lines does not match with {$ number }"
163162 );
164163 }
164+
165165 /**
166166 * Checks that contents of currently opened file matches $regex
167167 */
@@ -185,7 +185,7 @@ public function seeThisFileMatches(string $regex): void
185185 public function seeFileContentsEqual (string $ text ): void
186186 {
187187 $ file = str_replace ("\r" , '' , $ this ->file );
188- \ Codeception \ PHPUnit \ TestCase::assertEquals ($ text , $ file );
188+ TestCase::assertEquals ($ text , $ file );
189189 }
190190
191191 /**
@@ -207,7 +207,7 @@ public function dontSeeInThisFile(string $text): void
207207 */
208208 public function deleteThisFile (): void
209209 {
210- $ this ->deleteFile ($ this ->filepath );
210+ $ this ->deleteFile ($ this ->filePath );
211211 }
212212
213213 /**
@@ -223,7 +223,7 @@ public function seeFileFound(string $filename, string $path = ''): void
223223 {
224224 if ($ path === '' && file_exists ($ filename )) {
225225 $ this ->openFile ($ filename );
226- \ Codeception \ PHPUnit \ TestCase::assertFileExists ($ filename );
226+ TestCase::assertFileExists ($ filename );
227227 return ;
228228 }
229229
@@ -234,7 +234,7 @@ public function seeFileFound(string $filename, string $path = ''): void
234234 }
235235
236236 $ this ->openFile ($ found );
237- \ Codeception \ PHPUnit \ TestCase::assertFileExists ($ found );
237+ TestCase::assertFileExists ($ found );
238238 }
239239
240240 /**
@@ -243,25 +243,25 @@ public function seeFileFound(string $filename, string $path = ''): void
243243 public function dontSeeFileFound (string $ filename , string $ path = '' ): void
244244 {
245245 if ($ path === '' ) {
246- \ Codeception \ PHPUnit \ TestCase::assertFileNotExists ($ filename );
246+ TestCase::assertFileDoesNotExist ($ filename );
247247 return ;
248248 }
249249
250250 $ found = $ this ->findFileInPath ($ filename , $ path );
251251
252252 if ($ found === false ) {
253253 //this line keeps a count of assertions correct
254- \ Codeception \ PHPUnit \ TestCase::assertTrue (true );
254+ TestCase::assertTrue (true );
255255 return ;
256256 }
257257
258- \ Codeception \ PHPUnit \ TestCase::assertFileNotExists ($ found );
258+ TestCase::assertFileDoesNotExist ($ found );
259259 }
260260
261261 /**
262262 * Finds the first matching file
263263 *
264- * @throws \PHPUnit\Framework\ AssertionFailedError When path does not exist
264+ * @throws AssertionFailedError When path does not exist
265265 * @return string|false Path to the first matching file
266266 */
267267 private function findFileInPath (string $ filename , string $ path )
0 commit comments