@@ -729,7 +729,7 @@ public function _loadDump(string $databaseKey = null, array $databaseConfig = nu
729
729
$ databaseKey = empty ($ databaseKey ) ? self ::DEFAULT_DATABASE : $ databaseKey ;
730
730
$ databaseConfig = empty ($ databaseConfig ) ? $ this ->config : $ databaseConfig ;
731
731
732
- if ($ databaseConfig ['populator ' ]) {
732
+ if (! empty ( $ databaseConfig ['populator ' ]) ) {
733
733
$ this ->loadDumpUsingPopulator ($ databaseKey , $ databaseConfig );
734
734
return ;
735
735
}
@@ -956,6 +956,77 @@ public function grabFromDatabase(string $table, string $column, array $criteria
956
956
return $ this ->proceedSeeInDatabase ($ table , $ column , $ criteria );
957
957
}
958
958
959
+ /**
960
+ * Fetches a whole entry from a database.
961
+ * Make the test fail if the entry is not found.
962
+ * Provide table name, desired column and criteria.
963
+ *
964
+ * ``` php
965
+ * <?php
966
+ * $mail = $I->grabEntryFromDatabase('users', array('name' => 'Davert'));
967
+ * ```
968
+ * Comparison expressions can be used as well:
969
+ *
970
+ * ```php
971
+ * <?php
972
+ * $post = $I->grabEntryFromDatabase('posts', ['num_comments >=' => 100]);
973
+ * $user = $I->grabEntryFromDatabase('users', ['email like' => 'miles%']);
974
+ * ```
975
+ *
976
+ * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`.
977
+ *
978
+ * @return array Returns a single entry value
979
+ * @throws PDOException|Exception
980
+ */
981
+ public function grabEntryFromDatabase (string $ table , array $ criteria = []): array
982
+ {
983
+ $ query = $ this ->_getDriver ()->select ('* ' , $ table , $ criteria );
984
+ $ parameters = array_values ($ criteria );
985
+ $ this ->debugSection ('Query ' , $ query );
986
+ $ this ->debugSection ('Parameters ' , $ parameters );
987
+ $ sth = $ this ->_getDriver ()->executeQuery ($ query , $ parameters );
988
+
989
+ $ result = $ sth ->fetch (PDO ::FETCH_ASSOC , 0 );
990
+
991
+ if ($ result === false ) {
992
+ throw new \AssertionError ("No matching row found " );
993
+ }
994
+
995
+ return $ result ;
996
+ }
997
+
998
+ /**
999
+ * Fetches a set of entries from a database.
1000
+ * Provide table name and criteria.
1001
+ *
1002
+ * ``` php
1003
+ * <?php
1004
+ * $mail = $I->grabEntriesFromDatabase('users', array('name' => 'Davert'));
1005
+ * ```
1006
+ * Comparison expressions can be used as well:
1007
+ *
1008
+ * ```php
1009
+ * <?php
1010
+ * $post = $I->grabEntriesFromDatabase('posts', ['num_comments >=' => 100]);
1011
+ * $user = $I->grabEntriesFromDatabase('users', ['email like' => 'miles%']);
1012
+ * ```
1013
+ *
1014
+ * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`.
1015
+ *
1016
+ * @return array<array<string, mixed>> Returns an array of all matched rows
1017
+ * @throws PDOException|Exception
1018
+ */
1019
+ public function grabEntriesFromDatabase (string $ table , array $ criteria = []): array
1020
+ {
1021
+ $ query = $ this ->_getDriver ()->select ('* ' , $ table , $ criteria );
1022
+ $ parameters = array_values ($ criteria );
1023
+ $ this ->debugSection ('Query ' , $ query );
1024
+ $ this ->debugSection ('Parameters ' , $ parameters );
1025
+ $ sth = $ this ->_getDriver ()->executeQuery ($ query , $ parameters );
1026
+
1027
+ return $ sth ->fetchAll (PDO ::FETCH_ASSOC );
1028
+ }
1029
+
959
1030
/**
960
1031
* Returns the number of rows in a database
961
1032
*
0 commit comments