Adapt filesystem tests
This commit is contained in:
parent
ccd8895237
commit
7471b7698b
|
@ -54,7 +54,7 @@ class Filesystem implements IWritableStorage
|
||||||
$this->basePath = rtrim($path, '/');
|
$this->basePath = rtrim($path, '/');
|
||||||
|
|
||||||
if (!is_dir($this->basePath) || !is_writable($this->basePath)) {
|
if (!is_dir($this->basePath) || !is_writable($this->basePath)) {
|
||||||
throw new StorageException(sprintf('Path %s does not exist or is not writeable', $this->basePath));
|
throw new StorageException(sprintf('Path "%s" does not exist or is not writeable.', $this->basePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
use Friendica\Util\ConfigFileLoader;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
use org\bovigo\vfs\vfsStream;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
use Friendica\Test\Util\SampleStorageBackend;
|
use Friendica\Test\Util\SampleStorageBackend;
|
||||||
|
@ -64,6 +65,8 @@ class StorageManagerTest extends DatabaseTest
|
||||||
|
|
||||||
$this->setUpVfsDir();
|
$this->setUpVfsDir();
|
||||||
|
|
||||||
|
vfsStream::newDirectory(Storage\FilesystemConfig::DEFAULT_BASE_FOLDER, 0777)->at($this->root);
|
||||||
|
|
||||||
$this->logger = new NullLogger();
|
$this->logger = new NullLogger();
|
||||||
|
|
||||||
$profiler = \Mockery::mock(Profiler::class);
|
$profiler = \Mockery::mock(Profiler::class);
|
||||||
|
@ -81,12 +84,20 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$configModel = new Config($this->dba);
|
$configModel = new Config($this->dba);
|
||||||
$this->config = new PreloadConfig($configCache, $configModel);
|
$this->config = new PreloadConfig($configCache, $configModel);
|
||||||
$this->config->set('storage', 'name', 'Database');
|
$this->config->set('storage', 'name', 'Database');
|
||||||
|
$this->config->set('storage', 'filesystem_path', $this->root->getChild(Storage\FilesystemConfig::DEFAULT_BASE_FOLDER)->url());
|
||||||
|
|
||||||
$this->l10n = \Mockery::mock(L10n::class);
|
$this->l10n = \Mockery::mock(L10n::class);
|
||||||
|
|
||||||
$this->httpRequest = \Mockery::mock(HTTPClient::class);
|
$this->httpRequest = \Mockery::mock(HTTPClient::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
$this->root->removeChild(Storage\FilesystemConfig::DEFAULT_BASE_FOLDER);
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test plain instancing first
|
* Test plain instancing first
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
namespace Friendica\Test\src\Model\Storage;
|
namespace Friendica\Test\src\Model\Storage;
|
||||||
|
|
||||||
use Friendica\Model\Storage\Filesystem;
|
use Friendica\Model\Storage\Filesystem;
|
||||||
|
use Friendica\Model\Storage\FilesystemConfig;
|
||||||
use Friendica\Model\Storage\StorageException;
|
use Friendica\Model\Storage\StorageException;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use org\bovigo\vfs\vfsStream;
|
use org\bovigo\vfs\vfsStream;
|
||||||
|
@ -41,20 +42,34 @@ class FilesystemStorageTest extends StorageTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
return new Filesystem($this->root->getChild('storage')->url());
|
return new Filesystem($this->root->getChild(FilesystemConfig::DEFAULT_BASE_FOLDER)->url());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the exception in case of missing directorsy permissions
|
* Test the exception in case of missing directory permissions during put new files
|
||||||
|
*/
|
||||||
|
public function testMissingDirPermissionsDuringPut()
|
||||||
|
{
|
||||||
|
$this->expectException(StorageException::class);
|
||||||
|
$this->expectExceptionMessageMatches("/Filesystem storage failed to create \".*\". Check you write permissions./");
|
||||||
|
$this->root->getChild(FilesystemConfig::DEFAULT_BASE_FOLDER)->chmod(0777);
|
||||||
|
|
||||||
|
$instance = $this->getInstance();
|
||||||
|
|
||||||
|
$this->root->getChild(FilesystemConfig::DEFAULT_BASE_FOLDER)->chmod(0000);
|
||||||
|
$instance->put('test');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the exception in case the directory isn't writeable
|
||||||
*/
|
*/
|
||||||
public function testMissingDirPermissions()
|
public function testMissingDirPermissions()
|
||||||
{
|
{
|
||||||
$this->expectException(StorageException::class);
|
$this->expectException(StorageException::class);
|
||||||
$this->expectExceptionMessageMatches("/Filesystem storage failed to create \".*\". Check you write permissions./");
|
$this->expectExceptionMessageMatches("/Path \".*\" does not exist or is not writeable./");
|
||||||
$this->root->getChild('storage')->chmod(000);
|
$this->root->getChild(FilesystemConfig::DEFAULT_BASE_FOLDER)->chmod(0000);
|
||||||
|
|
||||||
$instance = $this->getInstance();
|
$this->getInstance();
|
||||||
$instance->put('test');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user