From 0fe610407d3e454628fad3b7697c76dabdd977d7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 24 Sep 2024 09:22:37 +0200 Subject: [PATCH 1/2] Try testing boolean comparison using ParameterType Signed-off-by: Joas Schilling --- .../Functional/Query/QueryBuilderBoolTest.php | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 tests/Functional/Query/QueryBuilderBoolTest.php diff --git a/tests/Functional/Query/QueryBuilderBoolTest.php b/tests/Functional/Query/QueryBuilderBoolTest.php new file mode 100644 index 00000000000..74ea5499709 --- /dev/null +++ b/tests/Functional/Query/QueryBuilderBoolTest.php @@ -0,0 +1,116 @@ +addColumn('id', Types::INTEGER); + $table->addColumn('b1', Types::BOOLEAN, ['notnull' => false]); + $table->setPrimaryKey(['id']); + + $this->dropAndCreateTable($table); + + $this->connection->insert('for_update', ['id' => 1, 'b1' => true]); + $this->connection->insert('for_update', ['id' => 2, 'b1' => false]); + } + + protected function tearDown(): void + { + if (! $this->connection->isTransactionActive()) { + return; + } + + $this->connection->rollBack(); + } + + public function testDeleteBooleanTrue(): void + { + $platform = $this->connection->getDatabasePlatform(); + + if ($platform instanceof SQLitePlatform) { + self::markTestSkipped('Skipping on SQLite'); + } + + $qb1 = $this->connection->createQueryBuilder(); + $qb1->delete('for_update') + ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(true, ParameterType::BOOLEAN))) + ->executeStatement(); + + $qb2 = $this->connection->createQueryBuilder(); + $qb2->select('id') + ->from('for_update'); + + self::assertEquals([2], $qb2->fetchFirstColumn()); + } + + public function testDeleteBooleanTrueWithWrongType(): void + { + $platform = $this->connection->getDatabasePlatform(); + + if ($platform instanceof SQLitePlatform) { + self::markTestSkipped('Skipping on SQLite'); + } + + $qb1 = $this->connection->createQueryBuilder(); + $qb1->delete('for_update') + ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(true, Types::BOOLEAN))) + ->executeStatement(); + + $qb2 = $this->connection->createQueryBuilder(); + $qb2->select('id') + ->from('for_update'); + + self::assertEquals([2], $qb2->fetchFirstColumn()); + } + + public function testDeleteBooleanFalse(): void + { + $platform = $this->connection->getDatabasePlatform(); + + if ($platform instanceof SQLitePlatform) { + self::markTestSkipped('Skipping on SQLite'); + } + + $qb1 = $this->connection->createQueryBuilder(); + $qb1->delete('for_update') + ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(false, ParameterType::BOOLEAN))) + ->executeStatement(); + + $qb2 = $this->connection->createQueryBuilder(); + $qb2->select('id') + ->from('for_update'); + + self::assertEquals([1], $qb2->fetchFirstColumn()); + } + + public function testDeleteBooleanFalseWithWrongType(): void + { + $platform = $this->connection->getDatabasePlatform(); + + if ($platform instanceof SQLitePlatform) { + self::markTestSkipped('Skipping on SQLite'); + } + + $qb1 = $this->connection->createQueryBuilder(); + $qb1->delete('for_update') + ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(false, Types::BOOLEAN))) + ->executeStatement(); + + $qb2 = $this->connection->createQueryBuilder(); + $qb2->select('id') + ->from('for_update'); + + self::assertEquals([1], $qb2->fetchFirstColumn()); + } +} From 0e54a06048426f257b15f6ae063aee4812e30a43 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 24 Sep 2024 11:47:09 +0200 Subject: [PATCH 2/2] fixup! Try testing boolean comparison using ParameterType --- tests/Functional/Query/QueryBuilderBoolTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Functional/Query/QueryBuilderBoolTest.php b/tests/Functional/Query/QueryBuilderBoolTest.php index 74ea5499709..fc0de7e6099 100644 --- a/tests/Functional/Query/QueryBuilderBoolTest.php +++ b/tests/Functional/Query/QueryBuilderBoolTest.php @@ -21,8 +21,8 @@ protected function setUp(): void $this->dropAndCreateTable($table); - $this->connection->insert('for_update', ['id' => 1, 'b1' => true]); - $this->connection->insert('for_update', ['id' => 2, 'b1' => false]); + $this->connection->insert('for_update', ['id' => 1, 'b1' => 1]); + $this->connection->insert('for_update', ['id' => 2, 'b1' => 0]); } protected function tearDown(): void @@ -44,7 +44,7 @@ public function testDeleteBooleanTrue(): void $qb1 = $this->connection->createQueryBuilder(); $qb1->delete('for_update') - ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(true, ParameterType::BOOLEAN))) + ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(1, ParameterType::BOOLEAN))) ->executeStatement(); $qb2 = $this->connection->createQueryBuilder(); @@ -64,7 +64,7 @@ public function testDeleteBooleanTrueWithWrongType(): void $qb1 = $this->connection->createQueryBuilder(); $qb1->delete('for_update') - ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(true, Types::BOOLEAN))) + ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(1, Types::BOOLEAN))) ->executeStatement(); $qb2 = $this->connection->createQueryBuilder(); @@ -84,7 +84,7 @@ public function testDeleteBooleanFalse(): void $qb1 = $this->connection->createQueryBuilder(); $qb1->delete('for_update') - ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(false, ParameterType::BOOLEAN))) + ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(0, ParameterType::BOOLEAN))) ->executeStatement(); $qb2 = $this->connection->createQueryBuilder(); @@ -104,7 +104,7 @@ public function testDeleteBooleanFalseWithWrongType(): void $qb1 = $this->connection->createQueryBuilder(); $qb1->delete('for_update') - ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(false, Types::BOOLEAN))) + ->where($qb1->expr()->eq('b1', $qb1->createNamedParameter(0, Types::BOOLEAN))) ->executeStatement(); $qb2 = $this->connection->createQueryBuilder();