PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/doctrine/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php

https://github.com/dlondero/fantamanager
PHP | 94 lines | 50 code | 15 blank | 29 comment | 3 complexity | 6cfcbeafc8109e0a8602b5cef5ca4863 MD5 | raw file
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. require_once __DIR__ . '/../../../TestInit.php';
  4. class DDC512Test extends \Doctrine\Tests\OrmFunctionalTestCase
  5. {
  6. protected function setUp()
  7. {
  8. parent::setUp();
  9. $this->_schemaTool->createSchema(array(
  10. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512Customer'),
  11. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512OfferItem'),
  12. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512Item'),
  13. ));
  14. }
  15. public function testIssue()
  16. {
  17. $customer1 = new DDC512Customer();
  18. $item = new DDC512OfferItem();
  19. $customer1->item = $item;
  20. $this->_em->persist($customer1);
  21. $customer2 = new DDC512Customer();
  22. $this->_em->persist($customer2);
  23. $this->_em->flush();
  24. $this->_em->clear();
  25. $q = $this->_em->createQuery("select u,i from ".__NAMESPACE__."\\DDC512Customer u left join u.item i");
  26. $result = $q->getResult();
  27. $this->assertEquals(2, count($result));
  28. $this->assertTrue($result[0] instanceof DDC512Customer);
  29. $this->assertTrue($result[1] instanceof DDC512Customer);
  30. if ($result[0]->id == $customer1->id) {
  31. $this->assertTrue($result[0]->item instanceof DDC512OfferItem);
  32. $this->assertEquals($item->id, $result[0]->item->id);
  33. $this->assertNull($result[1]->item);
  34. } else {
  35. $this->assertTrue($result[1]->item instanceof DDC512OfferItem);
  36. $this->assertNull($result[0]->item);
  37. }
  38. }
  39. }
  40. /**
  41. * @Entity
  42. */
  43. class DDC512Customer {
  44. /**
  45. * @Id
  46. * @Column(type="integer")
  47. * @GeneratedValue(strategy="AUTO")
  48. */
  49. public $id;
  50. /**
  51. * NOTE that we can currently not name the join column the same as the field
  52. * (item = item), this currently confuses Doctrine.
  53. *
  54. * @OneToOne(targetEntity="DDC512OfferItem", cascade={"remove","persist"})
  55. * @JoinColumn(name="item_id", referencedColumnName="id")
  56. */
  57. public $item;
  58. }
  59. /**
  60. * @Entity
  61. */
  62. class DDC512OfferItem extends DDC512Item
  63. {
  64. }
  65. /**
  66. * @Entity
  67. * @InheritanceType("JOINED")
  68. * @DiscriminatorColumn(name="discr", type="string")
  69. * @DiscriminatorMap({"item" = "DDC512Item", "offerItem" = "DDC512OfferItem"})
  70. */
  71. class DDC512Item
  72. {
  73. /**
  74. * @Id
  75. * @Column(type="integer")
  76. * @GeneratedValue(strategy="AUTO")
  77. */
  78. public $id;
  79. }