/** * @param AggregateRoot $aggregateRoot * @test * @dataProvider aggregateRootProvider */ public function itShouldLoadFromSnapshot(AggregateRoot $aggregateRoot) { $stream = $aggregateRoot->getEventStream(); $this->eventStore = $this->prophesize(EventStoreInterface::class); $this->eventBus = $this->prophesize(EventBusInterface::class); $version = 100; $snapshot = $this->prophesize(Snapshot::class); $snapshot->getVersion()->shouldBeCalled()->willReturn($version); $snapshot->getAggregate()->shouldBeCalled()->willReturn($aggregateRoot); $snapshotStore = $this->prophesize(SnapshotStoreInterface::class); $snapshotStore->byId($aggregateRoot->getAggregateRootId())->shouldBeCalled()->willReturn($snapshot); $strategy = $this->prophesize(SnapshotStrategyInterface::class); $snapshotter = new Snapshotter($snapshotStore->reveal(), $strategy->reveal()); $this->eventStore->fromVersion(new StreamName('event_stream'), $aggregateRoot->getAggregateRootId(), $version + 1)->shouldBeCalled()->willReturn($stream); $repo = new AggregateRepository($this->eventStore->reveal(), $this->eventBus->reveal(), $snapshotter); $repo->load($aggregateRoot->getAggregateRootId(), AggregateRoot::class); }