Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for Second level cache with Version, DDC #7067 #7069

Merged
merged 2 commits into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e
$data = $this->uow->getOriginalEntityData($entity);
$data = array_merge($data, $persister->getIdentifier($entity)); // why update has no identifier values ?

if ($metadata->isVersioned()) {
$data[$metadata->versionProperty->getName()] = $metadata->versionProperty->getValue($entity);
}

foreach ($metadata->getDeclaredPropertiesIterator() as $name => $association) {
if (! isset($data[$name]) || $association instanceof FieldMetadata) {
continue;
Expand Down
69 changes: 69 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Annotation as ORM;

final class GH7067Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp() : void
{
$this->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();
}
}

/**
* @ORM\Entity()
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/
class GH7067Entity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
public $id;

/**
* @ORM\Column(type="datetime")
*
* @var \DateTime
*/
public $lastUpdate;

/**
* @ORM\Column(type="datetime")
* @ORM\Version()
*
* @var \DateTime
*/
public $version;
}