Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Jul 16, 2017
1 parent 6b89312 commit c4c0d14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
48 changes: 24 additions & 24 deletions tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use PHPUnit\Framework\TestCase;
use Phunkie\Types\ImmList;
use Phunkie\Types\Nil;
use Phunkie\Validation\Failure;
use Prooph\Common\Messaging\Message;
use Prooph\EventStore\EventStore;
Expand All @@ -29,6 +28,7 @@
use Prooph\SnapshotStore\SnapshotStore;
use ProophTest\Micro\TestAsset\OneStreamPerAggregateTestAggregateDefinition;
use ProophTest\Micro\TestAsset\SingleStreamTestAggregateDefinition;
use ProophTest\Micro\TestAsset\TestDomainEvent;
use Prophecy\Argument;

class KernelTest extends TestCase
Expand All @@ -41,7 +41,9 @@ public function it_builds_command_dispatcher_and_dispatches(): void
$commandMap = [
'some_command' => [
'handler' => function (callable $stateResolver, Message $message): array {
return $stateResolver();
$stateResolver();

return [new TestDomainEvent(['foo' => 'bar'])];
},
'definition' => SingleStreamTestAggregateDefinition::class,
],
Expand All @@ -52,7 +54,7 @@ public function it_builds_command_dispatcher_and_dispatches(): void
$eventStore->load(Argument::type(StreamName::class), 1, null, null)->willReturn(new \ArrayIterator())->shouldBeCalled();
$eventStore->appendTo(Argument::type(StreamName::class), Argument::type(\Iterator::class))->shouldBeCalled();

$dispatch = \Prooph\Micro\Kernel\buildCommandDispatcher($eventStore->reveal())(new InMemorySnapshotStore())($commandMap);
$dispatch = \Prooph\Micro\Kernel\buildCommandDispatcher($eventStore->reveal(), $commandMap, new InMemorySnapshotStore());

$command = $this->prophesize(Message::class);
$command->messageName()->willReturn('some_command')->shouldBeCalled();
Expand All @@ -72,7 +74,7 @@ public function it_does_not_load_events_when_state_is_not_resolved(): void
$commandMap = [
'some_command' => [
'handler' => function (callable $stateResolver, Message $message): array {
return [];
return [new TestDomainEvent(['foo' => 'bar'])];
},
'definition' => SingleStreamTestAggregateDefinition::class,
],
Expand All @@ -83,7 +85,7 @@ public function it_does_not_load_events_when_state_is_not_resolved(): void
$eventStore->load(Argument::type(StreamName::class), 1, null, null)->willReturn(new \ArrayIterator())->shouldNotBeCalled();
$eventStore->appendTo(Argument::type(StreamName::class), Argument::type(\Iterator::class))->shouldBeCalled();

$dispatch = \Prooph\Micro\Kernel\buildCommandDispatcher($eventStore->reveal())(new InMemorySnapshotStore())($commandMap);
$dispatch = \Prooph\Micro\Kernel\buildCommandDispatcher($eventStore->reveal(), $commandMap, new InMemorySnapshotStore());

$command = $this->prophesize(Message::class);
$command->messageName()->willReturn('some_command')->shouldBeCalled();
Expand All @@ -109,7 +111,7 @@ public function it_loads_state_from_empty_snapshot_store(): void
$definition->aggregateType()->willReturn('test')->shouldBeCalled();
$definition->extractAggregateId($message)->willReturn('42')->shouldBeCalled();

$result = k\loadState($snapshotStore->reveal())($definition->reveal())($message);
$result = k\loadState($message, $definition->reveal(), $snapshotStore->reveal());

$this->assertInternalType('array', $result);
$this->assertEmpty($result);
Expand All @@ -136,7 +138,7 @@ public function it_loads_state_from_snapshot_store(): void
$definition->aggregateType()->willReturn('test')->shouldBeCalled();
$definition->extractAggregateId($message)->willReturn('42')->shouldBeCalled();

$result = k\loadState($snapshotStore)($definition->reveal())($message);
$result = k\loadState($message, $definition->reveal(), $snapshotStore);
$this->assertEquals(['foo' => 'bar'], $result);
}

Expand All @@ -148,9 +150,9 @@ public function it_loads_events_when_stream_not_found(): void
$eventStore = $this->prophesize(EventStore::class);
$eventStore->hasStream(new StreamName('foo'))->willReturn(false)->shouldBeCalled();

$result = k\loadEvents($eventStore->reveal())(new SingleStreamTestAggregateDefinition())('foo')(1);
$result = k\loadEvents($eventStore->reveal(), new SingleStreamTestAggregateDefinition(), 'foo', 1);

$this->assertInstanceOf(Nil::class, $result);
$this->assertInstanceOf(\EmptyIterator::class, $result);
}

