Skip to content

Commit

Permalink
Fix change set computation with enums (#10074)
Browse files Browse the repository at this point in the history
* add failing testcase test enum Change sets

* Fix change set computation with enums

Co-authored-by: Olda Salek <mzk@mozektevidi.net>
  • Loading branch information
HypeMC and mzk committed Oct 10, 2022
1 parent 5b6f3cd commit 1ed0057
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Doctrine/ORM/UnitOfWork.php
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM;

use BackedEnum;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
Expand Down Expand Up @@ -743,6 +744,10 @@ public function computeChangeSet(ClassMetadata $class, $entity)

$orgValue = $originalData[$propName];

if ($orgValue instanceof BackedEnum) {
$orgValue = $orgValue->value;
}

// skip if value haven't changed
if ($orgValue === $actualValue) {
continue;
Expand Down
40 changes: 40 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/EnumTest.php
Expand Up @@ -260,6 +260,46 @@ public function testEnumArrayInDtoHydration(): void
self::assertEqualsCanonicalizing([Unit::Gram, Unit::Meter], $result[0]->supportedUnits);
}

public function testEnumChangeSetsSimpleObjectHydrator(): void
{
$this->setUpEntitySchema([Card::class]);

$card = new Card();
$card->suit = Suit::Clubs;

$this->_em->persist($card);
$this->_em->flush();
$this->_em->clear();

$result = $this->_em->find(Card::class, $card->id);

$this->_em->getUnitOfWork()->computeChangeSets();

self::assertFalse($this->_em->getUnitOfWork()->isScheduledForUpdate($result));
}

public function testEnumChangeSetsObjectHydrator(): void
{
$this->setUpEntitySchema([Card::class]);

$card = new Card();
$card->suit = Suit::Clubs;

$this->_em->persist($card);
$this->_em->flush();
$this->_em->clear();

$result = $this->_em->createQueryBuilder()
->from(Card::class, 'c')
->select('c')
->getQuery()
->getResult();

$this->_em->getUnitOfWork()->computeChangeSets();

self::assertFalse($this->_em->getUnitOfWork()->isScheduledForUpdate($result[0]));
}

public function testFindByEnum(): void
{
$this->setUpEntitySchema([Card::class]);
Expand Down

0 comments on commit 1ed0057

Please sign in to comment.