From e7230ec1d028b395ef7a46f1540b4a8e5865e68d Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 31 Jul 2024 10:11:08 +0200 Subject: [PATCH] add clear method into in memory store --- src/Store/InMemoryStore.php | 5 +++++ tests/Unit/Store/InMemoryStoreTest.php | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) 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); + } }