[DDC-581] Implemented support to SingleValuedPathExpression to InExpression.
This commit is contained in:
parent
c3064336ab
commit
496a34a4d2
@ -2421,13 +2421,13 @@ class Parser
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
@ -135,6 +135,16 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase
|
||||
$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');
|
||||
|
@ -15,6 +15,14 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
$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 {
|
||||
@ -38,6 +46,39 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
@ -374,6 +415,23 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
);
|
||||
}
|
||||
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user