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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test failing...] DDC-1048 reported by cordoval #647

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 70 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1048Test.php
@@ -0,0 +1,70 @@
<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Tests\Models\Generic\BooleanModel;

require_once __DIR__ . '/../../../TestInit.php';

/**
* Class DDC1048Test
* @author Luis Cordova <cordoval@gmail.com>
* @package Doctrine\Tests\ORM\Functional\Ticket
*/
class DDC1048Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('generic');
parent::setUp();
}

/**
* @group DDC-1048
*/
public function testBugOnDQLForFalseValue()
{
$true = new BooleanModel();
$true->booleanField = true;

$false = new BooleanModel();
$false->booleanField = false;

$this->_em->persist($true);
$this->_em->persist($false);
$this->_em->flush();
$this->_em->clear();

$qb = $this->_em->createQueryBuilder()
->select('x')
->from('Doctrine\Tests\Models\Generic\BooleanModel', 'x')
;

$false = $qb
->where($qb->expr()->andX(
$qb->expr()->eq('x.booleanField', false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cordoval This is using string concatenation. It is expected to work this way. You should use parameters instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is, DQL supports booleans without parameters so one would expect this to work. This behavior is at least strange and unexpected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Majkl578 But it supports it by using a string, not a boolean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but that doesn't mean DQL builder can't use some extra logic for converting input to string representation (which would make sense here). Also, looking at Comparison::__construct, it says @param mixed $rightExpr, not @param string $rightExpr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, because it could be another Expr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query builder is a string builder and has nothing to do with casting constant values to their corresponding DQL representations. here, binding a string would mean using '"false"' and binding a boolean would require to use 'false', and not just the boolean false. these are all different

$qb->expr()->eq('x.booleanField', false)
))
->orderBy('x.booleanField', 'DESC')
->getQuery()
->execute()
;

$true = $qb
->where($qb->expr()->andX(
$qb->expr()->eq('x.booleanField', true),
$qb->expr()->eq('x.booleanField', true)
))
->orderBy('x.booleanField', 'DESC')
->getQuery()
->execute()
;

$this->assertInstanceOf('Doctrine\Tests\Models\Generic\BooleanModel', $true, "True model not found");
$this->assertTrue($true->booleanField, "True Boolean Model should be true.");

$this->assertInstanceOf('Doctrine\Tests\Models\Generic\BooleanModel', $false, "False model not found");
$this->assertFalse($false->booleanField, "False Boolean Model should be false.");
}
}