Skip to content

Commit

Permalink
Merge 4f0f3f5 into ac8ad7d
Browse files Browse the repository at this point in the history
  • Loading branch information
dilab committed Jun 30, 2020
2 parents ac8ad7d + 4f0f3f5 commit 63b87da
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Models/EloquentStoredEvent.php
Expand Up @@ -27,6 +27,7 @@ public function toStoredEvent(): StoredEvent
'id' => $this->id,
'event_properties' => $this->event_properties,
'aggregate_uuid' => $this->aggregate_uuid ?? '',
'aggregate_version' => $this->aggregate_version ?? 0,
'event_class' => $this->event_class,
'meta_data' => $this->meta_data,
'created_at' => $this->created_at,
Expand Down
4 changes: 4 additions & 0 deletions src/StoredEvent.php
Expand Up @@ -19,6 +19,8 @@ class StoredEvent implements Arrayable

public string $aggregate_uuid;

public string $aggregate_version;

public string $event_class;

public SchemalessAttributes $meta_data;
Expand All @@ -32,6 +34,7 @@ public function __construct(array $data)
$this->id = $data['id'] ?? null;
$this->event_properties = $data['event_properties'];
$this->aggregate_uuid = $data['aggregate_uuid'];
$this->aggregate_version = $data['aggregate_version'];
$this->event_class = self::getActualClassForEvent($data['event_class']);
$this->meta_data = $data['meta_data'];
$this->created_at = $data['created_at'];
Expand All @@ -54,6 +57,7 @@ public function toArray()
'id' => $this->id,
'event_properties' => $this->event_properties,
'aggregate_uuid' => $this->aggregate_uuid,
'aggregate_version' => $this->aggregate_version,
'event_class' => self::getEventClass($this->event_class),
'meta_data' => $this->meta_data instanceof Arrayable ? $this->meta_data->toArray() : (array) $this->meta_data,
'created_at' => $this->created_at,
Expand Down
14 changes: 14 additions & 0 deletions tests/Models/StoredEventTest.php
Expand Up @@ -91,6 +91,7 @@ public function it_can_handle_an_encoded_string_as_event_properties()
'id' => $eloquentEvent->id,
'event_properties' => json_encode($eloquentEvent->event_properties),
'aggregate_uuid' => $eloquentEvent->aggregate_uuid ?? '',
'aggregate_version' => $eloquentEvent->aggregate_version ?? 0,
'event_class' => $eloquentEvent->event_class,
'meta_data' => $eloquentEvent->meta_data,
'created_at' => $eloquentEvent->created_at,
Expand All @@ -112,6 +113,7 @@ public function it_encodes_the_event_properties_itself_when_its_an_array()
'id' => $eloquentEvent->id,
'event_properties' => $eloquentEvent->event_properties,
'aggregate_uuid' => $eloquentEvent->aggregate_uuid ?? '',
'aggregate_version' => $eloquentEvent->aggregate_version ?? 0,
'event_class' => $eloquentEvent->event_class,
'meta_data' => $eloquentEvent->meta_data,
'created_at' => $eloquentEvent->created_at,
Expand All @@ -120,6 +122,18 @@ public function it_encodes_the_event_properties_itself_when_its_an_array()
$this->assertEquals(MoneyAddedEvent::class, get_class($storedEvent->event));
}

/** @test **/
public function it_exposes_the_aggregate_version()
{
$this->fireEvents();

$eloquentEvent = EloquentStoredEvent::first();

$storedEvent = $eloquentEvent->toStoredEvent();

$this->assertEquals(0, $storedEvent->aggregate_version);
}

public function fireEvents(int $number = 1, string $className = MoneyAddedEvent::class)
{
foreach (range(1, $number) as $i) {
Expand Down

0 comments on commit 63b87da

Please sign in to comment.