/** * @param AggregateRoot $aggregateRoot * @test * @dataProvider aggregateRootProvider */ public function itShouldTakeASnapshot(AggregateRoot $aggregateRoot) { $stream = $aggregateRoot->getEventStream(); $this->setUpForEventStream($stream); $snapshotStore = $this->prophesize(SnapshotStoreInterface::class); $stream->each(function (DomainMessage $domainMessage) use($snapshotStore, $aggregateRoot) { $snapshotStore->has($aggregateRoot->getAggregateRootId(), $domainMessage->getVersion())->shouldBeCalled()->willReturn(false); $snapshotStore->save(Argument::type(Snapshot::class))->shouldBeCalled(); }); $strategy = $this->prophesize(SnapshotStrategyInterface::class); $strategy->isFulfilled(new StreamName('event_stream'), $aggregateRoot)->shouldBeCalled()->willReturn(true); $snapshotter = new Snapshotter($snapshotStore->reveal(), $strategy->reveal()); $repo = new AggregateRepository($this->eventStore->reveal(), $this->eventBus->reveal(), $snapshotter); $repo->save($aggregateRoot); }