From 05cf3bb29b53f124584b546e47787c0048c7ddfa Mon Sep 17 00:00:00 2001 From: David Badura Date: Mon, 20 Dec 2021 11:25:02 +0100 Subject: [PATCH 1/2] add recorded clock trait --- src/Aggregate/ClockRecordDate.php | 17 +++++++++ .../AggregateChangedWithClockTest.php | 29 +++++++++++++++ .../Unit/Fixture/ProfileVisitedWithClock.php | 36 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 src/Aggregate/ClockRecordDate.php create mode 100644 tests/Unit/Aggregate/AggregateChangedWithClockTest.php create mode 100644 tests/Unit/Fixture/ProfileVisitedWithClock.php diff --git a/src/Aggregate/ClockRecordDate.php b/src/Aggregate/ClockRecordDate.php new file mode 100644 index 00000000..85cdb14e --- /dev/null +++ b/src/Aggregate/ClockRecordDate.php @@ -0,0 +1,17 @@ +recordNow(1); + + self::assertSame($date, $event->recordedOn()); + } +} diff --git a/tests/Unit/Fixture/ProfileVisitedWithClock.php b/tests/Unit/Fixture/ProfileVisitedWithClock.php new file mode 100644 index 00000000..48415457 --- /dev/null +++ b/tests/Unit/Fixture/ProfileVisitedWithClock.php @@ -0,0 +1,36 @@ + + */ +final class ProfileVisitedWithClock extends AggregateChanged +{ + use ClockRecordDate; + + public static function raise(ProfileId $visitedId, ProfileId $visitorId): self + { + return new self( + $visitedId->toString(), + [ + 'visitorId' => $visitorId->toString(), + ] + ); + } + + public function visitedId(): ProfileId + { + return ProfileId::fromString($this->aggregateId); + } + + public function visitorId(): ProfileId + { + return ProfileId::fromString($this->payload['visitorId']); + } +} From 4ede68978b6eac699b5e02e60a56515f5b743b44 Mon Sep 17 00:00:00 2001 From: David Badura Date: Mon, 20 Dec 2021 11:32:36 +0100 Subject: [PATCH 2/2] fix pipeline --- src/Aggregate/ClockRecordDate.php | 4 +++- tests/Unit/Aggregate/AggregateChangedWithClockTest.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Aggregate/ClockRecordDate.php b/src/Aggregate/ClockRecordDate.php index 85cdb14e..507ae289 100644 --- a/src/Aggregate/ClockRecordDate.php +++ b/src/Aggregate/ClockRecordDate.php @@ -1,5 +1,7 @@ recordNow(1); + $recordedEvent = $event->recordNow(1); - self::assertSame($date, $event->recordedOn()); + self::assertSame($date, $recordedEvent->recordedOn()); } }