Skip to content

Commit

Permalink
Fixes #34: Change initialization sequence
Browse files Browse the repository at this point in the history
- Added a test to verify the bug and its fix
  • Loading branch information
codeliner committed Dec 11, 2014
1 parent 2d6ef6f commit 948525d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function __construct(EventStore $eventStore, AggregateType $superclass, a
{
$this->eventStore = $eventStore;

$this->streamName = $this->buildStreamName($superclass);

$this->aggregateTypeStreamMap = $aggregateTypeStreamMap;

$this->streamName = $this->buildStreamName($superclass);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,57 @@ public function it_reads_stream_events_for_aggregate_and_silently_changes_aggreg

$this->assertEquals('Employee', $aggregateType->toString());
}

/**
* @test
*/
public function it_uses_the_aggregate_type_map_to_write_to_a_global_stream()
{
$personType = new AggregateType('Person');

$strategyWithAggregateMap = new MappedSuperclassStreamStrategy(
$this->eventStore,
$personType, [
$personType->toString() => 'global_event_stream'
]
);

$this->eventStore->beginTransaction();

$this->eventStore->create(new Stream(new StreamName('global_event_stream'), array()));

$this->eventStore->commit();

$this->eventStore->beginTransaction();

$employeeType = new AggregateType('Employee');

$aggregateId1 = Uuid::uuid4()->toString();

$streamEvents1 = array(
new StreamEvent(
EventId::generate(),
new EventName('EmployeeHired'),
array('user_id' => $aggregateId1),
1,
new \DateTime()
)
);

$strategyWithAggregateMap->add($employeeType, $aggregateId1, $streamEvents1);

$this->eventStore->commit();

$streamEvents = $strategyWithAggregateMap->read($personType, $aggregateId1);

$this->assertEquals(1, count($streamEvents));

$this->assertInstanceOf('Prooph\EventStore\Stream\StreamEvent', $streamEvents[0]);

$this->assertEquals($aggregateId1, $streamEvents[0]->payload()['user_id']);

//Person became Employee after reading the stream
$this->assertEquals('Employee', $personType->toString());
}
}

0 comments on commit 948525d

Please sign in to comment.