]> git.mxchange.org Git - friendica.git/commitdiff
Add ExternalStorage dependency to StorageManager
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 28 Jun 2021 02:39:02 +0000 (22:39 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 28 Jun 2021 03:15:46 +0000 (23:15 -0400)
- Since ExternalStorage isn't instantiated automatically by Dice, we have to provide the dependency manually in StorageManager->getByName
- This requires StorageManager to take one one additional dependency
- Tests are updated with this additional dependency

src/Core/StorageManager.php
tests/src/Core/StorageManagerTest.php

index b8cde14bd0c1397a1d96391605adae401912545b..64e53c10b9f1f62883fa28c23919809774c8947e 100644 (file)
@@ -25,6 +25,7 @@ use Exception;
 use Friendica\Core\Config\IConfig;
 use Friendica\Database\Database;
 use Friendica\Model\Storage;
+use Friendica\Network\IHTTPRequest;
 use Psr\Log\LoggerInterface;
 
 
@@ -60,6 +61,8 @@ class StorageManager
        private $logger;
        /** @var L10n */
        private $l10n;
+       /** @var IHTTPRequest */
+       private $httpRequest;
 
        /** @var Storage\IStorage */
        private $currentBackend;
@@ -70,12 +73,13 @@ class StorageManager
         * @param LoggerInterface $logger
         * @param L10n            $l10n
         */
-       public function __construct(Database $dba, IConfig $config, LoggerInterface $logger, L10n $l10n)
+       public function __construct(Database $dba, IConfig $config, LoggerInterface $logger, L10n $l10n, IHTTPRequest $httpRequest)
        {
-               $this->dba      = $dba;
-               $this->config   = $config;
-               $this->logger   = $logger;
-               $this->l10n     = $l10n;
+               $this->dba         = $dba;
+               $this->config      = $config;
+               $this->logger      = $logger;
+               $this->l10n        = $l10n;
+               $this->httpRequest = $httpRequest;
                $this->backends = $config->get('storage', 'backends', self::DEFAULT_BACKENDS);
 
                $currentName = $this->config->get('storage', 'name', '');
@@ -127,7 +131,7 @@ class StorageManager
                                                $this->backendInstances[$name] = new Storage\SystemResource();
                                                break;
                                        case Storage\ExternalResource::getName():
-                                               $this->backendInstances[$name] = new Storage\ExternalResource();
+                                               $this->backendInstances[$name] = new Storage\ExternalResource($this->httpRequest);
                                                break;
                                        default:
                                                $data = [
index d2078c7e2a085c94cd08ee883df71ce33b2e56d0..618b5e33c4b753c81fd971597522065c637012f9 100644 (file)
@@ -35,6 +35,7 @@ use Friendica\Model\Config\Config;
 use Friendica\Model\Storage;
 use Friendica\Core\Session;
 use Friendica\Model\Storage\StorageException;
+use Friendica\Network\HTTPRequest;
 use Friendica\Test\DatabaseTest;
 use Friendica\Test\Util\Database\StaticDatabase;
 use Friendica\Test\Util\VFSTrait;
@@ -54,6 +55,8 @@ class StorageManagerTest extends DatabaseTest
        private $logger;
        /** @var L10n */
        private $l10n;
+       /** @var HTTPRequest */
+       private $httpRequest;
 
        use VFSTrait;
 
@@ -79,6 +82,8 @@ class StorageManagerTest extends DatabaseTest
                $this->config = new PreloadConfig($configCache, $configModel);
 
                $this->l10n = \Mockery::mock(L10n::class);
+
+               $this->httpRequest = \Mockery::mock(HTTPRequest::class);
        }
 
        /**
@@ -86,7 +91,7 @@ class StorageManagerTest extends DatabaseTest
         */
        public function testInstance()
        {
-               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
+               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
 
                self::assertInstanceOf(StorageManager::class, $storageManager);
        }
@@ -168,7 +173,7 @@ class StorageManagerTest extends DatabaseTest
         */
        public function testGetByName($name, $assert, $assertName, $userBackend)
        {
-               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
+               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
 
                $storage = $storageManager->getByName($name, $userBackend);
 
@@ -188,7 +193,7 @@ class StorageManagerTest extends DatabaseTest
         */
        public function testIsValidBackend($name, $assert, $assertName, $userBackend)
        {
-               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
+               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
 
                // true in every of the backends
                self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
@@ -202,7 +207,7 @@ class StorageManagerTest extends DatabaseTest
         */
        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, $this->httpRequest);
 
                self::assertEquals(StorageManager::DEFAULT_BACKENDS, $storageManager->listBackends());
        }
@@ -214,7 +219,7 @@ class StorageManagerTest extends DatabaseTest
         */
        public function testGetBackend($name, $assert, $assertName, $userBackend)
        {
-               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
+               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
 
                self::assertNull($storageManager->getBackend());
 
@@ -235,7 +240,7 @@ class StorageManagerTest extends DatabaseTest
        {
                $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, $this->httpRequest);
 
                if ($userBackend) {
                        self::assertInstanceOf($assert, $storageManager->getBackend());
@@ -260,7 +265,7 @@ class StorageManagerTest extends DatabaseTest
                        ->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);
+               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
 
                self::assertTrue($storageManager->register(SampleStorageBackend::class));
 
@@ -301,7 +306,7 @@ class StorageManagerTest extends DatabaseTest
 
                $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, $this->httpRequest);
                $storage = $storageManager->getByName($name);
                $storageManager->move($storage);
 
@@ -326,7 +331,7 @@ class StorageManagerTest extends DatabaseTest
                $this->expectExceptionMessage("Can't move to storage backend 'SystemResource'");
                $this->expectException(StorageException::class);
 
-               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
+               $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
                $storage = $storageManager->getByName(Storage\SystemResource::getName());
                $storageManager->move($storage);
        }