Skip to content

Commit

Permalink
[DDC-581] Implemented support to SingleValuedPathExpression to InExpr…
Browse files Browse the repository at this point in the history
…ession.
  • Loading branch information
Guilherme Blanco committed Aug 12, 2010
1 parent c306433 commit 496a34a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2421,13 +2421,13 @@ public function ComparisonExpression()
}

/**
* InExpression ::= StateFieldPathExpression ["NOT"] "IN" "(" (InParameter {"," InParameter}* | Subselect) ")"
* InExpression ::= SingleValuedPathExpression ["NOT"] "IN" "(" (InParameter {"," InParameter}* | Subselect) ")"
*
* @return \Doctrine\ORM\Query\AST\InExpression
*/
public function InExpression()
{
$inExpression = new AST\InExpression($this->StateFieldPathExpression());
$inExpression = new AST\InExpression($this->SingleValuedPathExpression());

if ($this->_lexer->isNextToken(Lexer::T_NOT)) {
$this->match(Lexer::T_NOT);
Expand Down
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ public function testNotInExpressionSupportedInWherePart()
$this->assertValidDql('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN (1)');
}

public function testInExpressionWithSingleValuedAssociationPathExpression()
{
$this->assertValidDql("SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.avatar IN (?1, ?2)");
}

public function testInvalidInExpressionWithCollectionValuedAssociationPathExpression()
{
$this->assertInvalidDql("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.phonenumbers IN (?1, ?2)");
}

public function testInstanceOfExpressionSupportedInWherePart()
{
$this->assertValidDql('SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee');
Expand Down
58 changes: 58 additions & 0 deletions tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ protected function setUp()
$this->_em = $this->_getTestEntityManager();
}

/**
* Assert a valid SQL generation.
*
* @param string $dqlToBeTested
* @param string $sqlToBeConfirmed
* @param array $queryHints
* @param array $queryParams
*/
public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $queryHints = array(), array $queryParams = array())
{
try {
Expand All @@ -38,6 +46,39 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $qu
}
}

/**
* Asser an invalid SQL generation.
*
* @param string $dqlToBeTested
* @param string $expectedException
* @param array $queryHints
* @param array $queryParams
*/
public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = array(), array $queryParams = array())
{
$this->setExpectedException($expectedException);

$query = $this->_em->createQuery($dqlToBeTested);

foreach ($queryParams AS $name => $value) {
$query->setParameter($name, $value);
}

$query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
->useQueryCache(false);

foreach ($queryHints AS $name => $value) {
$query->setHint($name, $value);
}

$sql = $query->getSql();
$query->free();

// If we reached here, test failed
$this->fail($sql);
}


public function testSupportsSelectForAllFields()
{
$this->assertSqlGeneration(
Expand Down Expand Up @@ -374,6 +415,23 @@ public function testSupportsNotInExpressionInWherePart()
);
}

public function testInExpressionWithSingleValuedAssociationPathExpressionInWherePart()
{
$this->assertSqlGeneration(
'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.avatar IN (?1, ?2)',
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ WHERE f0_.avatar_id IN (?, ?)'
);
}

public function testInvalidInExpressionWithSingleValuedAssociationPathExpressionOnInverseSide()
{
// We do not support SingleValuedAssociationPathExpression on inverse side
$this->assertInvalidSqlGeneration(
"SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address IN (?1, ?2)",
"Doctrine\ORM\Query\QueryException"
);
}

public function testSupportsConcatFunctionForMysqlAndPostgresql()
{
$connMock = $this->_em->getConnection();
Expand Down

0 comments on commit 496a34a

Please sign in to comment.