Prooph\EventStore\Adapter\InMemoryAdapter::replay PHP Method

replay() public method

public replay ( StreamName $streamName, DateTimeInterface $since = null, array $metadata = [] ) : ArrayIterator
$streamName Prooph\EventStore\Stream\StreamName
$since DateTimeInterface
$metadata array
return ArrayIterator
    public function replay(StreamName $streamName, DateTimeInterface $since = null, array $metadata = [])
    {
        if (!isset($this->streams[$streamName->toString()])) {
            return new ArrayIterator();
        }
        $streamEvents = [];
        foreach ($this->streams[$streamName->toString()] as $index => $streamEvent) {
            if (null === $since && $this->matchMetadataWith($streamEvent, $metadata)) {
                $streamEvents[] = $streamEvent;
            } elseif ($streamEvent->createdAt()->format('U.u') >= $since->format('U.u') && $this->matchMetadataWith($streamEvent, $metadata)) {
                $streamEvents[] = $streamEvent;
            }
        }
        return new ArrayIterator($streamEvents);
    }

Usage Example

 /**
  * @test
  */
 public function it_returns_nothing_when_trying_to_replay_non_existing_stream()
 {
     $streamName = $this->prophesize(StreamName::class);
     $streamName->toString()->willReturn('test');
     $this->assertCount(0, $this->adapter->replay($streamName->reveal(), null, []));
 }