Skip to content

Commit

Permalink
Try testing boolean comparison using ParameterType
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Sep 24, 2024
1 parent 7a82524 commit a06ad45
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/Functional/Query/QueryBuilderBoolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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);
$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')
->forUpdate();

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')
->forUpdate();

self::assertEquals([1], $qb2->fetchFirstColumn());
}
}

0 comments on commit a06ad45

Please sign in to comment.