Skip to content

Commit

Permalink
Merge pull request #36 from PcComponentes/feature/remove_uuid_aggrega…
Browse files Browse the repository at this point in the history
…te_id_retro_compatibility

Remove UUID aggregate id support
  • Loading branch information
calmohallag authored Sep 20, 2022
2 parents 694d3b7 + 1fb01ca commit 544f5fc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 43 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,11 @@
"mkdir -p .git/hooks",
"cp -r ./config/hooks/* .git/hooks"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpro/grumphp": true
}
}
}
15 changes: 0 additions & 15 deletions ganchudo.yml.dist

This file was deleted.

27 changes: 1 addition & 26 deletions src/Util/Message/AggregateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace PcComponentes\Ddd\Util\Message;

use PcComponentes\Ddd\Domain\Model\ValueObject\DateTimeValueObject;
use PcComponentes\Ddd\Domain\Model\ValueObject\StringValueObject;
use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid;
use PcComponentes\Ddd\Util\Message\ValueObject\AggregateId;

Expand All @@ -30,35 +29,11 @@ final protected function __construct(

final public static function fromPayload(
Uuid $messageId,
StringValueObject $aggregateId,
AggregateId $aggregateId,
DateTimeValueObject $occurredOn,
array $payload,
int $aggregateVersion = 0
): self {
if (false === $aggregateId instanceof Uuid && false === $aggregateId instanceof AggregateId) {
throw new \InvalidArgumentException(\sprintf(
"AggregateId value should be an instance of %s, %s given",
AggregateId::class,
\get_class($aggregateId),
));
}

if ($aggregateId instanceof Uuid) {
$aggregateId = AggregateId::from($aggregateId->value());

if (\function_exists('trigger_deprecation')) {
@\trigger_deprecation(
'pccomponentes/ddd',
'3.0',
\sprintf(
"AggregateId value should be an instance of %s, %s given",
AggregateId::class,
\get_class($aggregateId),
),
);
}
}

$message = new static($messageId, $aggregateId, $aggregateVersion, $occurredOn, $payload);
$message->assertPayload();

Expand Down
3 changes: 2 additions & 1 deletion tests/Domain/Model/SimpleAggregateRootTested.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PcComponentes\Ddd\Domain\Model\SimpleAggregateRoot;
use PcComponentes\Ddd\Domain\Model\ValueObject\DateTimeValueObject;
use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid;
use PcComponentes\Ddd\Util\Message\ValueObject\AggregateId;

final class SimpleAggregateRootTested extends SimpleAggregateRoot
{
Expand All @@ -15,7 +16,7 @@ public static function test(Uuid $aggregateId): self
$self->recordThat(
DomainEventTested::fromPayload(
Uuid::v4(),
$aggregateId,
AggregateId::from($aggregateId->value()),
DateTimeValueObject::now(),
[]
)
Expand Down
3 changes: 2 additions & 1 deletion tests/Util/Message/AggregatemessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use PcComponentes\Ddd\Domain\Model\ValueObject\DateTimeValueObject;
use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid;
use PcComponentes\Ddd\Util\Message\ValueObject\AggregateId;
use PHPUnit\Framework\TestCase;

class AggregatemessageTest extends TestCase
Expand All @@ -16,7 +17,7 @@ public function given_message_when_ask_to_serialize_then_return_expected_info()
{
AggregateMessageTested::set('example', 'v1', 'tested');
$messageId = Uuid::from('212e0a16-ae32-4c80-a6e4-26577f4cf7c7');
$aggregateId = Uuid::from('bdb507b6-838b-46ff-9aeb-53ab8ac01e33');
$aggregateId = AggregateId::from('bdb507b6-838b-46ff-9aeb-53ab8ac01e33');
$occurredOn = DateTimeValueObject::from('2018-01-01 01:01:01');
$aggregateVersion = 0;
$payload = [
Expand Down

0 comments on commit 544f5fc

Please sign in to comment.