From 6c96d63bd59a1895c1e7441068b4ced246880067 Mon Sep 17 00:00:00 2001 From: Olda Salek Date: Tue, 27 Sep 2022 14:45:12 +0200 Subject: [PATCH 1/2] add failing testcase test enum Change sets --- .../Tests/ORM/Functional/EnumTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/EnumTest.php b/tests/Doctrine/Tests/ORM/Functional/EnumTest.php index 9e53b856087..151067ef280 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EnumTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EnumTest.php @@ -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]); From a1ed32f697f66d33de42fe96b1ea90e873ba2d5f Mon Sep 17 00:00:00 2001 From: HypeMC Date: Wed, 28 Sep 2022 00:02:02 +0200 Subject: [PATCH 2/2] Fix change set computation with enums --- lib/Doctrine/ORM/UnitOfWork.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 3a157c404b8..a3f1794899b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -4,6 +4,7 @@ namespace Doctrine\ORM; +use BackedEnum; use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -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;