@@ -63,10 +63,12 @@ class MongoDb extends Module implements RequiresPackage
6363 * @var string
6464 */
6565 const DUMP_TYPE_JS = 'js ' ;
66+
6667 /**
6768 * @var string
6869 */
6970 const DUMP_TYPE_MONGODUMP = 'mongodump ' ;
71+
7072 /**
7173 * @var string
7274 */
@@ -78,16 +80,13 @@ class MongoDb extends Module implements RequiresPackage
7880 */
7981 public $ dbh ;
8082
81- /**
82- * @var
83- */
84- protected $ dumpFile ;
83+ protected ?string $ dumpFile = null ;
84+
85+ protected bool $ isDumpFileEmpty = true ;
8586
8687 /**
87- * @var bool
88+ * @var mixed|null
8889 */
89- protected $ isDumpFileEmpty = true ;
90-
9190 protected $ dbHash ;
9291
9392 /**
@@ -104,15 +103,9 @@ class MongoDb extends Module implements RequiresPackage
104103 'quiet ' => false ,
105104 ];
106105
107- /**
108- * @var bool
109- */
110- protected $ populated = false ;
106+ protected bool $ populated = false ;
111107
112- /**
113- * @var \Codeception\Lib\Driver\MongoDb
114- */
115- public $ driver ;
108+ public ?MongoDbDriver $ driver = null ;
116109
117110 /**
118111 * @var string[]
@@ -127,11 +120,12 @@ public function _initialize()
127120 $ this ->config ['user ' ],
128121 $ this ->config ['password ' ]
129122 );
130- } catch (MongoConnectionException $ e ) {
131- throw new ModuleException (__CLASS__ , $ e ->getMessage () . ' while creating Mongo connection ' );
123+ } catch (MongoConnectionException $ exception ) {
124+ throw new ModuleException (__CLASS__ ,
125+ $ exception ->getMessage () . ' while creating Mongo connection '
126+ );
132127 }
133128
134- // starting with loading dump
135129 if ($ this ->config ['populate ' ]) {
136130 $ this ->cleanup ();
137131 $ this ->loadDump ();
@@ -149,6 +143,7 @@ private function validateDump(): void
149143 Please, check path for dump file: " . $ this ->config ['dump ' ]
150144 );
151145 }
146+
152147 $ this ->dumpFile = Configuration::projectDir () . $ this ->config ['dump ' ];
153148 $ this ->isDumpFileEmpty = false ;
154149
@@ -158,6 +153,7 @@ private function validateDump(): void
158153 if (count (explode ("\n" , $ content )) === 0 ) {
159154 $ this ->isDumpFileEmpty = true ;
160155 }
156+
161157 return ;
162158 }
163159
@@ -169,6 +165,7 @@ private function validateDump(): void
169165 Please, check dump: " . $ this ->config ['dump ' ]
170166 );
171167 }
168+
172169 $ this ->isDumpFileEmpty = true ;
173170 $ dumpDir = dir ($ this ->dumpFile );
174171 while (false !== ($ entry = $ dumpDir ->read ())) {
@@ -177,6 +174,7 @@ private function validateDump(): void
177174 break ;
178175 }
179176 }
177+
180178 $ dumpDir ->close ();
181179 return ;
182180 }
@@ -188,13 +186,15 @@ private function validateDump(): void
188186 "Tar gunzip archives are not supported for Windows systems "
189187 );
190188 }
189+
191190 if (!preg_match ('#(\.tar\.gz|\.tgz)$# ' , $ this ->dumpFile )) {
192191 throw new ModuleConfigException (
193192 __CLASS__ ,
194193 "Dump file must be a valid tar gunzip archive. \n
195194 Please, check dump file: " . $ this ->config ['dump ' ]
196195 );
197196 }
197+
198198 return ;
199199 }
200200
@@ -235,16 +235,17 @@ protected function shouldCleanup(): bool
235235 protected function cleanup (): void
236236 {
237237 $ dbh = $ this ->driver ->getDbh ();
238- if (! $ dbh ) {
238+ if ($ dbh === null ) {
239239 throw new ModuleConfigException (
240240 __CLASS__ ,
241241 "No connection to database. Remove this module from config if you don't need database repopulation "
242242 );
243243 }
244+
244245 try {
245246 $ this ->driver ->cleanup ();
246- } catch (Exception $ e ) {
247- throw new ModuleException (__CLASS__ , $ e ->getMessage ());
247+ } catch (Exception $ exception ) {
248+ throw new ModuleException (__CLASS__ , $ exception ->getMessage ());
248249 }
249250 }
250251
@@ -260,10 +261,12 @@ protected function loadDump(): void
260261 if ($ this ->config ['dump_type ' ] === self ::DUMP_TYPE_JS ) {
261262 $ this ->driver ->load ($ this ->dumpFile );
262263 }
264+
263265 if ($ this ->config ['dump_type ' ] === self ::DUMP_TYPE_MONGODUMP ) {
264266 $ this ->driver ->setQuiet ($ this ->config ['quiet ' ]);
265267 $ this ->driver ->loadFromMongoDump ($ this ->dumpFile );
266268 }
269+
267270 if ($ this ->config ['dump_type ' ] === self ::DUMP_TYPE_MONGODUMP_TAR_GZ ) {
268271 $ this ->driver ->setQuiet ($ this ->config ['quiet ' ]);
269272 $ this ->driver ->loadFromTarGzMongoDump ($ this ->dumpFile );
@@ -284,8 +287,6 @@ protected function loadDump(): void
284287 * <?php
285288 * $I->useDatabase('db_1');
286289 * ```
287- *
288- * @param string $dbName
289290 */
290291 public function useDatabase (string $ dbName ): void
291292 {
@@ -300,10 +301,6 @@ public function useDatabase(string $dbName): void
300301 * $I->haveInCollection('users', ['name' => 'John', 'email' => 'john@coltrane.com']);
301302 * $user_id = $I->haveInCollection('users', ['email' => 'john@coltrane.com']);
302303 * ```
303- *
304- * @param string $collection
305- * @param array $data
306- * @return string
307304 */
308305 public function haveInCollection (string $ collection , array $ data ): string
309306 {
@@ -320,8 +317,6 @@ public function haveInCollection(string $collection, array $data): string
320317 * <?php
321318 * $I->seeInCollection('users', ['name' => 'miles']);
322319 * ```
323- *
324- * @param string $collection
325320 */
326321 public function seeInCollection (string $ collection , array $ criteria = []): void
327322 {
@@ -337,8 +332,6 @@ public function seeInCollection(string $collection, array $criteria = []): void
337332 * <?php
338333 * $I->dontSeeInCollection('users', ['name' => 'miles']);
339334 * ```
340- *
341- * @param string $collection
342335 */
343336 public function dontSeeInCollection (string $ collection , array $ criteria = []): void
344337 {
@@ -355,7 +348,6 @@ public function dontSeeInCollection(string $collection, array $criteria = []): v
355348 * $user = $I->grabFromCollection('users', ['name' => 'miles']);
356349 * ```
357350 *
358- * @param string $collection
359351 * @return \MongoDB\Model\BSONDocument|mixed
360352 */
361353 public function grabFromCollection (string $ collection , array $ criteria = [])
@@ -373,8 +365,6 @@ public function grabFromCollection(string $collection, array $criteria = [])
373365 * // or
374366 * $count = $I->grabCollectionCount('users', ['isAdmin' => true]);
375367 * ```
376- *
377- * @param string $collection
378368 */
379369 public function grabCollectionCount (string $ collection , array $ criteria = []): int
380370 {
@@ -408,6 +398,7 @@ public function seeElementIsArray(string $collection, array $criteria = [], stri
408398 'Error: you should test against a single element criteria when asserting that elementIsArray '
409399 );
410400 }
401+
411402 \PHPUnit \Framework \Assert::assertEquals (1 , $ res , 'Specified element is not a Mongo Object ' );
412403 }
413404
@@ -437,6 +428,7 @@ public function seeElementIsObject(string $collection, array $criteria = [], str
437428 'Error: you should test against a single element criteria when asserting that elementIsObject '
438429 );
439430 }
431+
440432 \PHPUnit \Framework \Assert::assertEquals (1 , $ res , 'Specified element is not a Mongo Object ' );
441433 }
442434
@@ -448,8 +440,6 @@ public function seeElementIsObject(string $collection, array $criteria = [], str
448440 * $I->seeNumElementsInCollection('users', 2);
449441 * $I->seeNumElementsInCollection('users', 1, ['name' => 'miles']);
450442 * ```
451- *
452- * @param string $collection
453443 */
454444 public function seeNumElementsInCollection (string $ collection , int $ expected , array $ criteria = []): void
455445 {
0 commit comments