mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-10 17:14:26 +02:00
Restructure Storage to new paradigm
This commit is contained in:
parent
24f8ee8e67
commit
2ab0d06996
29 changed files with 229 additions and 199 deletions
|
@ -19,10 +19,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Model\Storage;
|
||||
namespace Friendica\Test\src\Core\Storage;
|
||||
|
||||
use Friendica\Core\Config\Factory\Config;
|
||||
use Friendica\Model\Storage\Database;
|
||||
use Friendica\Core\Storage\Type\Database;
|
||||
use Friendica\Test\DatabaseTestTrait;
|
||||
use Friendica\Test\Util\Database\StaticDatabase;
|
||||
use Friendica\Test\Util\VFSTrait;
|
|
@ -19,12 +19,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Model\Storage;
|
||||
namespace Friendica\Test\src\Core\Storage;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Model\Storage\FilesystemConfig;
|
||||
use Friendica\Model\Storage\IStorageConfiguration;
|
||||
use Friendica\Core\Storage\Capability\ICanConfigureStorage;
|
||||
use Friendica\Core\Storage\Type\FilesystemConfig;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Mockery\MockInterface;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
@ -54,7 +54,7 @@ class FilesystemStorageConfigTest extends StorageConfigTest
|
|||
return new FilesystemConfig($config, $l10n);
|
||||
}
|
||||
|
||||
protected function assertOption(IStorageConfiguration $storage)
|
||||
protected function assertOption(ICanConfigureStorage $storage)
|
||||
{
|
||||
self::assertEquals([
|
||||
'storagepath' => [
|
|
@ -19,11 +19,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Model\Storage;
|
||||
namespace Friendica\Test\src\Core\Storage;
|
||||
|
||||
use Friendica\Model\Storage\Filesystem;
|
||||
use Friendica\Model\Storage\FilesystemConfig;
|
||||
use Friendica\Model\Storage\StorageException;
|
||||
use Friendica\Core\Storage\Exception\StorageException;
|
||||
use Friendica\Core\Storage\Type\Filesystem;
|
||||
use Friendica\Core\Storage\Type\FilesystemConfig;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Core;
|
||||
namespace Friendica\Test\src\Core\Storage\Repository;
|
||||
|
||||
use Dice\Dice;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
|
@ -28,12 +28,17 @@ use Friendica\Core\Hook;
|
|||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Session\Capability\IHandleSessions;
|
||||
use Friendica\Core\Session\Type\Memory;
|
||||
use Friendica\Core\StorageManager;
|
||||
use Friendica\Core\Storage\Exception\InvalidClassStorageException;
|
||||
use Friendica\Core\Storage\Capability\ICanReadFromStorage;
|
||||
use Friendica\Core\Storage\Capability\ICanWriteToStorage;
|
||||
use Friendica\Core\Storage\Repository\StorageManager;
|
||||
use Friendica\Core\Storage\Type\Filesystem;
|
||||
use Friendica\Core\Storage\Type\SystemResource;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\DI;
|
||||
use Friendica\Core\Config\Factory\Config;
|
||||
use Friendica\Core\Config\Repository;
|
||||
use Friendica\Model\Storage;
|
||||
use Friendica\Core\Storage\Type;
|
||||
use Friendica\Network\HTTPClient;
|
||||
use Friendica\Test\DatabaseTest;
|
||||
use Friendica\Test\Util\Database\StaticDatabase;
|
||||
|
@ -64,7 +69,7 @@ class StorageManagerTest extends DatabaseTest
|
|||
|
||||
$this->setUpVfsDir();
|
||||
|
||||
vfsStream::newDirectory(Storage\FilesystemConfig::DEFAULT_BASE_FOLDER, 0777)->at($this->root);
|
||||
vfsStream::newDirectory(Type\FilesystemConfig::DEFAULT_BASE_FOLDER, 0777)->at($this->root);
|
||||
|
||||
$this->logger = new NullLogger();
|
||||
|
||||
|
@ -83,7 +88,7 @@ class StorageManagerTest extends DatabaseTest
|
|||
$configModel = new Repository\Config($this->dba);
|
||||
$this->config = new PreloadConfig($configCache, $configModel);
|
||||
$this->config->set('storage', 'name', 'Database');
|
||||
$this->config->set('storage', 'filesystem_path', $this->root->getChild(Storage\FilesystemConfig::DEFAULT_BASE_FOLDER)->url());
|
||||
$this->config->set('storage', 'filesystem_path', $this->root->getChild(Type\FilesystemConfig::DEFAULT_BASE_FOLDER)->url());
|
||||
|
||||
$this->l10n = \Mockery::mock(L10n::class);
|
||||
|
||||
|
@ -92,7 +97,7 @@ class StorageManagerTest extends DatabaseTest
|
|||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->root->removeChild(Storage\FilesystemConfig::DEFAULT_BASE_FOLDER);
|
||||
$this->root->removeChild(Type\FilesystemConfig::DEFAULT_BASE_FOLDER);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
@ -113,30 +118,30 @@ class StorageManagerTest extends DatabaseTest
|
|||
'empty' => [
|
||||
'name' => '',
|
||||
'valid' => false,
|
||||
'interface' => Storage\IStorage::class,
|
||||
'interface' => ICanReadFromStorage::class,
|
||||
'assert' => null,
|
||||
'assertName' => '',
|
||||
],
|
||||
'database' => [
|
||||
'name' => Storage\Database::NAME,
|
||||
'name' => Type\Database::NAME,
|
||||
'valid' => true,
|
||||
'interface' => Storage\IWritableStorage::class,
|
||||
'assert' => Storage\Database::class,
|
||||
'assertName' => Storage\Database::NAME,
|
||||
'interface' => ICanWriteToStorage::class,
|
||||
'assert' => Type\Database::class,
|
||||
'assertName' => Type\Database::NAME,
|
||||
],
|
||||
'filesystem' => [
|
||||
'name' => Storage\Filesystem::NAME,
|
||||
'name' => Filesystem::NAME,
|
||||
'valid' => true,
|
||||
'interface' => Storage\IWritableStorage::class,
|
||||
'assert' => Storage\Filesystem::class,
|
||||
'assertName' => Storage\Filesystem::NAME,
|
||||
'interface' => ICanWriteToStorage::class,
|
||||
'assert' => Filesystem::class,
|
||||
'assertName' => Filesystem::NAME,
|
||||
],
|
||||
'systemresource' => [
|
||||
'name' => Storage\SystemResource::NAME,
|
||||
'name' => SystemResource::NAME,
|
||||
'valid' => true,
|
||||
'interface' => Storage\IStorage::class,
|
||||
'assert' => Storage\SystemResource::class,
|
||||
'assertName' => Storage\SystemResource::NAME,
|
||||
'interface' => ICanReadFromStorage::class,
|
||||
'assert' => SystemResource::class,
|
||||
'assertName' => SystemResource::NAME,
|
||||
],
|
||||
'invalid' => [
|
||||
'name' => 'invalid',
|
||||
|
@ -157,16 +162,16 @@ class StorageManagerTest extends DatabaseTest
|
|||
public function testGetByName($name, $valid, $interface, $assert, $assertName)
|
||||
{
|
||||
if (!$valid) {
|
||||
$this->expectException(Storage\InvalidClassStorageException::class);
|
||||
$this->expectException(InvalidClassStorageException::class);
|
||||
}
|
||||
|
||||
if ($interface === Storage\IWritableStorage::class) {
|
||||
if ($interface === ICanWriteToStorage::class) {
|
||||
$this->config->set('storage', 'name', $name);
|
||||
}
|
||||
|
||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
||||
|
||||
if ($interface === Storage\IWritableStorage::class) {
|
||||
if ($interface === ICanWriteToStorage::class) {
|
||||
$storage = $storageManager->getWritableStorageByName($name);
|
||||
} else {
|
||||
$storage = $storageManager->getByName($name);
|
||||
|
@ -189,8 +194,8 @@ class StorageManagerTest extends DatabaseTest
|
|||
// true in every of the backends
|
||||
self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
|
||||
|
||||
// if it's a IWritableStorage, the valid backend should return true, otherwise false
|
||||
self::assertEquals($interface === Storage\IWritableStorage::class, $storageManager->isValidBackend($name, StorageManager::DEFAULT_BACKENDS));
|
||||
// if it's a ICanWriteToStorage, the valid backend should return true, otherwise false
|
||||
self::assertEquals($interface === ICanWriteToStorage::class, $storageManager->isValidBackend($name, StorageManager::DEFAULT_BACKENDS));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,8 +215,8 @@ class StorageManagerTest extends DatabaseTest
|
|||
*/
|
||||
public function testGetBackend($name, $valid, $interface, $assert, $assertName)
|
||||
{
|
||||
if ($interface !== Storage\IWritableStorage::class) {
|
||||
static::markTestSkipped('only works for IWritableStorage');
|
||||
if ($interface !== ICanWriteToStorage::class) {
|
||||
static::markTestSkipped('only works for ICanWriteToStorage');
|
||||
}
|
||||
|
||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
||||
|
@ -230,8 +235,8 @@ class StorageManagerTest extends DatabaseTest
|
|||
public function testPresetBackend($name, $valid, $interface, $assert, $assertName)
|
||||
{
|
||||
$this->config->set('storage', 'name', $name);
|
||||
if ($interface !== Storage\IWritableStorage::class) {
|
||||
$this->expectException(Storage\InvalidClassStorageException::class);
|
||||
if ($interface !== ICanWriteToStorage::class) {
|
||||
$this->expectException(InvalidClassStorageException::class);
|
||||
}
|
||||
|
||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
||||
|
@ -250,7 +255,7 @@ class StorageManagerTest extends DatabaseTest
|
|||
{
|
||||
/// @todo Remove dice once "Hook" is dynamic and mockable
|
||||
$dice = (new Dice())
|
||||
->addRules(include __DIR__ . '/../../../static/dependencies.config.php')
|
||||
->addRules(include __DIR__ . '/../../../../../static/dependencies.config.php')
|
||||
->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
|
||||
->addRule(IHandleSessions::class, ['instanceOf' => Session\Type\Memory::class, 'shared' => true, 'call' => null]);
|
||||
DI::init($dice);
|
||||
|
@ -278,7 +283,7 @@ class StorageManagerTest extends DatabaseTest
|
|||
{
|
||||
/// @todo Remove dice once "Hook" is dynamic and mockable
|
||||
$dice = (new Dice())
|
||||
->addRules(include __DIR__ . '/../../../static/dependencies.config.php')
|
||||
->addRules(include __DIR__ . '/../../../../../static/dependencies.config.php')
|
||||
->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
|
||||
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
|
||||
DI::init($dice);
|
||||
|
@ -303,7 +308,7 @@ class StorageManagerTest extends DatabaseTest
|
|||
|
||||
self::assertInstanceOf(SampleStorageBackend::class, $storageManager->getBackend());
|
||||
|
||||
self::expectException(Storage\StorageException::class);
|
||||
self::expectException(\Friendica\Core\Storage\Exception\StorageException::class);
|
||||
self::expectExceptionMessage('Cannot unregister Sample Storage, because it\'s currently active.');
|
||||
|
||||
$storageManager->unregister(SampleStorageBackend::class);
|
||||
|
@ -316,11 +321,11 @@ class StorageManagerTest extends DatabaseTest
|
|||
*/
|
||||
public function testMoveStorage($name, $valid, $interface, $assert, $assertName)
|
||||
{
|
||||
if ($interface !== Storage\IWritableStorage::class) {
|
||||
if ($interface !== ICanWriteToStorage::class) {
|
||||
self::markTestSkipped("No user backend");
|
||||
}
|
||||
|
||||
$this->loadFixture(__DIR__ . '/../../datasets/storage/database.fixture.php', $this->dba);
|
||||
$this->loadFixture(__DIR__ . '/../../../../datasets/storage/database.fixture.php', $this->dba);
|
||||
|
||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
||||
$storage = $storageManager->getWritableStorageByName($name);
|
||||
|
@ -343,11 +348,11 @@ class StorageManagerTest extends DatabaseTest
|
|||
*/
|
||||
public function testWrongWritableStorage()
|
||||
{
|
||||
$this->expectException(Storage\InvalidClassStorageException::class);
|
||||
$this->expectException(InvalidClassStorageException::class);
|
||||
$this->expectExceptionMessage('Backend SystemResource is not valid');
|
||||
|
||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
||||
$storage = $storageManager->getWritableStorageByName(Storage\SystemResource::getName());
|
||||
$storage = $storageManager->getWritableStorageByName(SystemResource::getName());
|
||||
$storageManager->move($storage);
|
||||
}
|
||||
}
|
|
@ -19,17 +19,17 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Model\Storage;
|
||||
namespace Friendica\Test\src\Core\Storage;
|
||||
|
||||
use Friendica\Model\Storage\IStorageConfiguration;
|
||||
use Friendica\Core\Storage\Capability\ICanConfigureStorage;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
abstract class StorageConfigTest extends MockedTest
|
||||
{
|
||||
/** @return IStorageConfiguration */
|
||||
/** @return \Friendica\Core\Storage\Capability\ICanConfigureStorage */
|
||||
abstract protected function getInstance();
|
||||
|
||||
abstract protected function assertOption(IStorageConfiguration $storage);
|
||||
abstract protected function assertOption(\Friendica\Core\Storage\Capability\ICanConfigureStorage $storage);
|
||||
|
||||
/**
|
||||
* Test if the "getOption" is asserted
|
|
@ -19,16 +19,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Model\Storage;
|
||||
namespace Friendica\Test\src\Core\Storage;
|
||||
|
||||
use Friendica\Model\Storage\IWritableStorage;
|
||||
use Friendica\Model\Storage\IStorage;
|
||||
use Friendica\Model\Storage\ReferenceStorageException;
|
||||
use Friendica\Core\Storage\Capability\ICanReadFromStorage;
|
||||
use Friendica\Core\Storage\Capability\ICanWriteToStorage;
|
||||
use Friendica\Core\Storage\Exception\ReferenceStorageException;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
abstract class StorageTest extends MockedTest
|
||||
{
|
||||
/** @return IWritableStorage */
|
||||
/** @return ICanWriteToStorage */
|
||||
abstract protected function getInstance();
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ abstract class StorageTest extends MockedTest
|
|||
public function testInstance()
|
||||
{
|
||||
$instance = $this->getInstance();
|
||||
self::assertInstanceOf(IStorage::class, $instance);
|
||||
self::assertInstanceOf(ICanReadFromStorage::class, $instance);
|
||||
}
|
||||
|
||||
/**
|
Loading…
Add table
Add a link
Reference in a new issue