Skip to content

Commit

Permalink
[EntityMigrator] Integrate DoctrineEnvelopeEntityReference custom exc…
Browse files Browse the repository at this point in the history
…eption
  • Loading branch information
mpoiriert committed Dec 13, 2024
1 parent ee2ee36 commit 8598fc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions packages/entity-migrator/Message/MigrateEntityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
namespace Draw\Component\EntityMigrator\Message;

use Draw\Component\EntityMigrator\Entity\EntityMigrationInterface;
use Draw\Component\Messenger\DoctrineEnvelopeEntityReference\Exception\ObjectNotFoundException;
use Draw\Component\Messenger\DoctrineEnvelopeEntityReference\Message\DoctrineReferenceAwareInterface;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Draw\Component\Messenger\DoctrineEnvelopeEntityReference\Stamp\PropertyReferenceStamp;

class MigrateEntityCommand implements DoctrineReferenceAwareInterface
{
private ?EntityMigrationInterface $entity;
private PropertyReferenceStamp|EntityMigrationInterface|null $entity;

public function __construct(EntityMigrationInterface $entity)
{
$this->entity = $entity;
}

public function getEntity(): ?EntityMigrationInterface
public function getEntity(): EntityMigrationInterface
{
if (null === $this->entity) {
throw new UnrecoverableMessageHandlingException('Entity not found');
if (!$this->entity instanceof EntityMigrationInterface) {
throw new ObjectNotFoundException($this->entity?->getClass() ?? EntityMigrationInterface::class, $this->entity);
}

return $this->entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use Draw\Component\Core\Reflection\ReflectionAccessor;
use Draw\Component\EntityMigrator\Entity\EntityMigrationInterface;
use Draw\Component\EntityMigrator\Message\MigrateEntityCommand;
use Draw\Component\Messenger\DoctrineEnvelopeEntityReference\Exception\ObjectNotFoundException;
use Draw\Component\Messenger\DoctrineEnvelopeEntityReference\Stamp\PropertyReferenceStamp;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;

/**
* @internal
Expand Down Expand Up @@ -36,11 +37,11 @@ public function testGetEntity(): void
ReflectionAccessor::setPropertyValue(
$this->object,
'entity',
null
$stamp = new PropertyReferenceStamp('entity', EntityMigrationInterface::class, ['id' => 1])
);

static::expectExceptionObject(
new UnrecoverableMessageHandlingException('Entity not found')
new ObjectNotFoundException(EntityMigrationInterface::class, $stamp)
);

$this->object->getEntity();
Expand Down

0 comments on commit 8598fc9

Please sign in to comment.