Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Need Help] Testing boolean comparison using ParameterType #6526

Open
wants to merge 4 commits into
base: 4.1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions tests/Functional/Query/QueryBuilderBoolTest.php
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' => 1]);
$this->connection->insert('for_update', ['id' => 2, 'b1' => 0]);
}

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(1, 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(1, 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(0, 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(0, Types::BOOLEAN)))
->executeStatement();

$qb2 = $this->connection->createQueryBuilder();
$qb2->select('id')
->from('for_update');

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