From 42ee7bc20eb47f8afeaea47c3f2f13b16b0bd195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 9 Sep 2024 23:37:10 +0200 Subject: [PATCH] Reproduce MySQL warnings with and without emulated prepares MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Cobucci --- .../Platform/MySQLWarningsWithBinaryTest.php | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/Functional/Platform/MySQLWarningsWithBinaryTest.php diff --git a/tests/Functional/Platform/MySQLWarningsWithBinaryTest.php b/tests/Functional/Platform/MySQLWarningsWithBinaryTest.php new file mode 100644 index 00000000000..54b9f9144f0 --- /dev/null +++ b/tests/Functional/Platform/MySQLWarningsWithBinaryTest.php @@ -0,0 +1,85 @@ +addColumn('id', 'binary', ['notnull' => false, 'length' => 16]); + $table->setPrimaryKey(['id']); + + $this->dropAndCreateTable($table); + } + + /** @psalm-param WrapperParameterTypeArray $types */ + #[Test] + #[DataProvider('useCases')] + public function binaryValuesDoNotEmitWarningsWithEmulation(string $query, array $types): void + { + $this->connection->executeStatement($query, [hex2bin('0191d886e6dc73e7af1fee7f99ec6235')], $types); + + self::assertSame([], $this->connection->executeQuery('SHOW WARNINGS')->fetchAllAssociative()); + } + + /** @psalm-param WrapperParameterTypeArray $types */ + #[Test] + #[DataProvider('useCases')] + public function binaryValuesDoNotEmitWarningsWithoutEmulation(string $query, array $types): void + { + $pdo = $this->connection->getNativeConnection(); + assert($pdo instanceof PDO); + + $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $this->connection->executeStatement($query, [hex2bin('0191d886e6dc73e7af1fee7f99ec6235')], $types); + $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + + self::assertSame([], $this->connection->executeQuery('SHOW WARNINGS')->fetchAllAssociative()); + } + + /** @return iterable */ + public static function useCases(): iterable + { + yield '_binary and ParameterType::BINARY' => [ + 'INSERT INTO `binary_warnings_test` (`id`) VALUES (_binary ?)', + [ParameterType::BINARY], + ]; + + yield '_binary and ParameterType::STRING' => [ + 'INSERT INTO `binary_warnings_test` (`id`) VALUES (_binary ?)', + [], + ]; + + yield 'string and ParameterType::BINARY' => [ + 'INSERT INTO `binary_warnings_test` (`id`) VALUES (?)', + [ParameterType::BINARY], + ]; + + yield 'string and ParameterType::STRING' => [ + 'INSERT INTO `binary_warnings_test` (`id`) VALUES (?)', + [], + ]; + } +}