DDC719Test.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. require_once __DIR__ . '/../../../TestInit.php';
  4. class DDC719Test extends \Doctrine\Tests\OrmFunctionalTestCase
  5. {
  6. protected function setUp()
  7. {
  8. parent::setUp();
  9. //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
  10. $this->_schemaTool->createSchema(array(
  11. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC719Group'),
  12. ));
  13. }
  14. public function testIsEmptySqlGeneration()
  15. {
  16. $q = $this->_em->createQuery('SELECT g, c FROM Doctrine\Tests\ORM\Functional\Ticket\DDC719Group g LEFT JOIN g.children c WHERE g.parents IS EMPTY');
  17. $this->assertEquals(
  18. strtolower('SELECT g0_.name AS name0, g0_.description AS description1, g0_.id AS id2, g1_.name AS name3, g1_.description AS description4, g1_.id AS id5 FROM groups g0_ LEFT JOIN groups_groups g2_ ON g0_.id = g2_.parent_id LEFT JOIN groups g1_ ON g1_.id = g2_.child_id WHERE (SELECT COUNT(*) FROM groups_groups g3_ WHERE g3_.child_id = g0_.id) = 0'),
  19. strtolower($q->getSQL())
  20. );
  21. }
  22. }
  23. /**
  24. * @MappedSuperclass
  25. */
  26. class Entity
  27. {
  28. /**
  29. * @Id @GeneratedValue
  30. * @Column(type="integer")
  31. */
  32. protected $id;
  33. public function getId() { return $this->id; }
  34. }
  35. /**
  36. * @Entity
  37. * @Table(name="groups")
  38. */
  39. class DDC719Group extends Entity {
  40. /** @Column(type="string", nullable=false) */
  41. protected $name;
  42. /** @Column(type="string", nullable=true) */
  43. protected $description;
  44. /**
  45. * @ManyToMany(targetEntity="DDC719Group", inversedBy="parents")
  46. * @JoinTable(name="groups_groups",
  47. * joinColumns={@JoinColumn(name="parent_id", referencedColumnName="id")},
  48. * inverseJoinColumns={@JoinColumn(name="child_id", referencedColumnName="id")}
  49. * )
  50. */
  51. protected $children = NULL;
  52. /**
  53. * @ManyToMany(targetEntity="DDC719Group", mappedBy="children")
  54. */
  55. protected $parents = NULL;
  56. /**
  57. * construct
  58. */
  59. public function __construct() {
  60. parent::__construct();
  61. $this->channels = new ArrayCollection();
  62. $this->children = new ArrayCollection();
  63. $this->parents = new ArrayCollection();
  64. }
  65. /**
  66. * adds group as new child
  67. *
  68. * @param Group $child
  69. */
  70. public function addGroup(Group $child) {
  71. if ( ! $this->children->contains($child)) {
  72. $this->children->add($child);
  73. $child->addGroup($this);
  74. }
  75. }
  76. /**
  77. * adds channel as new child
  78. *
  79. * @param Channel $child
  80. */
  81. public function addChannel(Channel $child) {
  82. if ( ! $this->channels->contains($child)) {
  83. $this->channels->add($child);
  84. }
  85. }
  86. /**
  87. * getter & setter
  88. */
  89. public function getName() { return $this->name; }
  90. public function setName($name) { $this->name = $name; }
  91. public function getDescription() { return $this->description; }
  92. public function setDescription($description) { $this->description = $description; }
  93. public function getChildren() { return $this->children; }
  94. public function getParents() { return $this->parents; }
  95. public function getChannels() { return $this->channels; }
  96. }