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_add_events_in_memory() { $identity = BasketId::generate(); $event = new BasketWasPickedUp($identity); $stream = new UncommittedEvents($identity); $stream->append($event); $this->commit($stream); $this->getAggregateHistoryFor($identity)->first()->shouldbe($event); }
function it_should_be_able_to_find_the_first_and_last_event() { $basketId = BasketId::generate(); $firstEvent = new BasketWasPickedUp($basketId); $secondEvent = new ProductWasAdded($basketId, ProductId::generate()); $this->beConstructedWith($basketId, [$firstEvent, $secondEvent]); $this->first()->shouldBe($firstEvent); $this->last()->shouldBe($secondEvent); }
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);
function it_should_not_allow_appending_events_from_other_identities() { $event = new BasketWasPickedUp(BasketId::generate()); $this->shouldThrow('Domain\\Eventing\\Exception\\CorruptAggregateHistory')->during('append', [$event]); }