Skip to content

Commit e4b6b84

Browse files
committed
Add clear method to SimpleInMemoryStorage
1 parent 0e3264f commit e4b6b84

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Storage/SimpleInMemoryStorage.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ class SimpleInMemoryStorage implements StorageInterface
1010
{
1111
protected array $storage = [];
1212

13+
/**
14+
* Clear the current storage, e.g. to clean up after a test
15+
* @return void
16+
*/
17+
public function clear(): void
18+
{
19+
$this->storage = [];
20+
}
21+
1322
public function putIf(string $key, string $value, ?string $previousValue, bool $returnNewValueOnFail = false): bool|string|null
1423
{
1524
$realValue = $this->get($key);

test/Storage/SimpleInMemoryStorageTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public function testDeleteIfFailValue(?string $previousValue, ?string $realValue
9393
$this->assertEquals($realValue, $this->storage->deleteIf("key", $previousValue, true));
9494
$this->assertEquals($realValue, $this->storage->get("key"));
9595
}
96+
97+
public function testClear(): void
98+
{
99+
$this->assertTrue($this->storage->putIf("key", "value", null));
100+
$this->storage->clear();
101+
$this->assertNull($this->storage->get("key"));
102+
}
96103
}
97104

98105
class PublicSimpleInMemoryStorage extends SimpleInMemoryStorage

0 commit comments

Comments
 (0)