From 163e37f9a7b49f60d63ac2e897f57475c10044ca Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Mon, 15 Jan 2024 11:17:57 +0300 Subject: [PATCH] Updated tests --- tests/Cache/NotWhen/Simple/ArrayTest.php | 43 +++++++++++++++++++----- tests/Cache/NotWhen/Simple/FileTest.php | 43 +++++++++++++++++++----- tests/Cache/NotWhen/Simple/RedisTest.php | 43 +++++++++++++++++++----- tests/Cache/When/Simple/ArrayTest.php | 43 +++++++++++++++++++----- tests/Cache/When/Simple/FileTest.php | 43 +++++++++++++++++++----- tests/Cache/When/Simple/RedisTest.php | 43 +++++++++++++++++++----- 6 files changed, 210 insertions(+), 48 deletions(-) diff --git a/tests/Cache/NotWhen/Simple/ArrayTest.php b/tests/Cache/NotWhen/Simple/ArrayTest.php index f67dfcb..7bda21a 100644 --- a/tests/Cache/NotWhen/Simple/ArrayTest.php +++ b/tests/Cache/NotWhen/Simple/ArrayTest.php @@ -52,20 +52,47 @@ public function testForget() $this->assertNull($this->cache()->get()); } - public function testFlush() + public function testFlushByKeys() { - $tags = Cache::make()->tags('foo', 'bar'); - $cache = (clone $tags)->key('qwerty'); + $cache1 = Cache::make()->when($this->when)->key('foo'); + $cache2 = Cache::make()->when($this->when)->key('bar'); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $cache->put('asd'); + $cache1->put('qwe'); + $cache2->put('rty'); - $this->assertSame('asd', $cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $tags->flush(); + $cache1->flush(); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + } + + public function testFlushByTags() + { + $tags1 = Cache::make()->when($this->when)->tags('some1'); + $tags2 = Cache::make()->when($this->when)->tags('some2'); + + $cache1 = (clone $tags1)->key('foo'); + $cache2 = (clone $tags2)->key('bar'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $cache1->put('qwe'); + $cache2->put('rty'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $tags1->flush(); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); } public function testHas() diff --git a/tests/Cache/NotWhen/Simple/FileTest.php b/tests/Cache/NotWhen/Simple/FileTest.php index 5bc974e..d3e0311 100644 --- a/tests/Cache/NotWhen/Simple/FileTest.php +++ b/tests/Cache/NotWhen/Simple/FileTest.php @@ -52,20 +52,47 @@ public function testForget() $this->assertNull($this->cache()->get()); } - public function testFlush() + public function testFlushByKeys() { - $tags = Cache::make()->tags('foo', 'bar'); - $cache = (clone $tags)->key('qwerty'); + $cache1 = Cache::make()->when($this->when)->key('foo'); + $cache2 = Cache::make()->when($this->when)->key('bar'); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $cache->put('asd'); + $cache1->put('qwe'); + $cache2->put('rty'); - $this->assertSame('asd', $cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $tags->flush(); + $cache1->flush(); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + } + + public function testFlushByTags() + { + $tags1 = Cache::make()->when($this->when)->tags('some1'); + $tags2 = Cache::make()->when($this->when)->tags('some2'); + + $cache1 = (clone $tags1)->key('foo'); + $cache2 = (clone $tags2)->key('bar'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $cache1->put('qwe'); + $cache2->put('rty'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $tags1->flush(); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); } public function testHas() diff --git a/tests/Cache/NotWhen/Simple/RedisTest.php b/tests/Cache/NotWhen/Simple/RedisTest.php index 993e4d7..d2ca0e2 100644 --- a/tests/Cache/NotWhen/Simple/RedisTest.php +++ b/tests/Cache/NotWhen/Simple/RedisTest.php @@ -74,20 +74,47 @@ public function testForget() $this->assertNull($this->cache(['cache'])->get()); } - public function testFlush() + public function testFlushByKeys() { - $tags = Cache::make()->tags('foo', 'bar'); - $cache = (clone $tags)->key('qwerty'); + $cache1 = Cache::make()->when($this->when)->key('foo'); + $cache2 = Cache::make()->when($this->when)->key('bar'); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $cache->put('asd'); + $cache1->put('qwe'); + $cache2->put('rty'); - $this->assertSame('asd', $cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $tags->flush(); + $cache1->flush(); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + } + + public function testFlushByTags() + { + $tags1 = Cache::make()->when($this->when)->tags('some1'); + $tags2 = Cache::make()->when($this->when)->tags('some2'); + + $cache1 = (clone $tags1)->key('foo'); + $cache2 = (clone $tags2)->key('bar'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $cache1->put('qwe'); + $cache2->put('rty'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $tags1->flush(); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); } public function testHas() diff --git a/tests/Cache/When/Simple/ArrayTest.php b/tests/Cache/When/Simple/ArrayTest.php index fc3e3e2..524deb0 100644 --- a/tests/Cache/When/Simple/ArrayTest.php +++ b/tests/Cache/When/Simple/ArrayTest.php @@ -62,20 +62,47 @@ public function testForget() $this->assertNull($this->cache()->get()); } - public function testFlush() + public function testFlushByKeys() { - $tags = Cache::make()->tags('foo', 'bar'); - $cache = (clone $tags)->key('qwerty'); + $cache1 = Cache::make()->key('foo'); + $cache2 = Cache::make()->key('bar'); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $cache->put('asd'); + $cache1->put('qwe'); + $cache2->put('rty'); - $this->assertSame('asd', $cache->get()); + $this->assertSame('qwe', $cache1->get()); + $this->assertSame('rty', $cache2->get()); - $tags->flush(); + $cache1->flush(); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + } + + public function testFlushByTags() + { + $tags1 = Cache::make()->tags('some1'); + $tags2 = Cache::make()->tags('some2'); + + $cache1 = (clone $tags1)->key('foo'); + $cache2 = (clone $tags2)->key('bar'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $cache1->put('qwe'); + $cache2->put('rty'); + + $this->assertSame('qwe', $cache1->get()); + $this->assertSame('rty', $cache2->get()); + + $tags1->flush(); + + $this->assertNull($cache1->get()); + $this->assertSame('rty', $cache2->get()); } public function testHas() diff --git a/tests/Cache/When/Simple/FileTest.php b/tests/Cache/When/Simple/FileTest.php index dc696cc..f1acfa8 100644 --- a/tests/Cache/When/Simple/FileTest.php +++ b/tests/Cache/When/Simple/FileTest.php @@ -64,20 +64,47 @@ public function testForget() $this->assertNull($this->cache()->get()); } - public function testFlush() + public function testFlushByKeys() { - $tags = Cache::make()->tags('foo', 'bar'); - $cache = (clone $tags)->key('qwerty'); + $cache1 = Cache::make()->key('foo'); + $cache2 = Cache::make()->key('bar'); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $cache->put('asd'); + $cache1->put('qwe'); + $cache2->put('rty'); - $this->assertSame('asd', $cache->get()); + $this->assertSame('qwe', $cache1->get()); + $this->assertSame('rty', $cache2->get()); - $tags->flush(); + $cache1->flush(); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + } + + public function testFlushByTags() + { + $tags1 = Cache::make()->tags('some1'); + $tags2 = Cache::make()->tags('some2'); + + $cache1 = (clone $tags1)->key('foo'); + $cache2 = (clone $tags2)->key('bar'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $cache1->put('qwe'); + $cache2->put('rty'); + + $this->assertSame('qwe', $cache1->get()); + $this->assertSame('rty', $cache2->get()); + + $tags1->flush(); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); } public function testHas() diff --git a/tests/Cache/When/Simple/RedisTest.php b/tests/Cache/When/Simple/RedisTest.php index f945ae6..b92f13a 100644 --- a/tests/Cache/When/Simple/RedisTest.php +++ b/tests/Cache/When/Simple/RedisTest.php @@ -73,20 +73,47 @@ public function testForget() $this->assertNull($this->cache(['cache'])->get()); } - public function testFlush() + public function testFlushByKeys() { - $tags = Cache::make()->tags('foo', 'bar'); - $cache = (clone $tags)->key('qwerty'); + $cache1 = Cache::make()->key('foo'); + $cache2 = Cache::make()->key('bar'); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); - $cache->put('asd'); + $cache1->put('qwe'); + $cache2->put('rty'); - $this->assertSame('asd', $cache->get()); + $this->assertSame('qwe', $cache1->get()); + $this->assertSame('rty', $cache2->get()); - $tags->flush(); + $cache1->flush(); - $this->assertNull($cache->get()); + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + } + + public function testFlushByTags() + { + $tags1 = Cache::make()->tags('some1'); + $tags2 = Cache::make()->tags('some2'); + + $cache1 = (clone $tags1)->key('foo'); + $cache2 = (clone $tags2)->key('bar'); + + $this->assertNull($cache1->get()); + $this->assertNull($cache2->get()); + + $cache1->put('qwe'); + $cache2->put('rty'); + + $this->assertSame('qwe', $cache1->get()); + $this->assertSame('rty', $cache2->get()); + + $tags1->flush(); + + $this->assertNull($cache1->get()); + $this->assertSame('rty', $cache2->get()); } public function testHas()