/
CompositePrimaryKeyTest.php
95 lines (72 loc) · 3.01 KB
/
CompositePrimaryKeyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Tests\Models\Navigation\NavCountry;
use Doctrine\Tests\Models\Navigation\NavPointOfInterest;
use Doctrine\Tests\Models\Navigation\NavTour;
require_once __DIR__ . '/../../TestInit.php';
class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('navigation');
parent::setUp();
}
public function putGermanysBrandenburderTor()
{
$country = new NavCountry("Germany");
$this->_em->persist($country);
$poi = new NavPointOfInterest(100, 200, "Brandenburger Tor", $country);
$this->_em->persist($poi);
$this->_em->flush();
$this->_em->clear();
}
public function putTripAroundEurope()
{
$poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
$tour = new NavTour("Trip around Europe");
$tour->addPointOfInterest($poi);
$this->_em->persist($tour);
$this->_em->flush();
$this->_em->clear();
return $tour;
}
public function testPersistCompositePkEntity()
{
$this->putGermanysBrandenburderTor();
$poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
$this->assertInstanceOf('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi);
$this->assertEquals(100, $poi->getLat());
$this->assertEquals(200, $poi->getLong());
$this->assertEquals('Brandenburger Tor', $poi->getName());
}
public function testManyToManyCompositeRelation()
{
$this->putGermanysBrandenburderTor();
$tour = $this->putTripAroundEurope();
$tour = $this->_em->find('Doctrine\Tests\Models\Navigation\NavTour', $tour->getId());
$this->assertEquals(1, count($tour->getPointOfInterests()));
}
public function testCompositeDqlEagerFetching()
{
$this->putGermanysBrandenburderTor();
$this->putTripAroundEurope();
$dql = 'SELECT t, p, c FROM Doctrine\Tests\Models\Navigation\NavTour t ' .
'INNER JOIN t.pois p INNER JOIN p.country c';
$tours = $this->_em->createQuery($dql)->getResult();
$this->assertEquals(1, count($tours));
$pois = $tours[0]->getPointOfInterests();
$this->assertEquals(1, count($pois));
$this->assertEquals('Brandenburger Tor', $pois[0]->getName());
}
public function testCompositeCollectionMemberExpression()
{
$this->markTestSkipped('How to test this?');
$this->putGermanysBrandenburderTor();
$this->putTripAroundEurope();
$dql = 'SELECT t FROM Doctrine\Tests\Models\Navigation\NavTour t, Doctrine\Tests\Models\Navigation\NavPointOfInterest p ' .
'WHERE p MEMBER OF t.pois';
$tours = $this->_em->createQuery($dql)
->getResult();
$this->assertEquals(1, count($tours));
}
}