1
0
mirror of synced 2025-01-19 15:01:40 +03:00

faild test with multiple HINT_CUSTOM_TREE_WALKERS

failed test when we have more than 1 walker HINT_CUSTOM_TREE_WALKERS ,
because walkSelectStatement in TreeWalkerChain saves the last hint _queryComponents result.
This commit is contained in:
shustrik 2014-02-06 01:27:17 +03:00
parent 626efdafd4
commit 7107a85041

View File

@ -42,7 +42,7 @@ class CustomTreeWalkersTest extends \Doctrine\Tests\OrmTestCase
{
$query = $this->_em->createQuery($dqlToBeTested);
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $treeWalkers)
->useQueryCache(false);
->useQueryCache(false);
if ($outputWalker) {
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, $outputWalker);
@ -96,6 +96,15 @@ class CustomTreeWalkersTest extends \Doctrine\Tests\OrmTestCase
__NAMESPACE__ . '\\AddUnknownQueryComponentWalker'
);
}
public function testSupportsSeveralHintsQueriesWithoutWhere()
{
$this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\CMS\CmsUser u',
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c1_.id AS id4, c1_.country AS country5, c1_.zip AS zip6, c1_.city AS city7, c0_.email_id AS email_id8, c1_.user_id AS user_id9 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id WHERE c0_.id = 1",
array('Doctrine\Tests\ORM\Functional\CustomTreeWalkerJoin', 'Doctrine\Tests\ORM\Functional\CustomTreeWalker')
);
}
}
class AddUnknownQueryComponentWalker extends Query\SqlWalker
@ -183,3 +192,43 @@ class CustomTreeWalker extends Query\TreeWalkerAdapter
}
}
}
class CustomTreeWalkerJoin extends Query\TreeWalkerAdapter
{
public function walkSelectStatement(Query\AST\SelectStatement $selectStatement)
{
foreach ($selectStatement->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) {
if ($identificationVariableDeclaration->rangeVariableDeclaration->abstractSchemaName == 'Doctrine\Tests\Models\CMS\CmsUser') {
$identificationVariableDeclaration->joins[] = new Query\AST\Join(
Query\AST\Join::JOIN_TYPE_LEFT,
new Query\AST\JoinAssociationDeclaration(
new Query\AST\JoinAssociationPathExpression(
$identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable,
'address'
),
$identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable . 'a',
null
)
);
$selectStatement->selectClause->selectExpressions[] =
new Query\AST\SelectExpression(
$identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable . 'a',
null,
false
);
$meta1 = $this->_getQuery()->getEntityManager()->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$meta = $this->_getQuery()->getEntityManager()->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$this->setQueryComponent($identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable . 'a',
array(
'metadata' => $meta,
'parent' => $identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable,
'relation' => $meta1->getAssociationMapping('address'),
'map' => null,
'nestingLevel' => 0,
'token' => null
)
);
}
}
}
}