X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FOneToManyUnidirectionalAssociationTest.php;fp=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FOneToManyUnidirectionalAssociationTest.php;h=42fd2923582f2599166ed25ff793c9a0461ffee5;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fapplication_blanche.git diff --git a/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php new file mode 100644 index 0000000..42fd292 --- /dev/null +++ b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php @@ -0,0 +1,86 @@ +useModelSet('routing'); + parent::setUp(); + + $locations = array("Berlin", "Bonn", "Brasilia", "Atlanta"); + + foreach ($locations AS $locationName) { + $location = new RoutingLocation(); + $location->name = $locationName; + $this->_em->persist($location); + $this->locations[$locationName] = $location; + } + $this->_em->flush(); + } + + public function testPersistOwning_InverseCascade() + { + $leg = new RoutingLeg(); + $leg->fromLocation = $this->locations['Berlin']; + $leg->toLocation = $this->locations['Bonn']; + $leg->departureDate = new \DateTime("now"); + $leg->arrivalDate = new \DateTime("now +5 hours"); + + $route = new RoutingRoute(); + $route->legs[] = $leg; + + $this->_em->persist($route); + $this->_em->flush(); + $this->_em->clear(); + + $routes = $this->_em->createQuery( + "SELECT r, l, f, t FROM Doctrine\Tests\Models\Routing\RoutingRoute r ". + "JOIN r.legs l JOIN l.fromLocation f JOIN l.toLocation t" + )->getSingleResult(); + + $this->assertEquals(1, count($routes->legs)); + $this->assertEquals("Berlin", $routes->legs[0]->fromLocation->name); + $this->assertEquals("Bonn", $routes->legs[0]->toLocation->name); + } + + public function testLegsAreUniqueToRoutes() + { + $leg = new RoutingLeg(); + $leg->fromLocation = $this->locations['Berlin']; + $leg->toLocation = $this->locations['Bonn']; + $leg->departureDate = new \DateTime("now"); + $leg->arrivalDate = new \DateTime("now +5 hours"); + + $routeA = new RoutingRoute(); + $routeA->legs[] = $leg; + + $routeB = new RoutingRoute(); + $routeB->legs[] = $leg; + + $this->_em->persist($routeA); + $this->_em->persist($routeB); + + $exceptionThrown = false; + try { + // exception depending on the underyling Database Driver + $this->_em->flush(); + } catch(\Exception $e) { + $exceptionThrown = true; + } + + $this->assertTrue($exceptionThrown, "The underlying database driver throws an exception."); + } +}