Note: In this example I doesn't use the flysystem Memory or Null adpater, because the Memory adapter doesn't implement the getPathPrefix
method, like the AbstractAdapter
does. For this reason I use the Local
adapter in LOCK_NB
mode in combination with vfsStream
to simulate the filesystem in-memory.
composer require mikey179/vfsstream --dev
Add this method to your phpunit test trait:
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Adapter\Local;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
// ...
protected function mockFilesystem(): Filesystem
{
$root = vfsStream::setup();
$rootPath = $root->url();
// Must not be LOCK_EX, because LOCK_EX is not supported by vfsstream.
// We are running tests in-memory, so LOCK_EX is not important here.
$adapter = new Local($rootPath, LOCK_NB, FileStorageAdapter::DISALLOW_LINKS, [
'file' => [
'public' => 0777,
'private' => 0777,
],
'dir' => [
'public' => 0777,
'private' => 0777,
],
]);
return new Filesystem($adapter);
}