Skip to content

Commit

Permalink
Bugfixes in EventSourcing/Testing/Scenario, examples (#344)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
renedekat authored and othillo committed Dec 16, 2017
1 parent 1039c00 commit fda54df
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/event-sourced-child-entity/Parts.php
Expand Up @@ -30,7 +30,7 @@ public static function manufacture($partId, $manufacturerId, $manufacturerName)
*
* @return string
*/
public function getAggregateRootId()
public function getAggregateRootId(): string
{
return $this->partId;
}
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion examples/event-sourced-child-entity/PartsTest.php
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use Broadway\CommandHandling\CommandHandler;

require_once __DIR__.'/Parts.php';

/**
Expand All @@ -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);

Expand Down
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use Broadway\CommandHandling\CommandHandler;

require_once __DIR__.'/Invites.php';

/**
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion examples/event-sourced-domain-with-tests/Invites.php
Expand Up @@ -34,7 +34,7 @@ public static function invite($invitationId, $name)
*
* {@inheritdoc}
*/
public function getAggregateRootId()
public function getAggregateRootId(): string
{
return $this->invitationId;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/event-sourced-domain-with-tests/InvitesTest.php
Expand Up @@ -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;

Expand All @@ -23,7 +23,7 @@ public function setUp()
$this->generator = new Broadway\UuidGenerator\Rfc4122\Version4Generator();
}

protected function getAggregateRootClass()
protected function getAggregateRootClass(): string
{
return Invitation::class;
}
Expand Down
Expand Up @@ -30,7 +30,7 @@ public static function startLookingForWork($jobSeekerId)
*
* @return string
*/
public function getAggregateRootId()
public function getAggregateRootId(): string
{
return $this->jobSeekerId;
}
Expand Down Expand Up @@ -77,7 +77,7 @@ public function applyAccidentallyAddedJobWasRemovedFromJobSeekerEvent(
unset($this->jobs[$event->jobId]);
}

protected function getChildEntities()
protected function getChildEntities(): array
{
return $this->jobs;
}
Expand Down
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use Broadway\CommandHandling\CommandHandler;

require_once __DIR__.'/JobSeekers.php';

/**
Expand All @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Expand Up @@ -15,6 +15,9 @@
<testsuite name="Broadway Test Suite">
<directory>./test/</directory>
</testsuite>
<testsuite name="Broadway Example Test Suite">
<directory>./examples/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
Expand Down
2 changes: 1 addition & 1 deletion src/Broadway/EventSourcing/Testing/Scenario.php
Expand Up @@ -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()));
}
}

0 comments on commit fda54df

Please sign in to comment.