DDC960Test.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. require_once __DIR__ . '/../../../TestInit.php';
  5. class DDC960Test extends \Doctrine\Tests\OrmFunctionalTestCase
  6. {
  7. protected function setUp()
  8. {
  9. parent::setUp();
  10. try {
  11. $this->_schemaTool->createSchema(array(
  12. $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Root'),
  13. $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Child')
  14. ));
  15. } catch(\Exception $e) {
  16. }
  17. }
  18. /**
  19. * @group DDC-960
  20. */
  21. public function testUpdateRootVersion()
  22. {
  23. $child = new DDC960Child('Test');
  24. $this->_em->persist($child);
  25. $this->_em->flush();
  26. $child->setName("Test2");
  27. $this->_em->flush();
  28. $this->assertEquals(2, $child->getVersion());
  29. }
  30. }
  31. /**
  32. * @Entity
  33. * @InheritanceType("JOINED")
  34. * @DiscriminatorMap({
  35. * "root" = "DDC960Root",
  36. * "child" = "DDC960Child"
  37. * })
  38. */
  39. class DDC960Root
  40. {
  41. /**
  42. * @Id @GeneratedValue @Column(type="integer")
  43. */
  44. private $id;
  45. /**
  46. * @Column(type="integer") @Version
  47. */
  48. private $version;
  49. public function getId()
  50. {
  51. return $this->id;
  52. }
  53. public function getVersion()
  54. {
  55. return $this->version;
  56. }
  57. }
  58. /**
  59. * @Entity
  60. */
  61. class DDC960Child extends DDC960Root
  62. {
  63. /**
  64. * @column(type="string")
  65. * @var string
  66. */
  67. private $name;
  68. public function __construct($name)
  69. {
  70. $this->name = $name;
  71. }
  72. public function setName($name)
  73. {
  74. $this->name = $name;
  75. }
  76. }