3 namespace Doctrine\Tests\ORM\Functional;
4 use Doctrine\Tests\Models\Navigation\NavCountry;
5 use Doctrine\Tests\Models\Navigation\NavPointOfInterest;
6 use Doctrine\Tests\Models\Navigation\NavTour;
7 use Doctrine\Tests\Models\Navigation\NavPhotos;
8 use Doctrine\Tests\Models\Navigation\NavUser;
10 require_once __DIR__ . '/../../TestInit.php';
12 class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase
14 public function setUp()
16 $this->useModelSet('navigation');
20 public function putGermanysBrandenburderTor()
22 $country = new NavCountry("Germany");
23 $this->_em->persist($country);
24 $poi = new NavPointOfInterest(100, 200, "Brandenburger Tor", $country);
25 $this->_em->persist($poi);
30 public function putTripAroundEurope()
32 $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
34 $tour = new NavTour("Trip around Europe");
35 $tour->addPointOfInterest($poi);
37 $this->_em->persist($tour);
44 public function testPersistCompositePkEntity()
46 $this->putGermanysBrandenburderTor();
48 $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
50 $this->assertInstanceOf('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi);
51 $this->assertEquals(100, $poi->getLat());
52 $this->assertEquals(200, $poi->getLong());
53 $this->assertEquals('Brandenburger Tor', $poi->getName());
59 public function testSetParameterCompositeKeyObject()
61 $this->putGermanysBrandenburderTor();
63 $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
64 $photo = new NavPhotos($poi, "asdf");
65 $this->_em->persist($photo);
69 $dql = 'SELECT t FROM Doctrine\Tests\Models\Navigation\NavPhotos t WHERE t.poi = ?1';
71 $this->setExpectedException('Doctrine\ORM\Query\QueryException', 'A single-valued association path expression to an entity with a composite primary key is not supported.');
72 $sql = $this->_em->createQuery($dql)->getSQL();
75 public function testManyToManyCompositeRelation()
77 $this->putGermanysBrandenburderTor();
78 $tour = $this->putTripAroundEurope();
80 $tour = $this->_em->find('Doctrine\Tests\Models\Navigation\NavTour', $tour->getId());
82 $this->assertEquals(1, count($tour->getPointOfInterests()));
85 public function testCompositeDqlEagerFetching()
87 $this->putGermanysBrandenburderTor();
88 $this->putTripAroundEurope();
90 $dql = 'SELECT t, p, c FROM Doctrine\Tests\Models\Navigation\NavTour t ' .
91 'INNER JOIN t.pois p INNER JOIN p.country c';
92 $tours = $this->_em->createQuery($dql)->getResult();
94 $this->assertEquals(1, count($tours));
96 $pois = $tours[0]->getPointOfInterests();
98 $this->assertEquals(1, count($pois));
99 $this->assertEquals('Brandenburger Tor', $pois[0]->getName());
102 public function testCompositeCollectionMemberExpression()
104 $this->markTestSkipped('How to test this?');
106 $this->putGermanysBrandenburderTor();
107 $this->putTripAroundEurope();
109 $dql = 'SELECT t FROM Doctrine\Tests\Models\Navigation\NavTour t, Doctrine\Tests\Models\Navigation\NavPointOfInterest p ' .
110 'WHERE p MEMBER OF t.pois';
111 $tours = $this->_em->createQuery($dql)
114 $this->assertEquals(1, count($tours));
117 public function testSpecifiyUnknownIdentifierPrimaryKeyFails()
119 $this->setExpectedException('Doctrine\ORM\ORMException', 'The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest');
120 $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100));
126 public function testDeleteCompositePersistentCollection()
128 $this->putGermanysBrandenburderTor();
130 $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
131 $poi->addVisitor(new NavUser("test1"));
132 $poi->addVisitor(new NavUser("test2"));
136 $poi->getVisitors()->clear();
141 $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
142 $this->assertEquals(0, count($poi->getVisitors()));