Skip to content

Commit

Permalink
Merge pull request #627 from patchlevel/add-clear-in-memory-store
Browse files Browse the repository at this point in the history
add clear method into in-memory store
  • Loading branch information
DavidBadura authored Jul 31, 2024
2 parents e61519c + e7230ec commit 58b77ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Store/InMemoryStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,9 @@ static function (Message $message, int $index) use ($criteria): bool {
ARRAY_FILTER_USE_BOTH,
);
}

public function clear(): void
{
$this->messages = [];
}
}
21 changes: 21 additions & 0 deletions tests/Unit/Store/InMemoryStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 58b77ef

Please sign in to comment.