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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1048Test.php
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,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), | ||
$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."); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 booleanfalse
. these are all different