function it_should_be_able_to_discard_changes()
 {
     $this->getChanges()->shouldHaveCount(1);
     $this->addProduct(ProductId::generate());
     $this->getChanges()->shouldHaveCount(2);
     $this->clearChanges();
     $this->getChanges()->shouldHaveCount(0);
 }
 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);
 }
Beispiel #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);