Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align translator and decorator to fix replay bug #18

Merged
merged 1 commit into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/EventStoreIntegration/AggregateRootDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ public function fromHistory($arClass, \Iterator $aggregateChangedEvents)
* @param AggregateRoot $aggregateRoot
* @param Iterator $events
*/
public function applyStreamEvents(AggregateRoot $aggregateRoot, Iterator $events)
public function replayStreamEvents(AggregateRoot $aggregateRoot, Iterator $events)
{
foreach ($events as $event) {
$aggregateRoot->apply($event);
}
$aggregateRoot->replay($events);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/EventStoreIntegration/AggregateTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public function extractPendingStreamEvents($anEventSourcedAggregateRoot)
* @param object $anEventSourcedAggregateRoot
* @param Iterator $events
*/
public function applyStreamEvents($anEventSourcedAggregateRoot, Iterator $events)
public function replayStreamEvents($anEventSourcedAggregateRoot, Iterator $events)
{
$this->getAggregateRootDecorator()->applyStreamEvents($anEventSourcedAggregateRoot, $events);
$this->getAggregateRootDecorator()->replayStreamEvents($anEventSourcedAggregateRoot, $events);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/AggregateRootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public function it_applies_event_by_calling_appropriate_event_handler()
//In between would be the process of persisting recorded events to an event stream
//Only if this was successful the events can be applied to the aggregate root
//We skip the persistence process here and apply the events directly
$decorator->applyStreamEvents($user, new \ArrayIterator($recordedEvents));
$decorator->replayStreamEvents($user, new \ArrayIterator($recordedEvents));

$this->assertEquals('John', $user->name());

$user->changeName('Max');

$additionalRecordedEvents = $decorator->extractRecordedEvents($user);

$decorator->applyStreamEvents($user, new \ArrayIterator($additionalRecordedEvents));
$decorator->replayStreamEvents($user, new \ArrayIterator($additionalRecordedEvents));

$this->assertEquals('Max', $user->name());

Expand Down Expand Up @@ -89,13 +89,13 @@ public function it_reconstructs_itself_from_history()

$recordedEvents = $user->accessRecordedEvents();

AggregateRootDecorator::newInstance()->applyStreamEvents($user, new \ArrayIterator($recordedEvents));
AggregateRootDecorator::newInstance()->replayStreamEvents($user, new \ArrayIterator($recordedEvents));

$user->changeName('Max');

$additionalRecordedEvents = $user->accessRecordedEvents();

AggregateRootDecorator::newInstance()->applyStreamEvents($user, new \ArrayIterator($additionalRecordedEvents));
AggregateRootDecorator::newInstance()->replayStreamEvents($user, new \ArrayIterator($additionalRecordedEvents));

$historyEvents = new \ArrayIterator(array_merge($recordedEvents, $additionalRecordedEvents));

Expand Down
2 changes: 1 addition & 1 deletion tests/EventStoreIntegration/AggregateTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function it_applies_stream_events(User $loadedUser)
$newName = 'Jane Doe';

$translator = new AggregateTranslator();
$translator->applyStreamEvents($loadedUser, new \ArrayIterator([UserNameChanged::occur($loadedUser->id(), [
$translator->replayStreamEvents($loadedUser, new \ArrayIterator([UserNameChanged::occur($loadedUser->id(), [
'username' => $newName
])]));

Expand Down