From 30897c311593a9e51200d7d5bffc8aa6bdcb81b0 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Fri, 1 Nov 2013 20:46:08 +0100 Subject: [PATCH] adds tests for update/delete DQL queries --- .../Tests/ORM/Functional/ValueObjectsTest.php | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index a309acdb1..9386d1885 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -111,13 +111,32 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($person); $this->_em->flush($person); - $dql = "SELECT p FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.address.city = :city"; - $loadedPerson = $this->_em->createQuery($dql) + // SELECT + $selectDql = "SELECT p FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.address.city = :city"; + $loadedPerson = $this->_em->createQuery($selectDql) ->setParameter('city', 'Karlsruhe') ->getSingleResult(); $this->assertEquals($person, $loadedPerson); - $this->assertNull($this->_em->createQuery($dql)->setParameter('city', 'asdf')->getOneOrNullResult()); + $this->assertNull($this->_em->createQuery($selectDql)->setParameter('city', 'asdf')->getOneOrNullResult()); + + // UPDATE + $updateDql = "UPDATE " . __NAMESPACE__ . "\\DDC93Person p SET p.address.street = :street WHERE p.address.city = :city"; + $this->_em->createQuery($updateDql) + ->setParameter('street', 'Boo') + ->setParameter('city', 'Karlsruhe') + ->execute(); + + $this->_em->refresh($person); + $this->assertEquals('Boo', $person->address->street); + + // DELETE + $this->_em->createQuery("DELETE " . __NAMESPACE__ . "\\DDC93Person p WHERE p.address.city = :city") + ->setParameter('city', 'Karlsruhe') + ->execute(); + + $this->_em->clear(); + $this->assertNull($this->_em->find(__NAMESPACE__.'\\DDC93Person', $person->id)); } }