Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Blameable/Mapping/Driver/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Attribute extends AbstractAnnotationDriver
'one',
'string',
'int',
'integer',
'ulid',
'uuid',
'ascii_string',
Expand Down Expand Up @@ -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()}");
}
}

Expand Down
59 changes: 59 additions & 0 deletions tests/Gedmo/Blameable/BlameableIntegerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Doctrine Behavioral Extensions package.
* (c) Gediminas Morkevicius <[email protected]> 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,
];
}
}
67 changes: 67 additions & 0 deletions tests/Gedmo/Blameable/Fixture/Entity/CompanyInteger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Gedmo\Tests\Blameable\Fixture\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* @ORM\Entity
*/
#[ORM\Entity]
class CompanyInteger
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private $id;

/**
* @ORM\Column(name="name", type="string", length=128)
*/
#[ORM\Column(name: 'name', type: Types::STRING, length: 128)]
private ?string $name = null;

/**
* @var int|null
*
* @Gedmo\Blameable(on="create")
* @ORM\Column(name="creator", type="integer")
*/
#[ORM\Column(name: 'creator', type: Types::INTEGER)]
#[Gedmo\Blameable(on: 'create')]
private $creator;

public function getId(): ?int
{
return $this->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;
}
}