diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 06d329b37..154e869bf 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1715,6 +1715,13 @@ class Parser $token = $this->lexer->token; $className = $token['value']; + if (strrpos($className, ':') !== false) { + list($namespaceAlias, $simpleClassName) = explode(':', $className); + + $className = $this->em->getConfiguration() + ->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; + } + $this->match(Lexer::T_OPEN_PARENTHESIS); $args[] = $this->NewObjectArg(); diff --git a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php index 6859af5e6..4ef9d29e2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php @@ -153,6 +153,62 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); } + public function testShouldSupportFromEntityNamespaceAlias() + { + $dql = " + SELECT + new CmsUserDTO(u.name, e.email, a.city) + FROM + cms:CmsUser u + JOIN + u.email e + JOIN + u.address a + ORDER BY + u.name"; + + + $this->_em->getConfiguration() + ->addEntityNamespace('cms', 'Doctrine\Tests\Models\CMS'); + + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(3, $result); + + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + } + + public function testShouldSupportValueObjectNamespaceAlias() + { + $dql = " + SELECT + new cms:CmsUserDTO(u.name, e.email, a.city) + FROM + cms:CmsUser u + JOIN + u.email e + JOIN + u.address a + ORDER BY + u.name"; + + + $this->_em->getConfiguration() + ->addEntityNamespace('cms', 'Doctrine\Tests\Models\CMS'); + + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(3, $result); + + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + } + public function testShouldSupportLiteralExpression() { $dql = "