From c2ff2292c1751b026619cb0909f3ad9ab8e59132 Mon Sep 17 00:00:00 2001 From: Stefan Gehrig Date: Thu, 15 May 2025 12:45:13 +0200 Subject: [PATCH 1/4] [#2006] allow `integer` type for blamable fields doctrine uses `integer` if the column is of type `int` Signed-off-by: Stefan Gehrig --- src/Blameable/Mapping/Driver/Attribute.php | 5 +- .../Gedmo/Blameable/BlameableIntegerTest.php | 61 +++++++++++++++++ .../Fixture/Entity/CompanyInteger.php | 67 +++++++++++++++++++ 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 tests/Gedmo/Blameable/BlameableIntegerTest.php create mode 100644 tests/Gedmo/Blameable/Fixture/Entity/CompanyInteger.php diff --git a/src/Blameable/Mapping/Driver/Attribute.php b/src/Blameable/Mapping/Driver/Attribute.php index de2ce4158c..afbbf73536 100644 --- a/src/Blameable/Mapping/Driver/Attribute.php +++ b/src/Blameable/Mapping/Driver/Attribute.php @@ -36,6 +36,7 @@ class Attribute extends AbstractAnnotationDriver 'one', 'string', 'int', + 'integer', 'ulid', 'uuid', 'ascii_string', @@ -65,12 +66,12 @@ public function readExtendedMetadata($meta, array &$config) if ($meta->hasField($field)) { if (!$this->isValidField($meta, $field)) { - throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' or a one-to-many relation in class - {$meta->getName()}"); + throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string', 'integer' or a one-to-many relation in class - {$meta->getName()}"); } } else { // association if (!$meta->isSingleValuedAssociation($field)) { - throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}"); + throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string or integer field - {$meta->getName()}"); } } diff --git a/tests/Gedmo/Blameable/BlameableIntegerTest.php b/tests/Gedmo/Blameable/BlameableIntegerTest.php new file mode 100644 index 0000000000..a9b850ed62 --- /dev/null +++ b/tests/Gedmo/Blameable/BlameableIntegerTest.php @@ -0,0 +1,61 @@ + http://www.gediminasm.org + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gedmo\Blameable; + +use Doctrine\Common\EventManager; +use Gedmo\Tests\Blameable\Fixture\Entity\CompanyInteger; +use Gedmo\Tests\Tool\BaseTestCaseORM; + +final class BlameableIntegerTest extends BaseTestCaseORM +{ + private int $userId; + + protected function setUp(): void + { + parent::setUp(); + + $this->userId = 42; + + $listener = new BlameableListener(); + $listener->setUserValue($this->userId); + + $evm = new EventManager(); + $evm->addEventSubscriber($listener); + + $this->getDefaultMockSqliteEntityManager($evm); + } + + public function testBlameableInteger(): void + { + $company = new CompanyInteger(); + $company->setName('My Name'); + + $this->em->persist($company); + $this->em->flush(); + $this->em->clear(); + + /** + * @var CompanyInteger $foundCompany + */ + $foundCompany = $this->em->getRepository(CompanyInteger::class)->findOneBy(['name' => 'My Name']); + $creator = $foundCompany->getCreator(); + + static::assertSame($this->userId, $creator); + } + + protected function getUsedEntityFixtures(): array + { + return [ + CompanyInteger::class, + ]; + } +} diff --git a/tests/Gedmo/Blameable/Fixture/Entity/CompanyInteger.php b/tests/Gedmo/Blameable/Fixture/Entity/CompanyInteger.php new file mode 100644 index 0000000000..3af55178d0 --- /dev/null +++ b/tests/Gedmo/Blameable/Fixture/Entity/CompanyInteger.php @@ -0,0 +1,67 @@ +id; + } + + public function setName(?string $name): void + { + $this->name = $name; + } + + public function getName(): ?string + { + return $this->name; + } + + public function getCreator(): ?int + { + return $this->creator; + } + + public function setCreator(?int $creator): void + { + $this->creator = $creator; + } +} From 6a2cf938e8ec1ccaa0f6d7e3f91e3192af36db20 Mon Sep 17 00:00:00 2001 From: Stefan Gehrig Date: Thu, 25 Sep 2025 10:52:15 +0200 Subject: [PATCH 2/4] CS fixes as per suggestion Co-authored-by: Javier Spagnoletti --- tests/Gedmo/Blameable/BlameableIntegerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Gedmo/Blameable/BlameableIntegerTest.php b/tests/Gedmo/Blameable/BlameableIntegerTest.php index a9b850ed62..a07ca4909b 100644 --- a/tests/Gedmo/Blameable/BlameableIntegerTest.php +++ b/tests/Gedmo/Blameable/BlameableIntegerTest.php @@ -47,7 +47,7 @@ public function testBlameableInteger(): void * @var CompanyInteger $foundCompany */ $foundCompany = $this->em->getRepository(CompanyInteger::class)->findOneBy(['name' => 'My Name']); - $creator = $foundCompany->getCreator(); + $creator = $foundCompany->getCreator(); static::assertSame($this->userId, $creator); } From 63afa9ab36c5f8f4af78fac0c7dcd5c6bf6938e6 Mon Sep 17 00:00:00 2001 From: Stefan Gehrig Date: Thu, 25 Sep 2025 10:52:30 +0200 Subject: [PATCH 3/4] CS fixes as per suggestion Co-authored-by: Javier Spagnoletti --- tests/Gedmo/Blameable/BlameableIntegerTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Gedmo/Blameable/BlameableIntegerTest.php b/tests/Gedmo/Blameable/BlameableIntegerTest.php index a07ca4909b..92107d59a0 100644 --- a/tests/Gedmo/Blameable/BlameableIntegerTest.php +++ b/tests/Gedmo/Blameable/BlameableIntegerTest.php @@ -43,10 +43,8 @@ public function testBlameableInteger(): void $this->em->flush(); $this->em->clear(); - /** - * @var CompanyInteger $foundCompany - */ $foundCompany = $this->em->getRepository(CompanyInteger::class)->findOneBy(['name' => 'My Name']); + assert($foundCompany instanceof CompanyInteger); $creator = $foundCompany->getCreator(); static::assertSame($this->userId, $creator); From d970a0d29abf0e46a785fd7003c7518d0cc94a7d Mon Sep 17 00:00:00 2001 From: Stefan Gehrig Date: Thu, 25 Sep 2025 10:56:18 +0200 Subject: [PATCH 4/4] [#2006] added changelog entry Signed-off-by: Stefan Gehrig --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6fd39c05c..1eb9107d2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ a release. --- ## [Unreleased] +### Fixed +- Blameable: (Re-) Added integer in allowed types list for Blameable fields (#2006) ## [3.20.0] - 2025-04-04 ### Fixed