From 2c48f1a6b4683cee5e2d3b2bf79b298af012360f Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 19 Feb 2022 22:17:23 +0200 Subject: [PATCH 1/2] Use lowercase table name in tests to fix Closes #273 --- src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php | 1 + tests/rules/SyntaxErrorInQueryMethodRuleMysqliReflectorTest.php | 2 +- tests/rules/SyntaxErrorInQueryMethodRulePdoReflectorTest.php | 2 +- tests/rules/data/syntax-error-in-query-method.php | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php b/src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php index 07d17a0be..d17bb8351 100644 --- a/src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php +++ b/src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php @@ -130,6 +130,7 @@ private function inferType(MethodReflection $methodReflection, MethodCall $metho if (QueryReflector::FETCH_TYPE_KEY_VALUE === $fetchType) { return $rowType; } + return new ArrayType(new IntegerType(), $rowType); } diff --git a/tests/rules/SyntaxErrorInQueryMethodRuleMysqliReflectorTest.php b/tests/rules/SyntaxErrorInQueryMethodRuleMysqliReflectorTest.php index 075b05622..62a35d46d 100644 --- a/tests/rules/SyntaxErrorInQueryMethodRuleMysqliReflectorTest.php +++ b/tests/rules/SyntaxErrorInQueryMethodRuleMysqliReflectorTest.php @@ -50,7 +50,7 @@ public function testSyntaxErrorInQueryRule(): void 36, ], [ - "Query error: Table 'phpstan_dba.unknownTable' doesn't exist (1146).", + "Query error: Table 'phpstan_dba.unknown_table' doesn't exist (1146).", 41, ], [ diff --git a/tests/rules/SyntaxErrorInQueryMethodRulePdoReflectorTest.php b/tests/rules/SyntaxErrorInQueryMethodRulePdoReflectorTest.php index 475284b14..ef8c97f4a 100644 --- a/tests/rules/SyntaxErrorInQueryMethodRulePdoReflectorTest.php +++ b/tests/rules/SyntaxErrorInQueryMethodRulePdoReflectorTest.php @@ -50,7 +50,7 @@ public function testSyntaxErrorInQueryRule(): void 36, ], [ - "Query error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'phpstan_dba.unknownTable' doesn't exist (42S02).", + "Query error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'phpstan_dba.unknown_table' doesn't exist (42S02).", 41, ], [ diff --git a/tests/rules/data/syntax-error-in-query-method.php b/tests/rules/data/syntax-error-in-query-method.php index 0ef5fb235..e85dc8354 100644 --- a/tests/rules/data/syntax-error-in-query-method.php +++ b/tests/rules/data/syntax-error-in-query-method.php @@ -38,7 +38,7 @@ public function unknownGroupByColumn(PDO $pdo) public function unknownTable(PDO $pdo) { - $pdo->query('SELECT * FROM unknownTable', PDO::FETCH_ASSOC); + $pdo->query('SELECT * FROM unknown_table', PDO::FETCH_ASSOC); } public function incompleteQuery(PDO $pdo, string $tableName) From 2bf2176640b5c4d5bb2bb97d6e6ad2e15c2b1289 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 20 Feb 2022 10:25:42 +0100 Subject: [PATCH 2/2] re-record --- tests/rules/config/.phpstan-dba-mysqli.cache | 9 ++++++++- tests/rules/config/.phpstan-dba-pdo.cache | 9 ++++++++- tests/rules/config/.phpunit-phpstan-dba-mysqli.cache | 8 ++++++++ tests/rules/config/.phpunit-phpstan-dba-pdo.cache | 8 ++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/rules/config/.phpstan-dba-mysqli.cache b/tests/rules/config/.phpstan-dba-mysqli.cache index e8565ec04..9c571785b 100644 --- a/tests/rules/config/.phpstan-dba-mysqli.cache +++ b/tests/rules/config/.phpstan-dba-mysqli.cache @@ -30,6 +30,13 @@ 5 => NULL, ), ), + 'SELECT * FROM unknown_table' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), 'SELECT adaid FROM ada WHERE email=\'1970-01-01\'' => array ( 'result' => @@ -972,7 +979,7 @@ array ( 'result' => array ( - 3 => NULL, + 5 => NULL, ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE gesperrt=1' => diff --git a/tests/rules/config/.phpstan-dba-pdo.cache b/tests/rules/config/.phpstan-dba-pdo.cache index 4fd72dad7..072b54040 100644 --- a/tests/rules/config/.phpstan-dba-pdo.cache +++ b/tests/rules/config/.phpstan-dba-pdo.cache @@ -30,6 +30,13 @@ 5 => NULL, ), ), + 'SELECT * FROM unknown_table' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), 'SELECT adaid FROM ada WHERE email=\'1970-01-01\'' => array ( 'result' => @@ -972,7 +979,7 @@ array ( 'result' => array ( - 5 => NULL, + 3 => NULL, ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE gesperrt=1' => diff --git a/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache b/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache index 94d1c8d5f..39b9d5b00 100644 --- a/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache +++ b/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache @@ -272,6 +272,14 @@ 'code' => 1146, )), ), + 'SELECT * FROM unknown_table' => + array ( + 'error' => + staabm\PHPStanDba\Error::__set_state(array( + 'message' => 'Table \'phpstan_dba.unknown_table\' doesn\'t exist', + 'code' => 1146, + )), + ), 'SELECT adaid FROM ada WHERE email = \'1970-01-01\'' => array ( 'error' => NULL, diff --git a/tests/rules/config/.phpunit-phpstan-dba-pdo.cache b/tests/rules/config/.phpunit-phpstan-dba-pdo.cache index 01a19d7a8..b2cd9735a 100644 --- a/tests/rules/config/.phpunit-phpstan-dba-pdo.cache +++ b/tests/rules/config/.phpunit-phpstan-dba-pdo.cache @@ -272,6 +272,14 @@ 'code' => '42S02', )), ), + 'SELECT * FROM unknown_table' => + array ( + 'error' => + staabm\PHPStanDba\Error::__set_state(array( + 'message' => 'SQLSTATE[42S02]: Base table or view not found: 1146 Table \'phpstan_dba.unknown_table\' doesn\'t exist', + 'code' => '42S02', + )), + ), 'SELECT adaid FROM ada WHERE email = \'1970-01-01\'' => array ( 'error' => NULL,