namespace Friendica\Test\Util;
use Friendica\Core\Hook;
-use Friendica\Model\Storage\IStorage;
+use Friendica\Model\Storage\ISelectableStorage;
use Friendica\Core\L10n;
/**
* A backend storage example class
*/
-class SampleStorageBackend implements IStorage
+class SampleStorageBackend implements ISelectableStorage
{
const NAME = 'Sample Storage';
$this->l10n = $l10n;
}
- public function get(string $reference)
+ public function get(string $reference): string
{
// we return always the same image data. Which file we load is defined by
// a config key
- return $this->data[$reference] ?? null;
+ return $this->data[$reference] ?? '';
}
- public function put(string $data, string $reference = '')
+ public function put(string $data, string $reference = ''): string
{
if ($reference === '') {
$reference = 'sample';
return true;
}
- public function getOptions()
+ public function getOptions(): array
{
return $this->options;
}
- public function saveOptions(array $data)
+ public function saveOptions(array $data): array
{
$this->options = $data;
return self::NAME;
}
- public static function getName()
+ public static function getName(): string
{
return self::NAME;
}
Hook::register('storage_instance', __DIR__ . '/SampleStorageBackendInstance.php', 'create_instance');
}
}
-
{
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
- $storage = $storageManager->getByName($name, $userBackend);
+ if ($userBackend) {
+ $storage = $storageManager->getSelectableStorageByName($name);
+ } else {
+ $storage = $storageManager->getByName($name);
+ }
if (!empty($assert)) {
self::assertInstanceOf(Storage\IStorage::class, $storage);
*/
public function testIsValidBackend($name, $assert, $assertName, $userBackend)
{
- $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
+ $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
// true in every of the backends
self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
*/
public function testListBackends()
{
- $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
+ $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
self::assertEquals(StorageManager::DEFAULT_BACKENDS, $storageManager->listBackends());
}
*/
public function testGetBackend($name, $assert, $assertName, $userBackend)
{
- $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
+ $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
self::assertNull($storageManager->getBackend());
if ($userBackend) {
- $storageManager->setBackend($name);
+ $selBackend = $storageManager->getSelectableStorageByName($name);
+ $storageManager->setBackend($selBackend);
self::assertInstanceOf($assert, $storageManager->getBackend());
}
{
$this->config->set('storage', 'name', $name);
- $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
+ $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
if ($userBackend) {
self::assertInstanceOf($assert, $storageManager->getBackend());
->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
DI::init($dice);
- $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
+ $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
self::assertTrue($storageManager->register(SampleStorageBackend::class));
SampleStorageBackend::registerHook();
Hook::loadHooks();
- self::assertTrue($storageManager->setBackend(SampleStorageBackend::NAME));
+ self::assertTrue($storageManager->setBackend( $storageManager->getSelectableStorageByName(SampleStorageBackend::NAME)));
self::assertEquals(SampleStorageBackend::NAME, $this->config->get('storage', 'name'));
self::assertInstanceOf(SampleStorageBackend::class, $storageManager->getBackend());
$this->loadFixture(__DIR__ . '/../../datasets/storage/database.fixture.php', $this->dba);
- $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
+ $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
$storage = $storageManager->getSelectableStorageByName($name);
$storageManager->move($storage);
/**
* Test moving data to a WRONG storage
*/
- public function testMoveStorageWrong()
+ public function testWrongSelectableStorage()
{
- $this->expectExceptionMessage("Can't move to storage backend 'SystemResource'");
- $this->expectException(StorageException::class);
+ $this->expectException(\TypeError::class);
- $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
+ $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
$storage = $storageManager->getSelectableStorageByName(Storage\SystemResource::getName());
$storageManager->move($storage);
}
namespace Friendica\Test\src\Model\Storage;
use Friendica\Model\Storage\IStorage;
+use Friendica\Model\Storage\ReferenceStorageException;
+use Friendica\Model\Storage\StorageException;
use Friendica\Test\MockedTest;
abstract class StorageTest extends MockedTest
self::assertEquals('data12345', $instance->get($ref));
- self::assertTrue($instance->delete($ref));
+ $instance->delete($ref);
}
/**
*/
public function testInvalidDelete()
{
+ self::expectException(ReferenceStorageException::class);
+
$instance = $this->getInstance();
- // Even deleting not existing references should return "true"
- self::assertTrue($instance->delete(-1234456));
+ $instance->delete(-1234456);
}
/**
*/
public function testInvalidGet()
{
+ self::expectException(ReferenceStorageException::class);
+
$instance = $this->getInstance();
- // Invalid references return an empty string
- self::assertEmpty($instance->get(-123456));
+ $instance->get(-123456);
}
/**