From ff8cc6f4c0d9722d458ee7e53fd2d957e337c88c Mon Sep 17 00:00:00 2001 From: Josiah Truasheim Date: Mon, 18 Jun 2012 23:41:20 +0700 Subject: [PATCH] Fixed DDC-1880 Named Queries not registered in xml mapping --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- .../Tests/ORM/Mapping/AbstractMappingDriverTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index a69f78922..0154dc98e 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -76,7 +76,7 @@ class XmlDriver extends AbstractFileDriver $metadata->setPrimaryTable($table); // Evaluate named queries - if (isset($xmlRoot['named-queries'])) { + if (isset($xmlRoot->{'named-queries'})) { foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) { $metadata->addNamedQuery(array( 'name' => (string)$namedQueryElement['name'], diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 7d44417c3..e53881a91 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -485,6 +485,14 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity'); } + public function testNamedQuery() + { + $driver = $this->_loadDriver(); + $class = $this->createClassMetadata(__NAMESPACE__.'\User'); + + $this->assertCount(1, $class->getNamedQueries(), sprintf("Named queries not processed correctly by driver %s", get_class($driver))); + } + /** * @group DDC-1663 */ @@ -742,6 +750,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase * indexes={@Index(name="name_idx", columns={"name"}), @Index(name="0", columns={"user_email"})}, * options={"foo": "bar", "baz": {"key": "val"}} * ) + * @NamedQueries({@NamedQuery(name="all", query="SELECT u FROM __CLASS__ u")}) */ class User { @@ -921,6 +930,10 @@ class User 'allocationSize' => 100, 'initialValue' => 1, )); + $metadata->addNamedQuery(array( + 'name' => 'all', + 'query' => 'SELECT u FROM __CLASS__ u' + )); } }