From 8fc1d74820cafe80a1959c8200cf400b4aec540a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98Andrey=20Lukin=E2=80=99?= <‘lukin.andrej@gmail.com’> Date: Fri, 16 Feb 2018 11:33:20 +0300 Subject: [PATCH] Add test for L2C using optimistic locks As explained in #7067, fields with `@ORM\Version` annotation were not being added to L2C cached data. --- .../ORM/Functional/Ticket/GH7067Test.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php new file mode 100644 index 000000000..b82f25c05 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php @@ -0,0 +1,69 @@ +enableSecondLevelCache(); + parent::setUp(); + + $this->setUpEntitySchema([GH7067Entity::class]); + } + + /** + * @group 7067 + */ + public function testSLCWithVersion() : void + { + $entity = new GH7067Entity(); + $entity->lastUpdate = new \DateTime(); + + $this->_em->persist($entity); + $this->_em->flush(); + $this->_em->clear(); + + /** @var GH7067Entity $notCached */ + $notCached = $this->_em->find(GH7067Entity::class, $entity->id); + + self::assertNotNull($notCached->version, 'Version already cached by persister above, it must be not null'); + + $notCached->lastUpdate = new \DateTime(); + + $this->_em->flush(); + $this->_em->clear(); + } +} + +/** + * @Entity() + * @Cache(usage="NONSTRICT_READ_WRITE") + */ +class GH7067Entity +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + * + * @var int + */ + public $id; + + /** + * @Column(type="datetime") + * + * @var \DateTime + */ + public $lastUpdate; + + /** + * @Column(type="datetime") + * @Version + * + * @var \DateTime + */ + public $version; +}