DDC832Test.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Tests\Models\CMS\CmsUser;
  5. use Doctrine\Tests\Models\CMS\CmsGroup;
  6. require_once __DIR__ . '/../../../TestInit.php';
  7. class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase
  8. {
  9. public function setUp()
  10. {
  11. parent::setUp();
  12. $platform = $this->_em->getConnection()->getDatabasePlatform();
  13. if ($platform->getName() == "oracle") {
  14. $this->markTestSkipped('Doesnt run on Oracle.');
  15. }
  16. $this->_em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  17. try {
  18. $this->_schemaTool->createSchema(array(
  19. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedIndex'),
  20. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedTreeIndex'),
  21. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832Like'),
  22. ));
  23. } catch(\Exception $e) {
  24. }
  25. }
  26. public function tearDown()
  27. {
  28. /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
  29. $platform = $this->_em->getConnection()->getDatabasePlatform();
  30. $sm = $this->_em->getConnection()->getSchemaManager();
  31. $sm->dropTable($platform->quoteIdentifier('TREE_INDEX'));
  32. $sm->dropTable($platform->quoteIdentifier('INDEX'));
  33. $sm->dropTable($platform->quoteIdentifier('LIKE'));
  34. }
  35. /**
  36. * @group DDC-832
  37. */
  38. public function testQuotedTableBasicUpdate()
  39. {
  40. $like = new DDC832Like("test");
  41. $this->_em->persist($like);
  42. $this->_em->flush();
  43. $like->word = "test2";
  44. $this->_em->flush();
  45. }
  46. /**
  47. * @group DDC-832
  48. */
  49. public function testQuotedTableBasicRemove()
  50. {
  51. $like = new DDC832Like("test");
  52. $this->_em->persist($like);
  53. $this->_em->flush();
  54. $this->_em->remove($like);
  55. $this->_em->flush();
  56. }
  57. /**
  58. * @group DDC-832
  59. */
  60. public function testQuotedTableJoinedUpdate()
  61. {
  62. $index = new DDC832JoinedIndex("test");
  63. $this->_em->persist($index);
  64. $this->_em->flush();
  65. $index->name = "asdf";
  66. $this->_em->flush();
  67. }
  68. /**
  69. * @group DDC-832
  70. */
  71. public function testQuotedTableJoinedRemove()
  72. {
  73. $index = new DDC832JoinedIndex("test");
  74. $this->_em->persist($index);
  75. $this->_em->flush();
  76. $this->_em->remove($index);
  77. $this->_em->flush();
  78. }
  79. /**
  80. * @group DDC-832
  81. */
  82. public function testQuotedTableJoinedChildUpdate()
  83. {
  84. $index = new DDC832JoinedTreeIndex("test", 1, 2);
  85. $this->_em->persist($index);
  86. $this->_em->flush();
  87. $index->name = "asdf";
  88. $this->_em->flush();
  89. }
  90. /**
  91. * @group DDC-832
  92. */
  93. public function testQuotedTableJoinedChildRemove()
  94. {
  95. $index = new DDC832JoinedTreeIndex("test", 1, 2);
  96. $this->_em->persist($index);
  97. $this->_em->flush();
  98. $this->_em->remove($index);
  99. $this->_em->flush();
  100. }
  101. }
  102. /**
  103. * @Entity
  104. * @Table(name="`LIKE`")
  105. */
  106. class DDC832Like
  107. {
  108. /**
  109. * @Id @Column(type="integer") @GeneratedValue
  110. */
  111. public $id;
  112. /** @Column(type="string") */
  113. public $word;
  114. /**
  115. * @version
  116. * @Column(type="integer")
  117. */
  118. public $version;
  119. public function __construct($word)
  120. {
  121. $this->word = $word;
  122. }
  123. }
  124. /**
  125. * @Entity
  126. * @Table(name="`INDEX`")
  127. * @InheritanceType("JOINED")
  128. * @DiscriminatorColumn(name="discr", type="string")
  129. * @DiscriminatorMap({"like" = "DDC832JoinedIndex", "fuzzy" = "DDC832JoinedTreeIndex"})
  130. */
  131. class DDC832JoinedIndex
  132. {
  133. /**
  134. * @Id @Column(type="integer") @GeneratedValue
  135. */
  136. public $id;
  137. /** @Column(type="string") */
  138. public $name;
  139. /**
  140. * @version
  141. * @Column(type="integer")
  142. */
  143. public $version;
  144. public function __construct($name)
  145. {
  146. $this->name = $name;
  147. }
  148. }
  149. /**
  150. * @Entity
  151. * @Table(name="`TREE_INDEX`")
  152. */
  153. class DDC832JoinedTreeIndex extends DDC832JoinedIndex
  154. {
  155. /** @Column(type="integer") */
  156. public $lft;
  157. /** @Column(type="integer") */
  158. public $rgt;
  159. public function __construct($name, $lft, $rgt)
  160. {
  161. $this->name = $name;
  162. $this->lft = $lft;
  163. $this->rgt = $rgt;
  164. }
  165. }