From 6070c9395dee672538cd53fd9dd87ae6bdaf891d Mon Sep 17 00:00:00 2001 From: Karl Rixon Date: Mon, 23 Mar 2015 15:44:06 +0000 Subject: [PATCH] Functional tests for partial selection with embeddables [DDC-3630] --- .../Tests/ORM/Functional/ValueObjectsTest.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index de3ab7ee0..f7137b18b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -172,6 +172,42 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $this->assertNull($this->_em->find(__NAMESPACE__.'\\DDC93Person', $person->id)); } + + public function testPartialDqlOnEmbeddedObjectsField() + { + $person = new DDC93Person('Karl', new DDC93Address('Foo', '12345', 'Gosport', new DDC93Country('England'))); + $this->_em->persist($person); + $this->_em->flush($person); + $this->_em->clear(); + + // Prove that the entity was persisted correctly. + $dql = "SELECT p FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.name = :name"; + + $person = $this->_em->createQuery($dql) + ->setParameter('name', 'Karl') + ->getSingleResult(); + + $this->assertEquals('Gosport', $person->address->city); + $this->assertEquals('Foo', $person->address->street); + $this->assertEquals('12345', $person->address->zip); + $this->assertEquals('England', $person->address->country->name); + + // Clear the EM and prove that the embeddable can be the subject of a partial query. + $this->_em->clear(); + + $dql = "SELECT PARTIAL p.{id,address.city} FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.name = :name"; + + $person = $this->_em->createQuery($dql) + ->setParameter('name', 'Karl') + ->getSingleResult(); + + // Selected field must be equal, all other fields must be null. + $this->assertEquals('Gosport', $person->address->city); + $this->assertNull($person->address->street); + $this->assertNull($person->address->zip); + $this->assertNull($person->address->country); + $this->assertNull($person->name); + } public function testDqlWithNonExistentEmbeddableField() { @@ -180,6 +216,14 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->createQuery("SELECT p FROM " . __NAMESPACE__ . "\\DDC93Person p WHERE p.address.asdfasdf IS NULL") ->execute(); } + + public function testPartialDqlWithNonExistentEmbeddableField() + { + $this->setExpectedException('Doctrine\ORM\Query\QueryException', "no mapped field named 'address.asdfasdf'"); + + $this->_em->createQuery("SELECT PARTIAL p.{id,address.asdfasdf} FROM " . __NAMESPACE__ . "\\DDC93Person p") + ->execute(); + } public function testEmbeddableWithInheritance() {