@@ -16,7 +16,9 @@ trait DatabaseTableTestTrait
1616 * @param array $expectedRow Row expected to find
1717 * @param string $table Table to look into
1818 * @param int $id The primary key
19- * @param string|array|null $selectClause Fields array or string after SELECT and before FROM like 'id, name'
19+ * @param string|array|null $selectClause Fields array or string after "SELECT" and before "FROM" like 'id, `name`'
20+ * WARNING: the column names passed as array or string must be escaped with ` if they match a reserved word
21+ * Example: ['`column_name`', '`column_name_2`'] or '`column_name`, `column_name_2`'
2022 * @param string $message Optional message
2123 *
2224 * @return void
@@ -30,7 +32,11 @@ protected function assertTableRow(
3032 ): void {
3133 $ this ->assertSame (
3234 $ expectedRow ,
33- $ this ->getTableRowById ($ table , $ id , $ selectClause ?: array_keys ($ expectedRow )),
35+ $ this ->getTableRowById (
36+ $ table ,
37+ $ id ,
38+ $ selectClause ?: array_map (fn ($ key ) => "` $ key` " , array_keys ($ expectedRow ))
39+ ),
3440 $ message
3541 );
3642 }
@@ -40,7 +46,9 @@ protected function assertTableRow(
4046 *
4147 * @param string $table Table name
4248 * @param int $id The primary key value
43- * @param string|array $selectClause Fields string after SELECT and before FROM like 'id, name'
49+ * @param string|array $selectClause Fields array or string after "SELECT" and before "FROM" like 'id, `name`'
50+ * WARNING: the column names passed as array or string must be escaped with ` if they match a reserved word
51+ * Example: ['`column_name`', '`column_name_2`'] or '`column_name`, `column_name_2`'
4452 *
4553 * @throws DomainException
4654 *
@@ -71,7 +79,9 @@ protected function getTableRowById(string $table, int $id, string|array $selectC
7179 * @param array $expectedRow Row expected to find
7280 * @param string $table Table to look into
7381 * @param int $id The primary key
74- * @param string|array|null $selectClause Fields array or string after SELECT and before FROM like 'id, name'
82+ * @param string|array|null $selectClause Fields array or string after "SELECT" and before "FROM" like 'id, `name`'
83+ * WARNING: the column names passed as array or string must be escaped with ` if they match a reserved word
84+ * Example: ['`column_name`', '`column_name_2`'] or '`column_name`, `column_name_2`'
7585 * @param string $message Optional message
7686 *
7787 * @return void
@@ -85,7 +95,11 @@ protected function assertTableRowEquals(
8595 ): void {
8696 $ this ->assertEquals (
8797 $ expectedRow ,
88- $ this ->getTableRowById ($ table , $ id , $ selectClause ?: array_keys ($ expectedRow )),
98+ $ this ->getTableRowById (
99+ $ table ,
100+ $ id ,
101+ $ selectClause ?: array_map (fn ($ key ) => "` $ key` " , array_keys ($ expectedRow ))
102+ ),
89103 $ message
90104 );
91105 }
0 commit comments