/**
Expand All @@ -163,10 +165,9 @@ public function it_loads_events_when_stream_found(): void
$eventStore->hasStream($streamName)->willReturn(true)->shouldBeCalled();
$eventStore->load($streamName, 1, null, null)->willReturn(new \ArrayIterator())->shouldBeCalled();

$result = k\loadEvents($eventStore->reveal())(new SingleStreamTestAggregateDefinition())('foo')(1);
$result = k\loadEvents($eventStore->reveal(), new SingleStreamTestAggregateDefinition(), 'foo', 1);

$this->assertInstanceOf(ImmList::class, $result);
$this->assertTrue($result->isEmpty());
$this->assertInstanceOf(\ArrayIterator::class, $result);
}

/**
Expand All @@ -178,10 +179,9 @@ public function it_loads_events_when_stream_found_using_one_stream_per_aggregate
$eventStore->hasStream(Argument::type(StreamName::class))->willReturn(true)->shouldBeCalled();
$eventStore->load(Argument::type(StreamName::class), 1, null, null)->willReturn(new \ArrayIterator())->shouldBeCalled();

$result = k\loadEvents($eventStore->reveal())(new OneStreamPerAggregateTestAggregateDefinition())('foo')(1);
$result = k\loadEvents($eventStore->reveal(), new OneStreamPerAggregateTestAggregateDefinition(), 'foo', 1);

$this->assertInstanceOf(ImmList::class, $result);
$this->assertTrue($result->isEmpty());
$this->assertInstanceOf(\ArrayIterator::class, $result);
}

/**
Expand All @@ -201,7 +201,7 @@ public function it_appends_to_stream_during_persist_when_stream_found(): void
$aggregateDefinition->streamName()->willReturn(new StreamName('foo'))->shouldBeCalled();
$aggregateDefinition->hasOneStreamPerAggregate()->willReturn(false)->shouldBeCalled();

$validation = k\persistEvents($eventStore->reveal())($aggregateDefinition->reveal())('some_id')(ImmList(...$raisedEvents));
$validation = k\persistEvents(ImmList(...$raisedEvents), $eventStore->reveal(), $aggregateDefinition->reveal(), 'some_id');

if ($validation instanceof Failure) {
$this->fail($validation->toString());
Expand All @@ -220,7 +220,7 @@ public function it_persist_transactional_when_using_transactional_event_store():
$aggregateDefinition->streamName()->willReturn(new StreamName('foo'))->shouldBeCalled();
$aggregateDefinition->hasOneStreamPerAggregate()->willReturn(false)->shouldBeCalled();

$validation = k\persistEvents(new InMemoryEventStore())($aggregateDefinition->reveal())('some_id')(ImmList(...$raisedEvents));
$validation = k\persistEvents(ImmList(...$raisedEvents), new InMemoryEventStore(), $aggregateDefinition->reveal(), 'some_id');

if ($validation instanceof Failure) {
$this->fail($validation->toString());
Expand Down Expand Up @@ -252,8 +252,8 @@ public function it_rolls_back_transaction_during_persist_when_using_transactiona
$aggregateDefinition->streamName()->willReturn(new StreamName('foo'))->shouldBeCalled();
$aggregateDefinition->hasOneStreamPerAggregate()->willReturn(true)->shouldBeCalled();

k\persistEvents($eventStore)($aggregateDefinition->reveal())('one')(ImmList(...$raisedEvents));
k\persistEvents($eventStore)($aggregateDefinition->reveal())('one')(ImmList(...$raisedEvents));
k\persistEvents(ImmList(...$raisedEvents), $eventStore, $aggregateDefinition->reveal(), 'one');
k\persistEvents(ImmList(...$raisedEvents), $eventStore, $aggregateDefinition->reveal(), 'one');
}

/**
Expand All @@ -272,7 +272,7 @@ public function it_appends_to_stream_during_persist_when_stream_found_using_one_
$aggregateDefinition->streamName()->willReturn(new StreamName('foo'))->shouldBeCalled();
$aggregateDefinition->hasOneStreamPerAggregate()->willReturn(true)->shouldBeCalled();

$validation = k\persistEvents($eventStore->reveal())($aggregateDefinition->reveal())('some_id')(ImmList(...$raisedEvents));
$validation = k\persistEvents(ImmList(...$raisedEvents), $eventStore->reveal(), $aggregateDefinition->reveal(), 'some_id');

if ($validation instanceof Failure) {
$this->fail($validation->toString());
Expand All @@ -297,7 +297,7 @@ public function it_creates_stream_during_persist_when_no_stream_found_and_enrich
$aggregateDefinition->streamName()->willReturn($streamName)->shouldBeCalled();
$aggregateDefinition->hasOneStreamPerAggregate()->willReturn(false)->shouldBeCalled();

$validation = k\persistEvents($eventStore->reveal())($aggregateDefinition->reveal())('some_id')(ImmList($message->reveal()));
$validation = k\persistEvents(ImmList($message), $eventStore->reveal(), $aggregateDefinition->reveal(), 'some_id');

if ($validation instanceof Failure) {
$this->fail($validation->toString());
Expand All @@ -320,7 +320,7 @@ public function it_gets_handler(): void
],
];

$result = k\getHandler($commandMap)($message->reveal());
$result = k\getHandler($message->reveal(), $commandMap);

$this->assertInstanceOf(\Closure::class, $result);
}
Expand All @@ -338,7 +338,7 @@ public function it_throws_exception_when_no_handler_found(): void
$commandMap = ['foo' => ['handler' => function (): void {
}]];

k\getHandler($commandMap)($message->reveal());
k\getHandler($message->reveal(), $commandMap);
}

/**
Expand All @@ -353,6 +353,6 @@ public function it_throws_exception_when_no_definition_found(): void

$commandMap = [];

k\getAggregateDefinition($commandMap)($message->reveal());
k\getAggregateDefinition($message->reveal(), $commandMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function streamName(): StreamName
return new StreamName('foo');
}

public function metadataEnricher(string $aggregateId, int $aggregateVersion): ?MetadataEnricher
public function metadataEnricher(string $aggregateId, int $aggregateVersion, Message $causation = null): ?MetadataEnricher
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestAsset/SingleStreamTestAggregateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function streamName(): StreamName
return new StreamName('foo');
}

public function metadataEnricher(string $aggregateId, int $aggregateVersion): ?MetadataEnricher
public function metadataEnricher(string $aggregateId, int $aggregateVersion, Message $causation = null): ?MetadataEnricher
{
return null;
}
Expand Down

0 comments on commit c4c0d14

Please sign in to comment.