-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try testing boolean comparison using ParameterType
Signed-off-by: Joas Schilling <[email protected]>
- Loading branch information
1 parent
19a2b7d
commit 0fe6104
Showing
1 changed file
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Query; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Platforms\SQLitePlatform; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
use Doctrine\DBAL\Types\Types; | ||
|
||
final class QueryBuilderBoolTest extends FunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$table = new Table('for_update'); | ||
$table->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()); | ||
} | ||
} |