From fda54df3e470b9d33b38faeaffaebd38687b0497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20de=20Kat?= Date: Sat, 16 Dec 2017 10:26:26 +0000 Subject: [PATCH] Bugfixes in EventSourcing/Testing/Scenario, examples (#344) * Fixed missing return types required in strict mode. Fixed bug in Scenario->getEvents method: array_map only accepts an array and not an iterator. Using iterator_to_array() now. * Fixed incompatibile child classes. Added examples to test suite --- examples/event-sourced-child-entity/Parts.php | 4 ++-- examples/event-sourced-child-entity/PartsTest.php | 4 +++- .../InvitationCommandHandlerTest.php | 4 +++- examples/event-sourced-domain-with-tests/Invites.php | 2 +- examples/event-sourced-domain-with-tests/InvitesTest.php | 4 ++-- .../JobSeekers.php | 4 ++-- .../JobSeekersTest.php | 4 +++- phpunit.xml.dist | 3 +++ src/Broadway/EventSourcing/Testing/Scenario.php | 2 +- 9 files changed, 20 insertions(+), 11 deletions(-) diff --git a/examples/event-sourced-child-entity/Parts.php b/examples/event-sourced-child-entity/Parts.php index aa5004da..70b432e5 100644 --- a/examples/event-sourced-child-entity/Parts.php +++ b/examples/event-sourced-child-entity/Parts.php @@ -30,7 +30,7 @@ public static function manufacture($partId, $manufacturerId, $manufacturerName) * * @return string */ - public function getAggregateRootId() + public function getAggregateRootId(): string { return $this->partId; } @@ -55,7 +55,7 @@ public function applyPartWasManufacturedEvent(PartWasManufacturedEvent $event) ); } - protected function getChildEntities() + protected function getChildEntities(): array { // Since the aggregate root always handles the events first we can rely // on $this->manufacturer being set by the time the child entities are diff --git a/examples/event-sourced-child-entity/PartsTest.php b/examples/event-sourced-child-entity/PartsTest.php index b4cfa291..24e297d8 100644 --- a/examples/event-sourced-child-entity/PartsTest.php +++ b/examples/event-sourced-child-entity/PartsTest.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Broadway\CommandHandling\CommandHandler; + require_once __DIR__.'/Parts.php'; /** @@ -24,7 +26,7 @@ public function setUp() $this->generator = new Broadway\UuidGenerator\Rfc4122\Version4Generator(); } - protected function createCommandHandler(Broadway\EventStore\EventStore $eventStore, Broadway\EventHandling\EventBus $eventBus) + protected function createCommandHandler(Broadway\EventStore\EventStore $eventStore, Broadway\EventHandling\EventBus $eventBus): CommandHandler { $repository = new PartRepository($eventStore, $eventBus); diff --git a/examples/event-sourced-domain-with-tests/InvitationCommandHandlerTest.php b/examples/event-sourced-domain-with-tests/InvitationCommandHandlerTest.php index 4a638985..6714930e 100644 --- a/examples/event-sourced-domain-with-tests/InvitationCommandHandlerTest.php +++ b/examples/event-sourced-domain-with-tests/InvitationCommandHandlerTest.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Broadway\CommandHandling\CommandHandler; + require_once __DIR__.'/Invites.php'; /** @@ -24,7 +26,7 @@ public function setUp() $this->generator = new Broadway\UuidGenerator\Rfc4122\Version4Generator(); } - protected function createCommandHandler(Broadway\EventStore\EventStore $eventStore, Broadway\EventHandling\EventBus $eventBus) + protected function createCommandHandler(Broadway\EventStore\EventStore $eventStore, Broadway\EventHandling\EventBus $eventBus): CommandHandler { $repository = new InvitationRepository($eventStore, $eventBus); diff --git a/examples/event-sourced-domain-with-tests/Invites.php b/examples/event-sourced-domain-with-tests/Invites.php index 9763cbca..d45ac6e0 100644 --- a/examples/event-sourced-domain-with-tests/Invites.php +++ b/examples/event-sourced-domain-with-tests/Invites.php @@ -34,7 +34,7 @@ public static function invite($invitationId, $name) * * {@inheritdoc} */ - public function getAggregateRootId() + public function getAggregateRootId(): string { return $this->invitationId; } diff --git a/examples/event-sourced-domain-with-tests/InvitesTest.php b/examples/event-sourced-domain-with-tests/InvitesTest.php index 9095cd6c..7183e677 100644 --- a/examples/event-sourced-domain-with-tests/InvitesTest.php +++ b/examples/event-sourced-domain-with-tests/InvitesTest.php @@ -13,7 +13,7 @@ * - Third, the outcome is asserted. This can either be 1) some events are * recorded, or 2) an exception is thrown. */ -class InvitationTest extends Broadway\EventSourcing\Testing\AggregateRootScenarioTestCase +class InvitesTest extends Broadway\EventSourcing\Testing\AggregateRootScenarioTestCase { private $generator; @@ -23,7 +23,7 @@ public function setUp() $this->generator = new Broadway\UuidGenerator\Rfc4122\Version4Generator(); } - protected function getAggregateRootClass() + protected function getAggregateRootClass(): string { return Invitation::class; } diff --git a/examples/event-sourced-multiple-dyanmic-child-entities/JobSeekers.php b/examples/event-sourced-multiple-dyanmic-child-entities/JobSeekers.php index a8ac4dfc..2835a380 100644 --- a/examples/event-sourced-multiple-dyanmic-child-entities/JobSeekers.php +++ b/examples/event-sourced-multiple-dyanmic-child-entities/JobSeekers.php @@ -30,7 +30,7 @@ public static function startLookingForWork($jobSeekerId) * * @return string */ - public function getAggregateRootId() + public function getAggregateRootId(): string { return $this->jobSeekerId; } @@ -77,7 +77,7 @@ public function applyAccidentallyAddedJobWasRemovedFromJobSeekerEvent( unset($this->jobs[$event->jobId]); } - protected function getChildEntities() + protected function getChildEntities(): array { return $this->jobs; } diff --git a/examples/event-sourced-multiple-dyanmic-child-entities/JobSeekersTest.php b/examples/event-sourced-multiple-dyanmic-child-entities/JobSeekersTest.php index 43548a3e..d1006aee 100644 --- a/examples/event-sourced-multiple-dyanmic-child-entities/JobSeekersTest.php +++ b/examples/event-sourced-multiple-dyanmic-child-entities/JobSeekersTest.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Broadway\CommandHandling\CommandHandler; + require_once __DIR__.'/JobSeekers.php'; /** @@ -24,7 +26,7 @@ public function setUp() $this->generator = new Broadway\UuidGenerator\Rfc4122\Version4Generator(); } - protected function createCommandHandler(Broadway\EventStore\EventStore $eventStore, Broadway\EventHandling\EventBus $eventBus) + protected function createCommandHandler(Broadway\EventStore\EventStore $eventStore, Broadway\EventHandling\EventBus $eventBus): CommandHandler { $repository = new JobSeekerRepository($eventStore, $eventBus); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index af9c8ab8..86b1cd8a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,6 +15,9 @@ ./test/ + + ./examples/ + diff --git a/src/Broadway/EventSourcing/Testing/Scenario.php b/src/Broadway/EventSourcing/Testing/Scenario.php index bf5fc60b..282c66eb 100644 --- a/src/Broadway/EventSourcing/Testing/Scenario.php +++ b/src/Broadway/EventSourcing/Testing/Scenario.php @@ -131,6 +131,6 @@ private function getEvents(): array { return array_map(function (DomainMessage $message) { return $message->getPayload(); - }, $this->aggregateRootInstance->getUncommittedEvents()); + }, iterator_to_array($this->aggregateRootInstance->getUncommittedEvents())); } }