3 namespace Doctrine\Tests\ORM\Functional;
5 use Doctrine\Tests\Models\Routing\RoutingRoute;
6 use Doctrine\Tests\Models\Routing\RoutingLocation;
7 use Doctrine\Tests\Models\Routing\RoutingLeg;
9 require_once __DIR__ . '/../../TestInit.php';
12 * Tests a bidirectional one-to-one association mapping (without inheritance).
14 class OneToManyUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase
16 protected $locations = array();
18 public function setUp()
20 $this->useModelSet('routing');
23 $locations = array("Berlin", "Bonn", "Brasilia", "Atlanta");
25 foreach ($locations AS $locationName) {
26 $location = new RoutingLocation();
27 $location->name = $locationName;
28 $this->_em->persist($location);
29 $this->locations[$locationName] = $location;
34 public function testPersistOwning_InverseCascade()
36 $leg = new RoutingLeg();
37 $leg->fromLocation = $this->locations['Berlin'];
38 $leg->toLocation = $this->locations['Bonn'];
39 $leg->departureDate = new \DateTime("now");
40 $leg->arrivalDate = new \DateTime("now +5 hours");
42 $route = new RoutingRoute();
43 $route->legs[] = $leg;
45 $this->_em->persist($route);
49 $routes = $this->_em->createQuery(
50 "SELECT r, l, f, t FROM Doctrine\Tests\Models\Routing\RoutingRoute r ".
51 "JOIN r.legs l JOIN l.fromLocation f JOIN l.toLocation t"
54 $this->assertEquals(1, count($routes->legs));
55 $this->assertEquals("Berlin", $routes->legs[0]->fromLocation->name);
56 $this->assertEquals("Bonn", $routes->legs[0]->toLocation->name);
59 public function testLegsAreUniqueToRoutes()
61 $leg = new RoutingLeg();
62 $leg->fromLocation = $this->locations['Berlin'];
63 $leg->toLocation = $this->locations['Bonn'];
64 $leg->departureDate = new \DateTime("now");
65 $leg->arrivalDate = new \DateTime("now +5 hours");
67 $routeA = new RoutingRoute();
68 $routeA->legs[] = $leg;
70 $routeB = new RoutingRoute();
71 $routeB->legs[] = $leg;
73 $this->_em->persist($routeA);
74 $this->_em->persist($routeB);
76 $exceptionThrown = false;
78 // exception depending on the underyling Database Driver
80 } catch(\Exception $e) {
81 $exceptionThrown = true;
84 $this->assertTrue($exceptionThrown, "The underlying database driver throws an exception.");