Add DEVELOP flag for StorageManager for testing purpose only
This commit is contained in:
parent
9bcd0ffac8
commit
150e3a6f42
|
@ -80,11 +80,12 @@ class StorageManager
|
||||||
* @param IManageConfigValues $config
|
* @param IManageConfigValues $config
|
||||||
* @param LoggerInterface $logger
|
* @param LoggerInterface $logger
|
||||||
* @param L10n $l10n
|
* @param L10n $l10n
|
||||||
|
* @param bool $includeAddon (DEVELOP ONLY) Used for testing only - avoids loading addons because of DB direct access
|
||||||
*
|
*
|
||||||
* @throws InvalidClassStorageException in case the active backend class is invalid
|
* @throws InvalidClassStorageException in case the active backend class is invalid
|
||||||
* @throws StorageException in case of unexpected errors during the active backend class loading
|
* @throws StorageException in case of unexpected errors during the active backend class loading
|
||||||
*/
|
*/
|
||||||
public function __construct(Database $dba, IManageConfigValues $config, LoggerInterface $logger, L10n $l10n)
|
public function __construct(Database $dba, IManageConfigValues $config, LoggerInterface $logger, L10n $l10n, bool $includeAddon = true)
|
||||||
{
|
{
|
||||||
$this->dba = $dba;
|
$this->dba = $dba;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
@ -96,8 +97,10 @@ class StorageManager
|
||||||
|
|
||||||
/// @fixme Loading the addons & hooks here is really bad practice, but solves https://github.com/friendica/friendica/issues/11178
|
/// @fixme Loading the addons & hooks here is really bad practice, but solves https://github.com/friendica/friendica/issues/11178
|
||||||
/// clean solution = Making Addon & Hook dynamic and load them inside the constructor, so there's no custom load logic necessary anymore
|
/// clean solution = Making Addon & Hook dynamic and load them inside the constructor, so there's no custom load logic necessary anymore
|
||||||
Addon::loadAddons();
|
if ($includeAddon) {
|
||||||
Hook::loadHooks();
|
Addon::loadAddons();
|
||||||
|
Hook::loadHooks();
|
||||||
|
}
|
||||||
|
|
||||||
// you can only use user backends as a "default" backend, so the second parameter is true
|
// you can only use user backends as a "default" backend, so the second parameter is true
|
||||||
$this->currentBackend = $this->getWritableStorageByName($currentName);
|
$this->currentBackend = $this->getWritableStorageByName($currentName);
|
||||||
|
|
|
@ -40,7 +40,6 @@ use Friendica\DI;
|
||||||
use Friendica\Core\Config\Factory\Config;
|
use Friendica\Core\Config\Factory\Config;
|
||||||
use Friendica\Core\Config\Repository;
|
use Friendica\Core\Config\Repository;
|
||||||
use Friendica\Core\Storage\Type;
|
use Friendica\Core\Storage\Type;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClient;
|
|
||||||
use Friendica\Test\DatabaseTest;
|
use Friendica\Test\DatabaseTest;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
|
@ -61,8 +60,6 @@ class StorageManagerTest extends DatabaseTest
|
||||||
private $logger;
|
private $logger;
|
||||||
/** @var L10n */
|
/** @var L10n */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
/** @var HttpClient */
|
|
||||||
private $httpRequest;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
@ -92,8 +89,6 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$this->config->set('storage', 'filesystem_path', $this->root->getChild(Type\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);
|
$this->l10n = \Mockery::mock(L10n::class);
|
||||||
|
|
||||||
$this->httpRequest = \Mockery::mock(HttpClient::class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
|
@ -108,7 +103,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testInstance()
|
public function testInstance()
|
||||||
{
|
{
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
|
|
||||||
self::assertInstanceOf(StorageManager::class, $storageManager);
|
self::assertInstanceOf(StorageManager::class, $storageManager);
|
||||||
}
|
}
|
||||||
|
@ -170,7 +165,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$this->config->set('storage', 'name', $name);
|
$this->config->set('storage', 'name', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
|
|
||||||
if ($interface === ICanWriteToStorage::class) {
|
if ($interface === ICanWriteToStorage::class) {
|
||||||
$storage = $storageManager->getWritableStorageByName($name);
|
$storage = $storageManager->getWritableStorageByName($name);
|
||||||
|
@ -190,7 +185,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testIsValidBackend($name, $valid, $interface, $assert, $assertName)
|
public function testIsValidBackend($name, $valid, $interface, $assert, $assertName)
|
||||||
{
|
{
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
|
|
||||||
// true in every of the backends
|
// true in every of the backends
|
||||||
self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
|
self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
|
||||||
|
@ -204,7 +199,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testListBackends()
|
public function testListBackends()
|
||||||
{
|
{
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
|
|
||||||
self::assertEquals(StorageManager::DEFAULT_BACKENDS, $storageManager->listBackends());
|
self::assertEquals(StorageManager::DEFAULT_BACKENDS, $storageManager->listBackends());
|
||||||
}
|
}
|
||||||
|
@ -220,7 +215,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
static::markTestSkipped('only works for ICanWriteToStorage');
|
static::markTestSkipped('only works for ICanWriteToStorage');
|
||||||
}
|
}
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
|
|
||||||
$selBackend = $storageManager->getWritableStorageByName($name);
|
$selBackend = $storageManager->getWritableStorageByName($name);
|
||||||
$storageManager->setBackend($selBackend);
|
$storageManager->setBackend($selBackend);
|
||||||
|
@ -240,7 +235,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$this->expectException(InvalidClassStorageException::class);
|
$this->expectException(InvalidClassStorageException::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
|
|
||||||
self::assertInstanceOf($assert, $storageManager->getBackend());
|
self::assertInstanceOf($assert, $storageManager->getBackend());
|
||||||
}
|
}
|
||||||
|
@ -261,7 +256,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
|
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
|
||||||
DI::init($dice);
|
DI::init($dice);
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
|
|
||||||
self::assertTrue($storageManager->register(SampleStorageBackend::class));
|
self::assertTrue($storageManager->register(SampleStorageBackend::class));
|
||||||
|
|
||||||
|
@ -289,7 +284,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
|
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
|
||||||
DI::init($dice);
|
DI::init($dice);
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
|
|
||||||
self::assertTrue($storageManager->register(SampleStorageBackend::class));
|
self::assertTrue($storageManager->register(SampleStorageBackend::class));
|
||||||
|
|
||||||
|
@ -328,7 +323,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
|
|
||||||
$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);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
$storage = $storageManager->getWritableStorageByName($name);
|
$storage = $storageManager->getWritableStorageByName($name);
|
||||||
$storageManager->move($storage);
|
$storageManager->move($storage);
|
||||||
|
|
||||||
|
@ -352,7 +347,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$this->expectException(InvalidClassStorageException::class);
|
$this->expectException(InvalidClassStorageException::class);
|
||||||
$this->expectExceptionMessage('Backend SystemResource is not valid');
|
$this->expectExceptionMessage('Backend SystemResource is not valid');
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, false);
|
||||||
$storage = $storageManager->getWritableStorageByName(SystemResource::getName());
|
$storage = $storageManager->getWritableStorageByName(SystemResource::getName());
|
||||||
$storageManager->move($storage);
|
$storageManager->move($storage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user