From 75b0f2c9bfa008e4388dde26e46baf227a872395 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Thu, 20 Apr 2023 16:17:49 +0900 Subject: [PATCH] Create connection test with serializable redis adapter --- tests/RedisAdapterTest.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/RedisAdapterTest.php b/tests/RedisAdapterTest.php index eae6daf..c31a525 100644 --- a/tests/RedisAdapterTest.php +++ b/tests/RedisAdapterTest.php @@ -9,6 +9,7 @@ use Ray\Di\Injector; use Redis; use Symfony\Component\Cache\Adapter\AbstractAdapter; +use Symfony\Contracts\Cache\ItemInterface; use function serialize; use function unserialize; @@ -17,7 +18,19 @@ class RedisAdapterTest extends TestCase { public function testSerialize(): string { - $string = serialize(new RedisAdapter(new Redis())); + $client = RedisAdapter::createConnection( + 'redis://localhost', + ); + + $adapter = new RedisAdapter($client); + $adapter->get('foo', static function (ItemInterface $item) { + return 'foobar'; + }); + $foo = $adapter->get('foo', static function (ItemInterface $item) { + return '_no_serve_'; + }); + $this->assertSame('foobar', $foo); + $string = serialize($adapter); $this->assertIsString($string); return $string; @@ -26,7 +39,11 @@ public function testSerialize(): string /** @depends testSerialize */ public function testUnserialize(string $string): void { - $this->assertInstanceOf(RedisAdapter::class, unserialize($string)); + $adapter = unserialize($string); + $this->assertInstanceOf(RedisAdapter::class, $adapter); + $this->assertSame('foobar', $adapter->get('foo', static function (ItemInterface $item) { + return '_no_serve_'; + })); } public function testCacheNamespaceModule(): void