From 354fa14df450cd8752ef468eaafb1749448dfd92 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 29 Jul 2012 09:27:08 +0200 Subject: [PATCH] [DDC-1939] Add test for persistent collection delete with composite key --- .../Models/Navigation/NavPointOfInterest.php | 23 +++++++++++++++ .../Tests/Models/Navigation/NavUser.php | 28 +++++++++++++++++++ .../Functional/CompositePrimaryKeyTest.php | 23 +++++++++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 1 + 4 files changed, 75 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/Navigation/NavUser.php diff --git a/tests/Doctrine/Tests/Models/Navigation/NavPointOfInterest.php b/tests/Doctrine/Tests/Models/Navigation/NavPointOfInterest.php index 662a57a09..33d0f70bd 100644 --- a/tests/Doctrine/Tests/Models/Navigation/NavPointOfInterest.php +++ b/tests/Doctrine/Tests/Models/Navigation/NavPointOfInterest.php @@ -30,12 +30,25 @@ class NavPointOfInterest */ private $country; + /** + * @ManyToMany(targetEntity="NavUser", cascade={"persist"}) + * @JoinTable(name="navigation_pois_visitors", + * inverseJoinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, + * joinColumns={ + * @JoinColumn(name="poi_long", referencedColumnName="nav_long"), + * @JoinColumn(name="poi_lat", referencedColumnName="nav_lat") + * } + * ) + */ + private $visitors; + public function __construct($lat, $long, $name, $country) { $this->lat = $lat; $this->long = $long; $this->name = $name; $this->country = $country; + $this->visitors = new \Doctrine\Common\Collections\ArrayCollection; } public function getLong() { @@ -53,4 +66,14 @@ class NavPointOfInterest public function getCountry() { return $this->country; } + + public function addVisitor(NavUser $user) + { + $this->visitors[] = $user; + } + + public function getVisitors() + { + return $this->visitors; + } } diff --git a/tests/Doctrine/Tests/Models/Navigation/NavUser.php b/tests/Doctrine/Tests/Models/Navigation/NavUser.php new file mode 100644 index 000000000..42117e46b --- /dev/null +++ b/tests/Doctrine/Tests/Models/Navigation/NavUser.php @@ -0,0 +1,28 @@ +name = $name; + } +} + diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php index 4d321ad04..1af930a0c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php @@ -5,6 +5,7 @@ use Doctrine\Tests\Models\Navigation\NavCountry; use Doctrine\Tests\Models\Navigation\NavPointOfInterest; use Doctrine\Tests\Models\Navigation\NavTour; use Doctrine\Tests\Models\Navigation\NavPhotos; +use Doctrine\Tests\Models\Navigation\NavUser; require_once __DIR__ . '/../../TestInit.php'; @@ -118,4 +119,26 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->setExpectedException('Doctrine\ORM\ORMException', 'The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest'); $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100)); } + + /** + * @group DDC-1939 + */ + public function testDeleteCompositePersistentCollection() + { + $this->putGermanysBrandenburderTor(); + + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); + $poi->addVisitor(new NavUser("test1")); + $poi->addVisitor(new NavUser("test2")); + + $this->_em->flush(); + + $poi->getVisitors()->clear(); + + $this->_em->flush(); + $this->_em->clear(); + + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); + $this->assertEquals(0, count($poi->getVisitors())); + } } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 0e9343671..4b72a9a27 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -88,6 +88,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Routing\RoutingRouteBooking', ), 'navigation' => array( + 'Doctrine\Tests\Models\Navigation\NavUser', 'Doctrine\Tests\Models\Navigation\NavCountry', 'Doctrine\Tests\Models\Navigation\NavPhotos', 'Doctrine\Tests\Models\Navigation\NavTour',