|
18 | 18 | use Mcp\Server\Session\SessionStoreInterface; |
19 | 19 | use PHPUnit\Framework\Attributes\DataProvider; |
20 | 20 | use PHPUnit\Framework\TestCase; |
21 | | -use Symfony\Component\Cache\Adapter\ArrayAdapter; |
22 | | -use Symfony\Component\Cache\Psr16Cache; |
| 21 | +use Psr\SimpleCache\CacheInterface; |
23 | 22 | use Symfony\Component\Uid\UuidV4; |
24 | 23 |
|
25 | 24 | class SessionTest extends TestCase |
@@ -221,7 +220,7 @@ public static function provideStores(): iterable |
221 | 220 | { |
222 | 221 | yield 'in-memory' => [static fn () => new InMemorySessionStore()]; |
223 | 222 | yield 'file' => [static fn () => new FileSessionStore(sys_get_temp_dir().'/mcp-sessions-'.bin2hex(random_bytes(6)))]; |
224 | | - yield 'psr-16' => [static fn () => new Psr16SessionStore(new Psr16Cache(new ArrayAdapter()))]; |
| 223 | + yield 'psr-16' => [static fn () => new Psr16SessionStore(self::arrayCache())]; |
225 | 224 | } |
226 | 225 |
|
227 | 226 | /** |
@@ -402,4 +401,68 @@ public function testAllReturnsEmptyArrayForUndecodablePayload(): void |
402 | 401 |
|
403 | 402 | $this->assertSame([], $session->all()); |
404 | 403 | } |
| 404 | + |
| 405 | + private static function arrayCache(): CacheInterface |
| 406 | + { |
| 407 | + return new class implements CacheInterface { |
| 408 | + /** @var array<string, mixed> */ |
| 409 | + private array $values = []; |
| 410 | + |
| 411 | + public function get(string $key, mixed $default = null): mixed |
| 412 | + { |
| 413 | + return $this->values[$key] ?? $default; |
| 414 | + } |
| 415 | + |
| 416 | + public function set(string $key, mixed $value, int|\DateInterval|null $ttl = null): bool |
| 417 | + { |
| 418 | + $this->values[$key] = $value; |
| 419 | + |
| 420 | + return true; |
| 421 | + } |
| 422 | + |
| 423 | + public function delete(string $key): bool |
| 424 | + { |
| 425 | + unset($this->values[$key]); |
| 426 | + |
| 427 | + return true; |
| 428 | + } |
| 429 | + |
| 430 | + public function clear(): bool |
| 431 | + { |
| 432 | + $this->values = []; |
| 433 | + |
| 434 | + return true; |
| 435 | + } |
| 436 | + |
| 437 | + public function getMultiple(iterable $keys, mixed $default = null): iterable |
| 438 | + { |
| 439 | + foreach ($keys as $key) { |
| 440 | + yield $key => $this->get($key, $default); |
| 441 | + } |
| 442 | + } |
| 443 | + |
| 444 | + public function setMultiple(iterable $values, int|\DateInterval|null $ttl = null): bool |
| 445 | + { |
| 446 | + foreach ($values as $key => $value) { |
| 447 | + $this->set((string) $key, $value, $ttl); |
| 448 | + } |
| 449 | + |
| 450 | + return true; |
| 451 | + } |
| 452 | + |
| 453 | + public function deleteMultiple(iterable $keys): bool |
| 454 | + { |
| 455 | + foreach ($keys as $key) { |
| 456 | + $this->delete($key); |
| 457 | + } |
| 458 | + |
| 459 | + return true; |
| 460 | + } |
| 461 | + |
| 462 | + public function has(string $key): bool |
| 463 | + { |
| 464 | + return \array_key_exists($key, $this->values); |
| 465 | + } |
| 466 | + }; |
| 467 | + } |
405 | 468 | } |
0 commit comments