Inline KeyValueStorageTest into DBKeyValueStorageTest

This commit is contained in:
Art4 2024-12-14 21:33:16 +00:00
parent 54ee36a6aa
commit f3f52efe18
2 changed files with 77 additions and 92 deletions

View file

@ -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]);
}
}

View file

@ -1,91 +0,0 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace Friendica\Test\src\Core\KeyValueStorage;
use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
use Friendica\Test\MockedTestCase;
abstract class KeyValueStorageTest extends MockedTestCase
{
abstract public function getInstance(): IManageKeyValuePairs;
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]);
}
}