From f3f52efe18706c7e08d0db333e1bd8e36a5fddd6 Mon Sep 17 00:00:00 2001 From: Art4 Date: Sat, 14 Dec 2024 21:33:16 +0000 Subject: [PATCH] Inline KeyValueStorageTest into DBKeyValueStorageTest --- .../KeyValueStorage/DBKeyValueStorageTest.php | 78 +++++++++++++++- .../KeyValueStorage/KeyValueStorageTest.php | 91 ------------------- 2 files changed, 77 insertions(+), 92 deletions(-) delete mode 100644 tests/src/Core/KeyValueStorage/KeyValueStorageTest.php diff --git a/tests/src/Core/KeyValueStorage/DBKeyValueStorageTest.php b/tests/src/Core/KeyValueStorage/DBKeyValueStorageTest.php index 5575ea5e27..73699cd84e 100644 --- a/tests/src/Core/KeyValueStorage/DBKeyValueStorageTest.php +++ b/tests/src/Core/KeyValueStorage/DBKeyValueStorageTest.php @@ -10,9 +10,10 @@ namespace Friendica\Test\src\Core\KeyValueStorage; use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage; use Friendica\Database\Database; +use Friendica\Test\MockedTestCase; use Friendica\Test\Util\CreateDatabaseTrait; -class DBKeyValueStorageTest extends KeyValueStorageTest +class DBKeyValueStorageTest extends MockedTestCase { use CreateDatabaseTrait; @@ -68,4 +69,79 @@ class DBKeyValueStorageTest extends KeyValueStorageTest self::assertGreaterThanOrEqual($updateAt, $updateAtAfter); } + + public function testInstance() + { + $instance = $this->getInstance(); + + self::assertInstanceOf(IManageKeyValuePairs::class, $instance); + } + + public function dataTests(): array + { + return [ + 'string' => ['k' => 'data', 'v' => 'it'], + 'boolTrue' => ['k' => 'data', 'v' => true], + 'boolFalse' => ['k' => 'data', 'v' => false], + 'integer' => ['k' => 'data', 'v' => 235], + 'decimal' => ['k' => 'data', 'v' => 2.456], + 'array' => ['k' => 'data', 'v' => ['1', 2, '3', true, false]], + 'boolIntTrue' => ['k' => 'data', 'v' => 1], + 'boolIntFalse' => ['k' => 'data', 'v' => 0], + ]; + } + + /** + * @dataProvider dataTests + */ + public function testGetSetDelete($k, $v) + { + $instance = $this->getInstance(); + + $instance->set($k, $v); + + self::assertEquals($v, $instance->get($k)); + self::assertEquals($v, $instance[$k]); + + $instance->delete($k); + + self::assertNull($instance->get($k)); + self::assertNull($instance[$k]); + } + + /** + * @dataProvider dataTests + */ + public function testSetOverride($k, $v) + { + $instance = $this->getInstance(); + + $instance->set($k, $v); + + self::assertEquals($v, $instance->get($k)); + self::assertEquals($v, $instance[$k]); + + $instance->set($k, 'another_value'); + + self::assertEquals('another_value', $instance->get($k)); + self::assertEquals('another_value', $instance[$k]); + } + + /** + * @dataProvider dataTests + */ + public function testOffsetSetDelete($k, $v) + { + $instance = $this->getInstance(); + + $instance[$k] = $v; + + self::assertEquals($v, $instance->get($k)); + self::assertEquals($v, $instance[$k]); + + unset($instance[$k]); + + self::assertNull($instance->get($k)); + self::assertNull($instance[$k]); + } } diff --git a/tests/src/Core/KeyValueStorage/KeyValueStorageTest.php b/tests/src/Core/KeyValueStorage/KeyValueStorageTest.php deleted file mode 100644 index 123be61e12..0000000000 --- a/tests/src/Core/KeyValueStorage/KeyValueStorageTest.php +++ /dev/null @@ -1,91 +0,0 @@ -getInstance(); - - self::assertInstanceOf(IManageKeyValuePairs::class, $instance); - } - - public function dataTests(): array - { - return [ - 'string' => ['k' => 'data', 'v' => 'it'], - 'boolTrue' => ['k' => 'data', 'v' => true], - 'boolFalse' => ['k' => 'data', 'v' => false], - 'integer' => ['k' => 'data', 'v' => 235], - 'decimal' => ['k' => 'data', 'v' => 2.456], - 'array' => ['k' => 'data', 'v' => ['1', 2, '3', true, false]], - 'boolIntTrue' => ['k' => 'data', 'v' => 1], - 'boolIntFalse' => ['k' => 'data', 'v' => 0], - ]; - } - - /** - * @dataProvider dataTests - */ - public function testGetSetDelete($k, $v) - { - $instance = $this->getInstance(); - - $instance->set($k, $v); - - self::assertEquals($v, $instance->get($k)); - self::assertEquals($v, $instance[$k]); - - $instance->delete($k); - - self::assertNull($instance->get($k)); - self::assertNull($instance[$k]); - } - - /** - * @dataProvider dataTests - */ - public function testSetOverride($k, $v) - { - $instance = $this->getInstance(); - - $instance->set($k, $v); - - self::assertEquals($v, $instance->get($k)); - self::assertEquals($v, $instance[$k]); - - $instance->set($k, 'another_value'); - - self::assertEquals('another_value', $instance->get($k)); - self::assertEquals('another_value', $instance[$k]); - } - - /** - * @dataProvider dataTests - */ - public function testOffsetSetDelete($k, $v) - { - $instance = $this->getInstance(); - - $instance[$k] = $v; - - self::assertEquals($v, $instance->get($k)); - self::assertEquals($v, $instance[$k]); - - unset($instance[$k]); - - self::assertNull($instance->get($k)); - self::assertNull($instance[$k]); - } -}