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 (?)', + [], + ]; + } +}