3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Core\KeyValueStorage;
24 use Friendica\Core\KeyValueStorage\Capabilities\ICanManageKeyValuePairs;
25 use Friendica\Test\MockedTest;
27 abstract class KeyValueStorageTest extends MockedTest
29 abstract public function getInstance(): ICanManageKeyValuePairs;
31 public function testInstance()
33 $instance = $this->getInstance();
35 self::assertInstanceOf(ICanManageKeyValuePairs::class, $instance);
38 public function dataTests(): array
41 'string' => ['k' => 'data', 'v' => 'it'],
42 'boolTrue' => ['k' => 'data', 'v' => true],
43 'boolFalse' => ['k' => 'data', 'v' => false],
44 'integer' => ['k' => 'data', 'v' => 235],
45 'decimal' => ['k' => 'data', 'v' => 2.456],
46 'array' => ['k' => 'data', 'v' => ['1', 2, '3', true, false]],
47 'boolIntTrue' => ['k' => 'data', 'v' => 1],
48 'boolIntFalse' => ['k' => 'data', 'v' => 0],
53 * @dataProvider dataTests
55 public function testGetSetDelete($k, $v)
57 $instance = $this->getInstance();
59 $instance->set($k, $v);
61 self::assertEquals($v, $instance->get($k));
62 self::assertEquals($v, $instance[$k]);
64 $instance->delete($k);
66 self::assertNull($instance->get($k));
67 self::assertNull($instance[$k]);
71 * @dataProvider dataTests
73 public function testSetOverride($k, $v)
75 $instance = $this->getInstance();
77 $instance->set($k, $v);
79 self::assertEquals($v, $instance->get($k));
80 self::assertEquals($v, $instance[$k]);
82 $instance->set($k, 'another_value');
84 self::assertEquals('another_value', $instance->get($k));
85 self::assertEquals('another_value', $instance[$k]);
89 * @dataProvider dataTests
91 public function testOffsetSetDelete($k, $v)
93 $instance = $this->getInstance();
97 self::assertEquals($v, $instance->get($k));
98 self::assertEquals($v, $instance[$k]);
100 unset($instance[$k]);
102 self::assertNull($instance->get($k));
103 self::assertNull($instance[$k]);