diff --git a/src/Doctrine/RespectfulUuidGenerator.php b/src/Doctrine/RespectfulUuidGenerator.php deleted file mode 100644 index 38b3476..0000000 --- a/src/Doctrine/RespectfulUuidGenerator.php +++ /dev/null @@ -1,30 +0,0 @@ -getId() ?? Uuid::v7(); - } -} diff --git a/src/Entity/Contract/EntityIdTrait.php b/src/Entity/Contract/EntityIdTrait.php index 4d4cd1c..659ff0e 100644 --- a/src/Entity/Contract/EntityIdTrait.php +++ b/src/Entity/Contract/EntityIdTrait.php @@ -3,7 +3,6 @@ namespace Swag\Braintree\Entity\Contract; use Doctrine\ORM\Mapping as ORM; -use Swag\Braintree\Doctrine\RespectfulUuidGenerator; use Symfony\Component\Uid\Uuid; #[ORM\MappedSuperclass] @@ -12,17 +11,17 @@ trait EntityIdTrait #[ORM\Id] #[ORM\Column(type: 'uuid', unique: true)] #[ORM\GeneratedValue(strategy: 'CUSTOM')] - #[ORM\CustomIdGenerator(class: RespectfulUuidGenerator::class)] + #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] // will never be null in the database // null only signalizes the uuid-generator to generate a new uuid for the database - private ?Uuid $id = null; + private Uuid $id; public function getId(): ?Uuid { - return $this->id; + return $this->id ?? null; } - public function setId(?Uuid $id): self + public function setId(Uuid $id): self { $this->id = $id; diff --git a/src/Entity/Contract/EntityInterface.php b/src/Entity/Contract/EntityInterface.php index 5a9f9a0..472c785 100644 --- a/src/Entity/Contract/EntityInterface.php +++ b/src/Entity/Contract/EntityInterface.php @@ -8,7 +8,7 @@ interface EntityInterface { public function getId(): ?Uuid; - public function setId(?Uuid $id): self; + public function setId(Uuid $id): self; public function getCreatedAt(): \DateTimeInterface; diff --git a/tests/unit/Doctrine/RespectfulUuidGeneratorTest.php b/tests/unit/Doctrine/RespectfulUuidGeneratorTest.php deleted file mode 100644 index cd8852a..0000000 --- a/tests/unit/Doctrine/RespectfulUuidGeneratorTest.php +++ /dev/null @@ -1,99 +0,0 @@ -getTestEntity(); - - $generator = new RespectfulUuidGenerator(); - $id = $generator->generateId($this->createMock(EntityManager::class), $entity); - - static::assertNotNull($id); - static::assertTrue(Uuid::isValid($id->toRfc4122())); - } - - public function testGenerateIdWithNullEntity(): void - { - $generator = new RespectfulUuidGenerator(); - $id = $generator->generateId($this->createMock(EntityManager::class), null); - - static::assertNull($id); - } - - public function testGenerateIdWithNonEntity(): void - { - $entity = new \stdClass(); - - $generator = new RespectfulUuidGenerator(); - - static::expectException(\RuntimeException::class); - static::expectExceptionMessage('Class stdClass not supported for respectful uuid generation. Use Swag\Braintree\Entity\Contract\EntityInterface instead'); - - $generator->generateId($this->createMock(EntityManager::class), $entity); - } - - public function testGenerateIdWithExistingId(): void - { - $uuid = Uuid::v7(); - - $entity = $this->getTestEntity($uuid); - - $generator = new RespectfulUuidGenerator(); - $id = $generator->generateId($this->createMock(EntityManager::class), $entity); - - static::assertNotNull($id); - static::assertSame($uuid, $id); - } - - private function getTestEntity(?Uuid $id = null): EntityInterface - { - return new class($id) implements EntityInterface { - public function __construct(private ?Uuid $id = null) - { - } - - public function getId(): ?Uuid - { - return $this->id; - } - - public function setId(?Uuid $id): EntityInterface - { - $this->id = $id; - - return $this; - } - - public function getCreatedAt(): \DateTimeInterface - { - return new \DateTime(); - } - - public function setCreatedAt(\DateTimeInterface $createdAt): EntityInterface - { - return $this; - } - - public function getUpdatedAt(): ?\DateTimeInterface - { - return null; - } - - public function setUpdatedAt(?\DateTimeInterface $updatedAt): EntityInterface - { - return $this; - } - }; - } -}