<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
namespace Friendica\Test\src\Core\KeyValueStorage;
-use Friendica\Core\Config\ValueObject\Cache;
-use Friendica\Core\KeyValueStorage\Capabilities\ICanManageKeyValuePairs;
+use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs;
use Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage;
-use Friendica\Database\Definition\DbaDefinition;
-use Friendica\Database\Definition\ViewDefinition;
-use Friendica\Test\DatabaseTestTrait;
-use Friendica\Test\Util\Database\StaticDatabase;
-use Friendica\Util\BasePath;
-use Friendica\Util\Profiler;
+use Friendica\Database\Database;
+use Friendica\Test\Util\CreateDatabaseTrait;
class DBKeyValueStorageTest extends KeyValueStorageTest
{
- use DatabaseTestTrait;
+ use CreateDatabaseTrait;
+
+ /** @var Database */
+ protected $database;
protected function setUp(): void
{
parent::setUp();
+ $this->setUpVfsDir();
$this->setUpDb();
}
$this->tearDownDb();
}
- public function getInstance(): ICanManageKeyValuePairs
+ public function getInstance(): IManageKeyValuePairs
+ {
+ $this->database = $this->getDbInstance();
+
+ return new DBKeyValueStorage($this->database);
+ }
+
+ /** @dataProvider dataTests */
+ public function testUpdatedAt($k, $v)
{
- $cache = new Cache();
- $cache->set('database', 'disable_pdo', true);
+ $instance = $this->getInstance();
+
+ $instance->set($k, $v);
+
+ self::assertEquals($v, $instance->get($k));
+ self::assertEquals($v, $instance[$k]);
+
+ $entry = $this->database->selectFirst(DBKeyValueStorage::DB_KEY_VALUE_TABLE, ['updated_at'], ['k' => $k]);
+ self::assertNotEmpty($entry);
+
+ $updateAt = $entry['updated_at'];
+
+ $instance->set($k, 'another_value');
+
+ self::assertEquals('another_value', $instance->get($k));
+ self::assertEquals('another_value', $instance[$k]);
- $basePath = new BasePath(dirname(__FILE__, 5), $_SERVER);
+ $entry = $this->database->selectFirst(DBKeyValueStorage::DB_KEY_VALUE_TABLE, ['updated_at'], ['k' => $k]);
+ self::assertNotEmpty($entry);
- $database = new StaticDatabase($cache, new Profiler($cache), (new DbaDefinition($basePath->getPath()))->load(), (new ViewDefinition($basePath->getPath()))->load());
- $database->setTestmode(true);
+ $updateAtAfter = $entry['updated_at'];
- return new DBKeyValueStorage($database);
+ self::assertLessThanOrEqual($updateAt, $updateAtAfter);
}
}