예제 #1
0
 function it_should_be_able_to_restore_to_a_previous_state_via_history()
 {
     $basketId = BasketId::generate();
     $aggregate = Basket::pickup($basketId);
     $committedEvents = new CommittedEvents($basketId, $aggregate->getChanges()->getEvents());
     $this::reconstituteFrom($committedEvents)->getIdentity()->shouldBe($basketId);
 }
 function it_should_be_able_to_reconstitute_aggregates()
 {
     $store = new InMemoryEventStore();
     $this->beConstructedWith($store);
     $basketId = BasketId::generate();
     $aggregate = Basket::pickup($basketId);
     // when
     $this->save($aggregate);
     $this->get($basketId)->getIdentity()->shouldBe($basketId);
 }
예제 #3
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Domain\Fixtures\Identity\BasketId;
use Domain\Fixtures\Identity\ProductId;
use Domain\Fixtures\Aggregates\Basket;
use Domain\Fixtures\Repository\BasketRepository;
use Domain\Eventing\InMemoryEventStore;
$basketId = BasketId::generate();
$basket = Basket::pickup($basketId);
$basket->addProduct(ProductId::generate());
// right now we already have registered an event on the aggregate called "basketWasPickedUp"
$eventStore = new InMemoryEventStore();
$repo = new BasketRepository($eventStore);
// the changes are saved into the store
$repo->save($basket);
// get the changes from the store and reconstitute the aggregatee
$reconstituted = $repo->get($basketId);
예제 #4
0
 public static function pickup(BasketId $basketId)
 {
     $basket = new Basket($basketId);
     $basket->recordThat(new BasketWasPickedUp($basketId));
     return $basket;
 }