diff --git a/src/Store/InMemoryStore.php b/src/Store/InMemoryStore.php index f774e89f..20430ffa 100644 --- a/src/Store/InMemoryStore.php +++ b/src/Store/InMemoryStore.php @@ -227,4 +227,9 @@ static function (Message $message, int $index) use ($criteria): bool { ARRAY_FILTER_USE_BOTH, ); } + + public function clear(): void + { + $this->messages = []; + } } diff --git a/tests/Unit/Store/InMemoryStoreTest.php b/tests/Unit/Store/InMemoryStoreTest.php index 626918ba..8d4e059e 100644 --- a/tests/Unit/Store/InMemoryStoreTest.php +++ b/tests/Unit/Store/InMemoryStoreTest.php @@ -347,4 +347,25 @@ static function () use (&$called): void { self::assertTrue($called); } + + public function testClear(): void + { + $message1 = (new Message(new ProfileVisited(ProfileId::fromString('1')))) + ->withHeader(new StreamHeader('foo')); + $message2 = (new Message(new ProfileVisited(ProfileId::fromString('2')))) + ->withHeader(new StreamHeader('bar')); + $message3 = (new Message(new ProfileVisited(ProfileId::fromString('3')))) + ->withHeader(new StreamHeader('bar')); + $message4 = (new Message(new ProfileVisited(ProfileId::fromString('3')))); + + $store = new InMemoryStore([$message1, $message2, $message3, $message4]); + + $store->clear(); + + $stream = $store->load(); + + $messages = iterator_to_array($stream); + + self::assertSame([], $messages); + } }