/** * @test * @expectedException \SimpleES\EventSourcing\Exception\IdNotMappedToAggregate */ public function itCannotReconstituteAnAggregateWhenMapNotFound() { $factory = new MappingAggregateFactory([]); $id = BasketId::fromString('some-id'); $aggregateHistory = $this->testHelper->getAggregateHistory($id); $factory->reconstituteFromHistory($aggregateHistory); }
/** * @test */ public function itResolvesEventNames() { $basketId = BasketId::fromString('some-basket'); $productId = ProductId::fromString('some-product'); $this->assertSame('basket_was_picked_up', $this->eventNameResolver->resolveEventName(new BasketWasPickedUp($basketId))); $this->assertSame('product_was_added_to_basket', $this->eventNameResolver->resolveEventName(new ProductWasAddedToBasket($basketId, $productId))); $this->assertSame('product_was_removed_from_basket', $this->eventNameResolver->resolveEventName(new ProductWasRemovedFromBasket($basketId, $productId))); }
/** * @test */ public function itResolvesEventNames() { $basketId = BasketId::fromString('some-basket'); $productId = ProductId::fromString('some-product'); $this->assertSame('SimpleES\\EventSourcing\\Example\\Basket\\Events\\BasketWasPickedUp', $this->eventNameResolver->resolveEventName(new BasketWasPickedUp($basketId))); $this->assertSame('SimpleES\\EventSourcing\\Example\\Basket\\Events\\ProductWasAddedToBasket', $this->eventNameResolver->resolveEventName(new ProductWasAddedToBasket($basketId, $productId))); $this->assertSame('SimpleES\\EventSourcing\\Example\\Basket\\Events\\ProductWasRemovedFromBasket', $this->eventNameResolver->resolveEventName(new ProductWasRemovedFromBasket($basketId, $productId))); }
/** * @test */ public function itSimplyProxiesGettingEventsToTheNextEventStore() { $id = BasketId::fromString('some-id'); $eventStream = $this->testHelper->getEventStream($id); $this->nextEventStore->expects($this->once())->method('read')->with($this->equalTo($id))->will($this->returnValue($eventStream)); $returnedEnvelopeStream = $this->eventStore->read($id); $this->assertSame($eventStream, $returnedEnvelopeStream); }
/** * @test */ public function itEnrichesMetadataWithARondomString() { $id = BasketId::fromString('some-id'); $envelope = $this->testHelper->getEventStreamEnvelopeOne($id); $enricher = new EnrichesMetadataWithARandomString(); $enrichedEnvelope = $enricher->enrich($envelope); $metadata = $enrichedEnvelope->metadata(); $this->assertArrayHasKey('random_string', $metadata); $this->assertInternalType('string', $metadata['random_string']); }
/** * @test */ public function itExposesAnAggregateId() { $id = BasketId::fromString('some-id'); $exposedId = $this->envelope->aggregateId(); $this->assertTrue($id->equals($exposedId)); }
/** * @test * @expectedException \SimpleES\EventSourcing\Exception\AggregateIdNotFound */ public function itCanBeCleared() { $id = BasketId::fromString('some-id'); $this->identityMap->clear(); $this->identityMap->get($id); }
/** * @test * @expectedException \SimpleES\EventSourcing\Exception\CollectionIsEmpty */ public function itCannotBeEmpty() { $id = BasketId::fromString('some-id'); new AggregateHistory($id, []); }
/** * @test */ public function itMaintainsConsecutivePlayheadAfterUnwrapping() { $id = BasketId::fromString('some-id'); $domainEvents = $this->testHelper->getDomainEvents($id); $eventStream = $this->testHelper->getEventStream($id); $this->eventWrapper->unwrap($eventStream); $newEnvelopeStream = $this->eventWrapper->wrap($id, $domainEvents); /** @var EnvelopsEvent[] $envelopes */ $envelopes = iterator_to_array($newEnvelopeStream); $this->assertSame(3, $envelopes[0]->aggregateVersion()); $this->assertSame(4, $envelopes[1]->aggregateVersion()); $this->assertSame(5, $envelopes[2]->aggregateVersion()); }
/** * @test */ public function itExposesItsBasketId() { $basketId = BasketId::fromString('basket-1'); $this->assertTrue($basketId->equals($this->event->basketId())); }
public function setUp() { $this->testHelper = new TestHelper($this); $id = BasketId::fromString('some-id'); $this->domainEvents = new DomainEvents([$this->testHelper->getDomainEventsEventOne($id), $this->testHelper->getDomainEventsEventTwo($id), $this->testHelper->getDomainEventsEventThree($id)]); }
/** * @test */ public function itReconstitutesAnAggregateFromHistoryRetrievedFromTheEventStore() { $id = BasketId::fromString('some-basket'); $eventStream = $this->testHelper->getEventStream($id); $aggregateHistory = $this->testHelper->getAggregateHistory($id); $aggregate = Basket::pickUp($id); $this->eventStore->expects($this->once())->method('read')->with($this->equalTo($id))->will($this->returnValue($eventStream)); $this->eventWrapper->expects($this->once())->method('unwrap')->with($this->equalTo($eventStream))->will($this->returnValue($aggregateHistory)); $this->aggregateFactory->expects($this->once())->method('reconstituteFromHistory')->with($this->equalTo($aggregateHistory))->will($this->returnValue($aggregate)); $foundAggregate = $this->repository->get($id); $this->assertSame($aggregate, $foundAggregate); }
/** * @test * @expectedException \SimpleES\EventSourcing\Exception\AggregateIdNotFound */ public function itFailsWhenAnAggregateIdIsNotFound() { $id = BasketId::fromString('id-3'); $this->eventStore->read($id); }
/** * @test */ public function itExposesItsAggregateId() { $basketId = BasketId::fromString('basket-1'); $exposedAggregateId = $this->basket->aggregateId(); $this->assertTrue($basketId->equals($exposedAggregateId)); }
/** * @test */ public function itGetsTheAggregateFromTheIdentityMapIfItIsInThere() { $id = BasketId::fromString('some-id'); $aggregate = $this->getMock('SimpleES\\EventSourcing\\Aggregate\\TracksEvents'); $aggregate->expects($this->any())->method('aggregateId')->will($this->returnValue($id)); $this->identityMap->expects($this->once())->method('contains')->with($id)->will($this->returnValue(true)); $this->identityMap->expects($this->once())->method('get')->with($id)->will($this->returnValue($aggregate)); $this->identityMap->expects($this->never())->method('add'); $this->repository->expects($this->never())->method('get'); $gotAggregate = $this->aggregateManager->get($id); $this->assertSame($aggregate, $gotAggregate); }
/** * @test */ public function itDoesNotEqualAnotherWithADifferentClass() { $other = BasketId::fromString('product-1'); $this->assertNotTrue($this->productId->equals($other)); }
/** * @test */ public function itDoesNotEqualAnotherWithADifferentValue() { $other = BasketId::fromString('basket-2'); $this->assertNotTrue($this->basketId->equals($other)); }
/** * @test * @expectedException \SimpleES\EventSourcing\Exception\CollectionIsEmpty */ public function itCannotBeEmpty() { $id = BasketId::fromString('some-id'); new EventStream($id, []); }