ReadOnlyTest.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional;
  3. require_once __DIR__ . '/../../TestInit.php';
  4. /**
  5. * Functional Query tests.
  6. *
  7. * @group DDC-692
  8. */
  9. class ReadOnlyTest extends \Doctrine\Tests\OrmFunctionalTestCase
  10. {
  11. protected function setUp()
  12. {
  13. parent::setUp();
  14. $this->_schemaTool->createSchema(array(
  15. $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ReadOnlyEntity'),
  16. ));
  17. }
  18. public function testReadOnlyEntityNeverChangeTracked()
  19. {
  20. $readOnly = new ReadOnlyEntity("Test1", 1234);
  21. $this->_em->persist($readOnly);
  22. $this->_em->flush();
  23. $readOnly->name = "Test2";
  24. $readOnly->number = 4321;
  25. $this->_em->flush();
  26. $this->_em->clear();
  27. $dbReadOnly = $this->_em->find('Doctrine\Tests\ORM\Functional\ReadOnlyEntity', $readOnly->id);
  28. $this->assertEquals("Test1", $dbReadOnly->name);
  29. $this->assertEquals(1234, $dbReadOnly->number);
  30. }
  31. }
  32. /**
  33. * @Entity(readOnly=true)
  34. */
  35. class ReadOnlyEntity
  36. {
  37. /**
  38. * @Id @GeneratedValue @Column(type="integer")
  39. * @var int
  40. */
  41. public $id;
  42. /** @column(type="string") */
  43. public $name;
  44. /** @Column(type="integer") */
  45. public $number;
  46. public function __construct($name, $number)
  47. {
  48. $this->name = $name;
  49. $this->number = $number;
  50. }
  51. }