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); }
<?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);