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 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..92107d59a0 --- /dev/null +++ b/tests/Gedmo/Blameable/BlameableIntegerTest.php @@ -0,0 +1,59 @@ + 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(); + + $foundCompany = $this->em->getRepository(CompanyInteger::class)->findOneBy(['name' => 'My Name']); + assert($foundCompany instanceof CompanyInteger); + $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; + } +}