Skip to content

Commit 291d172

Browse files
committed
Expanded compatibility with psr/cache to include v3.
1 parent 98d0ab9 commit 291d172

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"require": {
1212
"php": "^8.1",
1313
"async/throttle": "^4",
14-
"psr/cache": "^1|^2",
14+
"psr/cache": "^1|^2|^3",
1515
"psr/container": "^1|^2",
1616
"scriptfusion/retry": "^5",
1717
"scriptfusion/retry-exception-handlers": "^1.2",

src/Cache/CacheItem.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function get(): mixed
2424
return $this->value;
2525
}
2626

27-
public function set(mixed $value): self
27+
public function set(mixed $value): static
2828
{
2929
$this->value = $value;
3030

@@ -36,12 +36,12 @@ public function isHit(): bool
3636
return $this->hit;
3737
}
3838

39-
public function expiresAt($expiration): self
39+
public function expiresAt($expiration): static
4040
{
4141
throw new NotImplementedException;
4242
}
4343

44-
public function expiresAfter($time): self
44+
public function expiresAfter($time): static
4545
{
4646
throw new NotImplementedException;
4747
}

src/Cache/MemoryCache.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class MemoryCache extends \ArrayObject implements CacheItemPoolInterface
1414
/**
1515
* @param string $key
1616
*/
17-
public function getItem($key): mixed
17+
public function getItem($key): CacheItemInterface
1818
{
1919
return \Closure::bind(
2020
function () use ($key): self {
@@ -37,17 +37,21 @@ public function hasItem($key): bool
3737
return isset($this[$key]);
3838
}
3939

40-
public function clear(): void
40+
public function clear(): bool
4141
{
4242
$this->exchangeArray([]);
43+
44+
return true;
4345
}
4446

45-
public function deleteItem($key): void
47+
public function deleteItem($key): bool
4648
{
4749
unset($this[$key]);
50+
51+
return true;
4852
}
4953

50-
public function deleteItems(array $keys): void
54+
public function deleteItems(array $keys): bool
5155
{
5256
foreach ($keys as $key) {
5357
if (!$this->hasItem($key)) {
@@ -56,16 +60,22 @@ public function deleteItems(array $keys): void
5660

5761
$this->deleteItem($key);
5862
}
63+
64+
return true;
5965
}
6066

61-
public function save(CacheItemInterface $item): void
67+
public function save(CacheItemInterface $item): bool
6268
{
6369
$this[$item->getKey()] = $item->get();
70+
71+
return true;
6472
}
6573

66-
public function saveDeferred(CacheItemInterface $item): void
74+
public function saveDeferred(CacheItemInterface $item): bool
6775
{
6876
$this->save($item);
77+
78+
return true;
6979
}
7080

7181
public function commit(): bool

test/Unit/Cache/MemoryCacheTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use ScriptFUSION\Porter\Cache\InvalidArgumentException;
99
use ScriptFUSION\Porter\Cache\MemoryCache;
1010

11+
/**
12+
* @see MemoryCache
13+
*/
1114
final class MemoryCacheTest extends TestCase
1215
{
1316
private MemoryCache $cache;
@@ -50,21 +53,21 @@ public function testHasItem(): void
5053

5154
public function testClear(): void
5255
{
53-
$this->cache->clear();
56+
self::assertTrue($this->cache->clear());
5457

5558
self::assertEmpty($this->cache->getArrayCopy());
5659
}
5760

5861
public function testDeleteItem(): void
5962
{
60-
$this->cache->deleteItem('foo');
63+
self::assertTrue($this->cache->deleteItem('foo'));
6164

6265
self::assertFalse($this->cache->hasItem('foo'));
6366
}
6467

6568
public function testDeleteItems(): void
6669
{
67-
$this->cache->deleteItems(['foo']);
70+
self::assertTrue($this->cache->deleteItems(['foo']));
6871

6972
self::assertEmpty($this->cache->getArrayCopy());
7073
}
@@ -78,14 +81,14 @@ public function testDeleteInvalidItem(): void
7881

7982
public function testSave(): void
8083
{
81-
$this->cache->save($this->cache->getItem('bar')->set('baz'));
84+
self::assertTrue($this->cache->save($this->cache->getItem('bar')->set('baz')));
8285

8386
self::assertSame('baz', $this->cache->getItem('bar')->get());
8487
}
8588

8689
public function testSaveDeferred(): void
8790
{
88-
$this->cache->saveDeferred($this->cache->getItem('bar')->set('baz'));
91+
self::assertTrue($this->cache->saveDeferred($this->cache->getItem('bar')->set('baz')));
8992

9093
self::assertSame('baz', $this->cache->getItem('bar')->get());
9194
}

0 commit comments

Comments
 (0)