From b8f50332dfde58c30a6f0c1421edf2a3b66d0475 Mon Sep 17 00:00:00 2001 From: Enea Date: Tue, 15 Aug 2023 18:10:49 +0200 Subject: [PATCH] Introduce CommonStoreMultipleTestsTrait --- composer.json | 3 +- tests/src/CacheTestTrait.php | 3 +- tests/src/CommonMultipleProviderTrait.php | 56 --------- tests/src/CommonTrait.php | 135 ---------------------- tests/src/ModTestTrait.php | 3 +- tests/src/OptionTestsTrait.php | 4 +- tests/src/TransientTestsTrait.php | 3 +- 7 files changed, 11 insertions(+), 196 deletions(-) delete mode 100644 tests/src/CommonMultipleProviderTrait.php delete mode 100644 tests/src/CommonTrait.php diff --git a/composer.json b/composer.json index 2bb2eda..3c09526 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "rector/rector": "^0.15.17", "infection/infection": "^0.26.6", "infection/codeception-adapter": "^0.4.1", - "italystrap/debug": "^2.1" + "italystrap/debug": "^2.1", + "italystrap/storage-tests": "dev-master" }, "autoload": { "psr-4": { diff --git a/tests/src/CacheTestTrait.php b/tests/src/CacheTestTrait.php index cc917f5..7cd867c 100644 --- a/tests/src/CacheTestTrait.php +++ b/tests/src/CacheTestTrait.php @@ -5,10 +5,11 @@ namespace ItalyStrap\Tests; use ItalyStrap\Storage\Cache; +use ItalyStrap\StorageTests\CommonStoreMultipleTestsTrait; trait CacheTestTrait { - use NormalizeTtlTestTrait, CommonMultipleProviderTrait, CommonTrait; + use NormalizeTtlTestTrait, CommonStoreMultipleTestsTrait; /** * @test diff --git a/tests/src/CommonMultipleProviderTrait.php b/tests/src/CommonMultipleProviderTrait.php deleted file mode 100644 index f05bff5..0000000 --- a/tests/src/CommonMultipleProviderTrait.php +++ /dev/null @@ -1,56 +0,0 @@ - [ - ['key1' => 'value1', 'key2' => 'value2'], - ]; - - yield 'Traversable' => [ - new \ArrayIterator(['key1' => 'value1', 'key2' => 'value2']), - ]; - - yield 'Generator' => [ - (function () { - yield 'key1' => 'value1'; - yield 'key2' => 'value2'; - })(), - ]; - - yield 'ArrayObject' => [ - new \ArrayObject(['key1' => 'value1', 'key2' => 'value2']), - ]; - } - - public static function iterableValuesForGetMultipleAndUpdateMultipleProvider(): iterable - { - yield 'Array' => [ - ['key1', 'key2'], - ['key1' => 'value1', 'key2' => 'value2'], - ]; - - yield 'Traversable' => [ - new \ArrayIterator(['key1', 'key2']), - ['key1' => 'value1', 'key2' => 'value2'], - ]; - - yield 'Generator' => [ - (function () { - yield 'key1'; - yield 'key2'; - })(), - ['key1' => 'value1', 'key2' => 'value2'], - ]; - - yield 'ArrayObject' => [ - new \ArrayObject(['key1', 'key2']), - ['key1' => 'value1', 'key2' => 'value2'], - ]; - } -} diff --git a/tests/src/CommonTrait.php b/tests/src/CommonTrait.php deleted file mode 100644 index 54bb735..0000000 --- a/tests/src/CommonTrait.php +++ /dev/null @@ -1,135 +0,0 @@ -assertSame('default', $this->makeInstance()->get('key', 'default'), ''); - } - - /** - * @test - */ - public function getZeroWhenValueIsZero(): void - { - $sut = $this->makeInstance(); - $sut->set('key', 0); - $this->assertSame(0, $sut->get('key'), ''); - } - - /** - * @test - * @dataProvider iterableValueForSetMultipleProvider - */ - public function setMultiple(iterable $values) - { - $sut = $this->makeInstance(); - $this->assertTrue($sut->setMultiple($values), ''); - $this->assertSame('value1', $sut->get('key1'), ''); - $this->assertSame('value2', $sut->get('key2'), ''); - } - - abstract protected function prepareSetMultipleReturnFalse(): void; - - /** - * @test - */ - public function setMultipleReturnFalse(): void - { - $this->prepareSetMultipleReturnFalse(); - $sut = $this->makeInstance(); - $this->assertFalse($sut->set('', 'value1'), ''); - $this->assertFalse($sut->setMultiple([ - '' => 'value1', - ]), ''); - } - - /** - * @test - * @dataProvider iterableValuesForGetMultipleAndUpdateMultipleProvider - */ - public function getMultiple(iterable $keys, iterable $expected = []) - { - $sut = $this->makeInstance(); - $sut->set('key1', 'value1'); - $sut->set('key2', 'value2'); - $actual = $sut->getMultiple($keys); - - $count = 0; - foreach ($actual as $key => $value) { - $count++; - $this->assertSame($expected[$key], $value, ''); - } - $this->assertSame(2, $count, ''); - } - - /** - * @test - */ - public function getMultipleReturnDefaultValue(): void - { - $sut = $this->makeInstance(); - $sut->set('key2', 'value2'); - $actual = $sut->getMultiple(['key1', 'key3'], 'default'); - - $count = 0; - foreach ($actual as $value) { - $count++; - $this->assertSame('default', $value, ''); - } - $this->assertSame(2, $count, ''); - } - - /** - * @test - * @dataProvider iterableValuesForGetMultipleAndUpdateMultipleProvider - */ - public function deleteMultiple(iterable $keys, iterable $expected = []) - { - $sut = $this->makeInstance(); - $sut->set('key1', 'value1'); - $sut->set('key2', 'value2'); - $this->assertSame('value1', $sut->get('key1'), ''); - $this->assertSame('value2', $sut->get('key2'), ''); - $this->assertTrue($this->makeInstance()->deleteMultiple($keys), ''); - $this->assertNull($sut->get('key1'), ''); - $this->assertNull($sut->get('key2'), ''); - } - - /** - * @test - */ - public function deleteMultipleReturnTrueWithNotExistentValue() - { - $this->assertNull($this->makeInstance()->get('key1')); - $this->assertNull($this->makeInstance()->get('key3')); - $this->assertTrue($this->makeInstance()->deleteMultiple(['key1', 'key3']), ''); - } - - /** - * @test - * @todo In the future make this test pass - */ - public function deleteNotExistingValue() - { - $this->assertTrue($this->makeInstance()->delete('key1'), ''); - } - - /** - * @test - */ - public function deleteFromEmptyKeyShouldReturnFalse() - { - $this->assertFalse($this->makeInstance()->delete(''), ''); - $this->assertFalse($this->makeInstance()->deleteMultiple(['']), ''); - } -} diff --git a/tests/src/ModTestTrait.php b/tests/src/ModTestTrait.php index 843ab91..cbcb2f1 100644 --- a/tests/src/ModTestTrait.php +++ b/tests/src/ModTestTrait.php @@ -5,10 +5,11 @@ namespace ItalyStrap\Tests; use ItalyStrap\Storage\Mod; +use ItalyStrap\StorageTests\CommonStoreMultipleTestsTrait; trait ModTestTrait { - use CommonTrait; + use CommonStoreMultipleTestsTrait; /** * @test diff --git a/tests/src/OptionTestsTrait.php b/tests/src/OptionTestsTrait.php index bb3e077..e044e95 100644 --- a/tests/src/OptionTestsTrait.php +++ b/tests/src/OptionTestsTrait.php @@ -4,9 +4,11 @@ namespace ItalyStrap\Tests; +use ItalyStrap\StorageTests\CommonStoreMultipleTestsTrait; + trait OptionTestsTrait { - use CommonTrait; + use CommonStoreMultipleTestsTrait; /** * @test diff --git a/tests/src/TransientTestsTrait.php b/tests/src/TransientTestsTrait.php index ea05e93..c6fe940 100644 --- a/tests/src/TransientTestsTrait.php +++ b/tests/src/TransientTestsTrait.php @@ -5,10 +5,11 @@ namespace ItalyStrap\Tests; use ItalyStrap\Storage\Transient; +use ItalyStrap\StorageTests\CommonStoreMultipleTestsTrait; trait TransientTestsTrait { - use ValidateKeyLenghtTestTrait, NormalizeTtlTestTrait, CommonMultipleProviderTrait, CommonTrait; + use ValidateKeyLenghtTestTrait, NormalizeTtlTestTrait, CommonStoreMultipleTestsTrait; /** * @test