11<?php
2+
3+ declare (strict_types=1 );
4+
25namespace Codeception \Module ;
36
47use Codeception \Util \FileSystem as Util ;
58use Symfony \Component \Finder \Finder ;
6- use Codeception \Module as CodeceptionModule ;
9+ use Codeception \Module ;
710use Codeception \TestInterface ;
811use Codeception \Configuration ;
912
1922 *
2023 * Module was developed to test Codeception itself.
2124 */
22- class Filesystem extends CodeceptionModule
25+ class Filesystem extends Module
2326{
24- protected $ file = null ;
25- protected $ filepath = null ;
27+ protected $ file ;
28+ /**
29+ * @var string|null
30+ */
31+ protected $ filepath ;
2632
33+ /**
34+ * @var string
35+ */
2736 protected $ path = '' ;
2837
29- public function _before (TestInterface $ test )
38+ public function _before (TestInterface $ test ): void
3039 {
3140 $ this ->path = Configuration::projectDir ();
3241 }
3342
3443 /**
3544 * Enters a directory In local filesystem.
3645 * Project root directory is used by default
37- *
38- * @param string $path
3946 */
40- public function amInPath ($ path )
47+ public function amInPath (string $ path ): void
4148 {
4249 chdir ($ this ->path = $ this ->absolutizePath ($ path ) . DIRECTORY_SEPARATOR );
4350 $ this ->debug ('Moved to ' . getcwd ());
4451 }
4552
46- /**
47- * @param string $path
48- * @return string
49- */
50- protected function absolutizePath ($ path )
53+ protected function absolutizePath (string $ path ): string
5154 {
5255 // *nix way
5356 if (strpos ($ path , '/ ' ) === 0 ) {
@@ -70,12 +73,9 @@ protected function absolutizePath($path)
7073 * <?php
7174 * $I->openFile('composer.json');
7275 * $I->seeInThisFile('codeception/codeception');
73- * ?>
7476 * ```
75- *
76- * @param string $filename
7777 */
78- public function openFile ($ filename )
78+ public function openFile (string $ filename ): void
7979 {
8080 $ this ->file = file_get_contents ($ this ->absolutizePath ($ filename ));
8181 $ this ->filepath = $ filename ;
@@ -87,12 +87,9 @@ public function openFile($filename)
8787 * ``` php
8888 * <?php
8989 * $I->deleteFile('composer.lock');
90- * ?>
9190 * ```
92- *
93- * @param string $filename
9491 */
95- public function deleteFile ($ filename )
92+ public function deleteFile (string $ filename ): void
9693 {
9794 if (!file_exists ($ this ->absolutizePath ($ filename ))) {
9895 \Codeception \PHPUnit \TestCase::fail ('file not found ' );
@@ -106,12 +103,9 @@ public function deleteFile($filename)
106103 * ``` php
107104 * <?php
108105 * $I->deleteDir('vendor');
109- * ?>
110106 * ```
111- *
112- * @param string $dirname
113107 */
114- public function deleteDir ($ dirname )
108+ public function deleteDir (string $ dirname ): void
115109 {
116110 $ dir = $ this ->absolutizePath ($ dirname );
117111 Util::deleteDir ($ dir );
@@ -123,13 +117,9 @@ public function deleteDir($dirname)
123117 * ``` php
124118 * <?php
125119 * $I->copyDir('vendor','old_vendor');
126- * ?>
127120 * ```
128- *
129- * @param string $src
130- * @param string $dst
131121 */
132- public function copyDir ($ src , $ dst )
122+ public function copyDir (string $ src , string $ dst ): void
133123 {
134124 Util::copyDir ($ src , $ dst );
135125 }
@@ -143,14 +133,11 @@ public function copyDir($src, $dst)
143133 * <?php
144134 * $I->openFile('composer.json');
145135 * $I->seeInThisFile('codeception/codeception');
146- * ?>
147136 * ```
148- *
149- * @param string $text
150137 */
151- public function seeInThisFile ($ text )
138+ public function seeInThisFile (string $ text ): void
152139 {
153- $ this ->assertStringContainsString ($ text , $ this ->file , "No text ' $ text' in currently opened file " );
140+ $ this ->assertStringContainsString ($ text , $ this ->file , "No text ' { $ text} ' in currently opened file " );
154141 }
155142
156143 /**
@@ -162,28 +149,25 @@ public function seeInThisFile($text)
162149 * <?php
163150 * $I->openFile('composer.json');
164151 * $I->seeNumberNewLines(5);
165- * ?>
166152 * ```
167153 *
168154 * @param int $number New lines
169155 */
170- public function seeNumberNewLines ($ number )
156+ public function seeNumberNewLines (int $ number ): void
171157 {
172- $ lines = preg_split ('/ \n|\r/ ' , $ this ->file );
158+ $ lines = preg_split ('# \n|\r# ' , $ this ->file );
173159
174160 $ this ->assertTrue (
175- ( int ) $ number === count ($ lines ),
176- "The number of new lines does not match with $ number "
161+ $ number === count ($ lines ),
162+ "The number of new lines does not match with { $ number} "
177163 );
178164 }
179165 /**
180166 * Checks that contents of currently opened file matches $regex
181- *
182- * @param string $regex
183167 */
184- public function seeThisFileMatches ($ regex )
168+ public function seeThisFileMatches (string $ regex ): void
185169 {
186- $ this ->assertRegExp ($ regex , $ this ->file , "Contents of currently opened file does not match ' $ regex' " );
170+ $ this ->assertRegExp ($ regex , $ this ->file , "Contents of currently opened file does not match ' { $ regex} ' " );
187171 }
188172
189173 /**
@@ -196,12 +180,9 @@ public function seeThisFileMatches($regex)
196180 * <?php
197181 * $I->openFile('process.pid');
198182 * $I->seeFileContentsEqual('3192');
199- * ?>
200183 * ```
201- *
202- * @param string $text
203184 */
204- public function seeFileContentsEqual ($ text )
185+ public function seeFileContentsEqual (string $ text ): void
205186 {
206187 $ file = str_replace ("\r" , '' , $ this ->file );
207188 \Codeception \PHPUnit \TestCase::assertEquals ($ text , $ file );
@@ -214,20 +195,17 @@ public function seeFileContentsEqual($text)
214195 * <?php
215196 * $I->openFile('composer.json');
216197 * $I->dontSeeInThisFile('codeception/codeception');
217- * ?>
218198 * ```
219- *
220- * @param string $text
221199 */
222- public function dontSeeInThisFile ($ text )
200+ public function dontSeeInThisFile (string $ text ): void
223201 {
224- $ this ->assertStringNotContainsString ($ text , $ this ->file , "Found text ' $ text' in currently opened file " );
202+ $ this ->assertStringNotContainsString ($ text , $ this ->file , "Found text ' { $ text} ' in currently opened file " );
225203 }
226204
227205 /**
228206 * Deletes a file
229207 */
230- public function deleteThisFile ()
208+ public function deleteThisFile (): void
231209 {
232210 $ this ->deleteFile ($ this ->filepath );
233211 }
@@ -239,13 +217,9 @@ public function deleteThisFile()
239217 * ``` php
240218 * <?php
241219 * $I->seeFileFound('UserModel.php','app/models');
242- * ?>
243220 * ```
244- *
245- * @param string $filename
246- * @param string $path
247221 */
248- public function seeFileFound ($ filename , $ path = '' )
222+ public function seeFileFound (string $ filename , string $ path = '' ): void
249223 {
250224 if ($ path === '' && file_exists ($ filename )) {
251225 $ this ->openFile ($ filename );
@@ -256,7 +230,7 @@ public function seeFileFound($filename, $path = '')
256230 $ found = $ this ->findFileInPath ($ filename , $ path );
257231
258232 if ($ found === false ) {
259- $ this ->fail (" File \" $ filename \ " not found at \" $ path\"" );
233+ $ this ->fail (sprintf ( ' File "%s " not found at "%s" ' , $ filename , $ path) );
260234 }
261235
262236 $ this ->openFile ($ found );
@@ -265,11 +239,8 @@ public function seeFileFound($filename, $path = '')
265239
266240 /**
267241 * Checks if file does not exist in path
268- *
269- * @param string $filename
270- * @param string $path
271242 */
272- public function dontSeeFileFound ($ filename , $ path = '' )
243+ public function dontSeeFileFound (string $ filename , string $ path = '' ): void
273244 {
274245 if ($ path === '' ) {
275246 \Codeception \PHPUnit \TestCase::assertFileNotExists ($ filename );
@@ -290,16 +261,14 @@ public function dontSeeFileFound($filename, $path = '')
290261 /**
291262 * Finds the first matching file
292263 *
293- * @param string $filename
294- * @param string $path
295264 * @throws \PHPUnit\Framework\AssertionFailedError When path does not exist
296265 * @return string|false Path to the first matching file
297266 */
298- private function findFileInPath ($ filename , $ path )
267+ private function findFileInPath (string $ filename , string $ path )
299268 {
300269 $ path = $ this ->absolutizePath ($ path );
301270 if (!file_exists ($ path )) {
302- $ this ->fail (" Directory does not exist: $ path" );
271+ $ this ->fail (sprintf ( ' Directory does not exist: %s ' , $ path) );
303272 }
304273
305274 $ files = Finder::create ()->files ()->name ($ filename )->in ($ path );
@@ -319,24 +288,18 @@ private function findFileInPath($filename, $path)
319288 * ``` php
320289 * <?php
321290 * $I->cleanDir('logs');
322- * ?>
323291 * ```
324- *
325- * @param string $dirname
326292 */
327- public function cleanDir ($ dirname )
293+ public function cleanDir (string $ dirname ): void
328294 {
329295 $ path = $ this ->absolutizePath ($ dirname );
330296 Util::doEmptyDir ($ path );
331297 }
332298
333299 /**
334300 * Saves contents to file
335- *
336- * @param string $filename
337- * @param string $contents
338301 */
339- public function writeToFile ($ filename , $ contents )
302+ public function writeToFile (string $ filename , string $ contents ): void
340303 {
341304 file_put_contents ($ filename , $ contents );
342305 }
0 commit comments