CompositePrimaryKeyTest.php 3.0KB

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