From efebf26cc59f498cccba1068cda61b9134fcf88c Mon Sep 17 00:00:00 2001 From: Aigars Gedroics Date: Thu, 5 Apr 2012 11:30:00 +0300 Subject: [PATCH 1/8] DDC-1757 test and patched query builder --- lib/Doctrine/ORM/QueryBuilder.php | 32 ++++-- .../ORM/Functional/Ticket/DDC1757Test.php | 102 ++++++++++++++++++ 2 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 13d041e2b..b78ed59d0 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -96,6 +96,12 @@ class QueryBuilder */ private $_maxResults = null; + /** + * Keeps root entity alias names for join entities + * @var array + */ + private $joinRootAliases = array(); + /** * Initializes a new QueryBuilder that uses the given EntityManager. * @@ -234,10 +240,22 @@ class QueryBuilder * @deprecated Please use $qb->getRootAliases() instead. * @return string $rootAlias */ - public function getRootAlias() + public function getRootAlias($rootAlias = null, $alias = null) { - $aliases = $this->getRootAliases(); - return $aliases[0]; + if ( ! is_null($rootAlias) && in_array($rootAlias, $this->getRootAliases())) { + // Do nothing + } elseif ( ! is_null($rootAlias) && isset($this->joinRootAliases[$rootAlias])) { + $rootAlias = $this->joinRootAliases[$rootAlias]; + } else { + $aliases = $this->getRootAliases(); + $rootAlias = $aliases[0]; + } + + if ( ! is_null($alias)) { + $this->joinRootAliases[$alias] = $rootAlias; + } + + return $rootAlias; } /** @@ -669,9 +687,7 @@ class QueryBuilder { $rootAlias = substr($join, 0, strpos($join, '.')); - if ( ! in_array($rootAlias, $this->getRootAliases())) { - $rootAlias = $this->getRootAlias(); - } + $rootAlias = $this->getRootAlias($rootAlias, $alias); $join = new Expr\Join( Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy @@ -705,9 +721,7 @@ class QueryBuilder { $rootAlias = substr($join, 0, strpos($join, '.')); - if ( ! in_array($rootAlias, $this->getRootAliases())) { - $rootAlias = $this->getRootAlias(); - } + $rootAlias = $this->getRootAlias($rootAlias, $alias); $join = new Expr\Join( Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php new file mode 100644 index 000000000..703142003 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php @@ -0,0 +1,102 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757A'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757B'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757C'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757D'), + )); + } catch(\Exception $ignored) {} + } + + public function testFailingCase() + { + $qb = $this->_em->createQueryBuilder(); + /* @var $qb \Doctrine\ORM\QueryBuilder */ + + $qb->select('_a') + ->from(__NAMESPACE__ . '\DDC1757A', '_a') + ->from(__NAMESPACE__ . '\DDC1757B', '_b') + ->join('_b.c', '_c') + ->join('_c.d', '_d'); + + $q = $qb->getQuery(); + $dql = $q->getDQL(); + $q->getResult(); + } +} + +/** + * @Entity + */ +class DDC1757A +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + private $id; +} + +/** + * @Entity + */ +class DDC1757B +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @OneToOne(targetEntity="DDC1757C") + */ + private $c; +} + +/** + * @Entity + */ +class DDC1757C +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + public $id; + + /** + * @OneToOne(targetEntity="DDC1757D") + */ + private $d; +} + +/** + * @Entity + */ +class DDC1757D +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + public $id; +} From 49016bc156ce89bc4df178a7abedb9b767322c9a Mon Sep 17 00:00:00 2001 From: gedrox Date: Thu, 5 Apr 2012 13:56:08 +0300 Subject: [PATCH 2/8] Parameter PHP documentation for the QueryBuilder::getRootAlias() method --- lib/Doctrine/ORM/QueryBuilder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index b78ed59d0..6d0df50d7 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -238,6 +238,8 @@ class QueryBuilder * * * @deprecated Please use $qb->getRootAliases() instead. + * @param string $rootAlias + * @param string $alias * @return string $rootAlias */ public function getRootAlias($rootAlias = null, $alias = null) From aa381951cdb49d98db595d8271265cb9eae15c7a Mon Sep 17 00:00:00 2001 From: Aigars Gedroics Date: Tue, 10 Apr 2012 11:47:05 +0300 Subject: [PATCH 3/8] [DDC-1757] Fix moved to private method, test improved. --- lib/Doctrine/ORM/QueryBuilder.php | 57 +++++++++++-------- .../ORM/Functional/Ticket/DDC1757Test.php | 24 ++++++-- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 6d0df50d7..3dfc2754b 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -97,8 +97,7 @@ class QueryBuilder private $_maxResults = null; /** - * Keeps root entity alias names for join entities - * @var array + * @var array Keeps root entity alias names for join entities. */ private $joinRootAliases = array(); @@ -225,6 +224,32 @@ class QueryBuilder ->setMaxResults($this->_maxResults); } + /** + * Finds the root entity alias of the joined entity. + * + * @param string $alias The alias of the new join entity + * @param string $parentAlias The parent entity alias of the join relationship + * @return string + */ + private function findRootAlias($alias, $parentAlias) + { + $rootAlias = null; + + if (in_array($parentAlias, $this->getRootAliases())) { + $rootAlias = $parentAlias; + } elseif (isset($this->joinRootAliases[$parentAlias])) { + $rootAlias = $this->joinRootAliases[$parentAlias]; + } else { + // Should never happen with correct joining order. Might be + // thoughtful to throw exception instead. + $rootAlias = $this->getRootAlias(); + } + + $this->joinRootAliases[$alias] = $rootAlias; + + return $rootAlias; + } + /** * Gets the FIRST root alias of the query. This is the first entity alias involved * in the construction of the query. @@ -238,26 +263,12 @@ class QueryBuilder * * * @deprecated Please use $qb->getRootAliases() instead. - * @param string $rootAlias - * @param string $alias * @return string $rootAlias */ - public function getRootAlias($rootAlias = null, $alias = null) + public function getRootAlias() { - if ( ! is_null($rootAlias) && in_array($rootAlias, $this->getRootAliases())) { - // Do nothing - } elseif ( ! is_null($rootAlias) && isset($this->joinRootAliases[$rootAlias])) { - $rootAlias = $this->joinRootAliases[$rootAlias]; - } else { - $aliases = $this->getRootAliases(); - $rootAlias = $aliases[0]; - } - - if ( ! is_null($alias)) { - $this->joinRootAliases[$alias] = $rootAlias; - } - - return $rootAlias; + $aliases = $this->getRootAliases(); + return $aliases[0]; } /** @@ -687,9 +698,9 @@ class QueryBuilder */ public function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) { - $rootAlias = substr($join, 0, strpos($join, '.')); + $parentAlias = substr($join, 0, strpos($join, '.')); - $rootAlias = $this->getRootAlias($rootAlias, $alias); + $rootAlias = $this->findRootAlias($alias, $parentAlias); $join = new Expr\Join( Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy @@ -721,9 +732,9 @@ class QueryBuilder */ public function leftJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) { - $rootAlias = substr($join, 0, strpos($join, '.')); + $parentAlias = substr($join, 0, strpos($join, '.')); - $rootAlias = $this->getRootAlias($rootAlias, $alias); + $rootAlias = $this->findRootAlias($alias, $parentAlias); $join = new Expr\Join( Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php index 703142003..49a573390 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php @@ -11,7 +11,7 @@ class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - + try { $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757A'), @@ -26,16 +26,28 @@ class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase { $qb = $this->_em->createQueryBuilder(); /* @var $qb \Doctrine\ORM\QueryBuilder */ - + $qb->select('_a') ->from(__NAMESPACE__ . '\DDC1757A', '_a') ->from(__NAMESPACE__ . '\DDC1757B', '_b') ->join('_b.c', '_c') ->join('_c.d', '_d'); - - $q = $qb->getQuery(); - $dql = $q->getDQL(); - $q->getResult(); + + $q = $qb->getQuery(); + $dql = $q->getDQL(); + + try { + $data = $q->getResult(); + + self::assertEmpty($data); + } catch (\Doctrine\ORM\Query\QueryException $queryException) { + // Show difference between expected and actual queries on error + self::assertEquals("SELECT _a FROM " . __NAMESPACE__ . "\DDC1757A _a, " . __NAMESPACE__ . "\DDC1757B _b INNER JOIN _b.c _c INNER JOIN _c.d _d", + $dql, + "Wrong DQL query: " . $queryException->getMessage()); + + throw new \RuntimeException("Unexpected issue. DQL is correct but the query is failing."); + } } } From 59e598acc5681d6793e7732b04dfde93a19961d2 Mon Sep 17 00:00:00 2001 From: Aigars Gedroics Date: Tue, 17 Apr 2012 10:57:31 +0300 Subject: [PATCH 4/8] [DDC-1757] test checks DQL only now, doesn't create schema anymore --- .../ORM/Functional/Ticket/DDC1757Test.php | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php index 49a573390..77f32907e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php @@ -8,20 +8,6 @@ require_once __DIR__ . '/../../../TestInit.php'; class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase { - protected function setUp() - { - parent::setUp(); - - try { - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757A'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757B'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757C'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757D'), - )); - } catch(\Exception $ignored) {} - } - public function testFailingCase() { $qb = $this->_em->createQueryBuilder(); @@ -36,18 +22,10 @@ class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase $q = $qb->getQuery(); $dql = $q->getDQL(); - try { - $data = $q->getResult(); - - self::assertEmpty($data); - } catch (\Doctrine\ORM\Query\QueryException $queryException) { - // Show difference between expected and actual queries on error - self::assertEquals("SELECT _a FROM " . __NAMESPACE__ . "\DDC1757A _a, " . __NAMESPACE__ . "\DDC1757B _b INNER JOIN _b.c _c INNER JOIN _c.d _d", - $dql, - "Wrong DQL query: " . $queryException->getMessage()); - - throw new \RuntimeException("Unexpected issue. DQL is correct but the query is failing."); - } + // Show difference between expected and actual queries on error + self::assertEquals("SELECT _a FROM " . __NAMESPACE__ . "\DDC1757A _a, " . __NAMESPACE__ . "\DDC1757B _b INNER JOIN _b.c _c INNER JOIN _c.d _d", + $dql, + "Wrong DQL query"); } } From a1ab3e8cf40746e326ec4f10e896f066f44c4178 Mon Sep 17 00:00:00 2001 From: Aigars Gedroics Date: Thu, 5 Apr 2012 11:30:00 +0300 Subject: [PATCH 5/8] DDC-1757 test and patched query builder --- lib/Doctrine/ORM/QueryBuilder.php | 32 ++++-- .../ORM/Functional/Ticket/DDC1757Test.php | 102 ++++++++++++++++++ 2 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 13d041e2b..b78ed59d0 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -96,6 +96,12 @@ class QueryBuilder */ private $_maxResults = null; + /** + * Keeps root entity alias names for join entities + * @var array + */ + private $joinRootAliases = array(); + /** * Initializes a new QueryBuilder that uses the given EntityManager. * @@ -234,10 +240,22 @@ class QueryBuilder * @deprecated Please use $qb->getRootAliases() instead. * @return string $rootAlias */ - public function getRootAlias() + public function getRootAlias($rootAlias = null, $alias = null) { - $aliases = $this->getRootAliases(); - return $aliases[0]; + if ( ! is_null($rootAlias) && in_array($rootAlias, $this->getRootAliases())) { + // Do nothing + } elseif ( ! is_null($rootAlias) && isset($this->joinRootAliases[$rootAlias])) { + $rootAlias = $this->joinRootAliases[$rootAlias]; + } else { + $aliases = $this->getRootAliases(); + $rootAlias = $aliases[0]; + } + + if ( ! is_null($alias)) { + $this->joinRootAliases[$alias] = $rootAlias; + } + + return $rootAlias; } /** @@ -669,9 +687,7 @@ class QueryBuilder { $rootAlias = substr($join, 0, strpos($join, '.')); - if ( ! in_array($rootAlias, $this->getRootAliases())) { - $rootAlias = $this->getRootAlias(); - } + $rootAlias = $this->getRootAlias($rootAlias, $alias); $join = new Expr\Join( Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy @@ -705,9 +721,7 @@ class QueryBuilder { $rootAlias = substr($join, 0, strpos($join, '.')); - if ( ! in_array($rootAlias, $this->getRootAliases())) { - $rootAlias = $this->getRootAlias(); - } + $rootAlias = $this->getRootAlias($rootAlias, $alias); $join = new Expr\Join( Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php new file mode 100644 index 000000000..703142003 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php @@ -0,0 +1,102 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757A'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757B'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757C'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757D'), + )); + } catch(\Exception $ignored) {} + } + + public function testFailingCase() + { + $qb = $this->_em->createQueryBuilder(); + /* @var $qb \Doctrine\ORM\QueryBuilder */ + + $qb->select('_a') + ->from(__NAMESPACE__ . '\DDC1757A', '_a') + ->from(__NAMESPACE__ . '\DDC1757B', '_b') + ->join('_b.c', '_c') + ->join('_c.d', '_d'); + + $q = $qb->getQuery(); + $dql = $q->getDQL(); + $q->getResult(); + } +} + +/** + * @Entity + */ +class DDC1757A +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + private $id; +} + +/** + * @Entity + */ +class DDC1757B +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @OneToOne(targetEntity="DDC1757C") + */ + private $c; +} + +/** + * @Entity + */ +class DDC1757C +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + public $id; + + /** + * @OneToOne(targetEntity="DDC1757D") + */ + private $d; +} + +/** + * @Entity + */ +class DDC1757D +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + public $id; +} From 29a94f4f520122361c479bec55689788e1d3ab72 Mon Sep 17 00:00:00 2001 From: gedrox Date: Thu, 5 Apr 2012 13:56:08 +0300 Subject: [PATCH 6/8] Parameter PHP documentation for the QueryBuilder::getRootAlias() method --- lib/Doctrine/ORM/QueryBuilder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index b78ed59d0..6d0df50d7 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -238,6 +238,8 @@ class QueryBuilder * * * @deprecated Please use $qb->getRootAliases() instead. + * @param string $rootAlias + * @param string $alias * @return string $rootAlias */ public function getRootAlias($rootAlias = null, $alias = null) From 3ddc461d30afbce6b315070d4a64fab117945172 Mon Sep 17 00:00:00 2001 From: Aigars Gedroics Date: Tue, 10 Apr 2012 11:47:05 +0300 Subject: [PATCH 7/8] [DDC-1757] Fix moved to private method, test improved. --- lib/Doctrine/ORM/QueryBuilder.php | 57 +++++++++++-------- .../ORM/Functional/Ticket/DDC1757Test.php | 24 ++++++-- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 6d0df50d7..3dfc2754b 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -97,8 +97,7 @@ class QueryBuilder private $_maxResults = null; /** - * Keeps root entity alias names for join entities - * @var array + * @var array Keeps root entity alias names for join entities. */ private $joinRootAliases = array(); @@ -225,6 +224,32 @@ class QueryBuilder ->setMaxResults($this->_maxResults); } + /** + * Finds the root entity alias of the joined entity. + * + * @param string $alias The alias of the new join entity + * @param string $parentAlias The parent entity alias of the join relationship + * @return string + */ + private function findRootAlias($alias, $parentAlias) + { + $rootAlias = null; + + if (in_array($parentAlias, $this->getRootAliases())) { + $rootAlias = $parentAlias; + } elseif (isset($this->joinRootAliases[$parentAlias])) { + $rootAlias = $this->joinRootAliases[$parentAlias]; + } else { + // Should never happen with correct joining order. Might be + // thoughtful to throw exception instead. + $rootAlias = $this->getRootAlias(); + } + + $this->joinRootAliases[$alias] = $rootAlias; + + return $rootAlias; + } + /** * Gets the FIRST root alias of the query. This is the first entity alias involved * in the construction of the query. @@ -238,26 +263,12 @@ class QueryBuilder * * * @deprecated Please use $qb->getRootAliases() instead. - * @param string $rootAlias - * @param string $alias * @return string $rootAlias */ - public function getRootAlias($rootAlias = null, $alias = null) + public function getRootAlias() { - if ( ! is_null($rootAlias) && in_array($rootAlias, $this->getRootAliases())) { - // Do nothing - } elseif ( ! is_null($rootAlias) && isset($this->joinRootAliases[$rootAlias])) { - $rootAlias = $this->joinRootAliases[$rootAlias]; - } else { - $aliases = $this->getRootAliases(); - $rootAlias = $aliases[0]; - } - - if ( ! is_null($alias)) { - $this->joinRootAliases[$alias] = $rootAlias; - } - - return $rootAlias; + $aliases = $this->getRootAliases(); + return $aliases[0]; } /** @@ -687,9 +698,9 @@ class QueryBuilder */ public function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) { - $rootAlias = substr($join, 0, strpos($join, '.')); + $parentAlias = substr($join, 0, strpos($join, '.')); - $rootAlias = $this->getRootAlias($rootAlias, $alias); + $rootAlias = $this->findRootAlias($alias, $parentAlias); $join = new Expr\Join( Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy @@ -721,9 +732,9 @@ class QueryBuilder */ public function leftJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) { - $rootAlias = substr($join, 0, strpos($join, '.')); + $parentAlias = substr($join, 0, strpos($join, '.')); - $rootAlias = $this->getRootAlias($rootAlias, $alias); + $rootAlias = $this->findRootAlias($alias, $parentAlias); $join = new Expr\Join( Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php index 703142003..49a573390 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php @@ -11,7 +11,7 @@ class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - + try { $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757A'), @@ -26,16 +26,28 @@ class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase { $qb = $this->_em->createQueryBuilder(); /* @var $qb \Doctrine\ORM\QueryBuilder */ - + $qb->select('_a') ->from(__NAMESPACE__ . '\DDC1757A', '_a') ->from(__NAMESPACE__ . '\DDC1757B', '_b') ->join('_b.c', '_c') ->join('_c.d', '_d'); - - $q = $qb->getQuery(); - $dql = $q->getDQL(); - $q->getResult(); + + $q = $qb->getQuery(); + $dql = $q->getDQL(); + + try { + $data = $q->getResult(); + + self::assertEmpty($data); + } catch (\Doctrine\ORM\Query\QueryException $queryException) { + // Show difference between expected and actual queries on error + self::assertEquals("SELECT _a FROM " . __NAMESPACE__ . "\DDC1757A _a, " . __NAMESPACE__ . "\DDC1757B _b INNER JOIN _b.c _c INNER JOIN _c.d _d", + $dql, + "Wrong DQL query: " . $queryException->getMessage()); + + throw new \RuntimeException("Unexpected issue. DQL is correct but the query is failing."); + } } } From 5392133beb62b994e4b34b10067e0f5021f0cd9a Mon Sep 17 00:00:00 2001 From: Aigars Gedroics Date: Tue, 17 Apr 2012 10:57:31 +0300 Subject: [PATCH 8/8] [DDC-1757] test checks DQL only now, doesn't create schema anymore --- .../ORM/Functional/Ticket/DDC1757Test.php | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php index 49a573390..77f32907e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php @@ -8,20 +8,6 @@ require_once __DIR__ . '/../../../TestInit.php'; class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase { - protected function setUp() - { - parent::setUp(); - - try { - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757A'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757B'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757C'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1757D'), - )); - } catch(\Exception $ignored) {} - } - public function testFailingCase() { $qb = $this->_em->createQueryBuilder(); @@ -36,18 +22,10 @@ class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase $q = $qb->getQuery(); $dql = $q->getDQL(); - try { - $data = $q->getResult(); - - self::assertEmpty($data); - } catch (\Doctrine\ORM\Query\QueryException $queryException) { - // Show difference between expected and actual queries on error - self::assertEquals("SELECT _a FROM " . __NAMESPACE__ . "\DDC1757A _a, " . __NAMESPACE__ . "\DDC1757B _b INNER JOIN _b.c _c INNER JOIN _c.d _d", - $dql, - "Wrong DQL query: " . $queryException->getMessage()); - - throw new \RuntimeException("Unexpected issue. DQL is correct but the query is failing."); - } + // Show difference between expected and actual queries on error + self::assertEquals("SELECT _a FROM " . __NAMESPACE__ . "\DDC1757A _a, " . __NAMESPACE__ . "\DDC1757B _b INNER JOIN _b.c _c INNER JOIN _c.d _d", + $dql, + "Wrong DQL query"); } }