Initial commit
This commit is contained in:
commit
d09a91dfaa
|
@ -0,0 +1 @@
|
|||
/vendor/
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "zoomyboy/filesystem-tests",
|
||||
"description": "Tests filesystems",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Zoomyboy\\FilesystemTests\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Philipp Lang",
|
||||
"email": "philipp@zoomyboy.de"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "5432d073dea9577fe882d9516969dceb",
|
||||
"packages": [],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.2.0"
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\FilesystemTests;
|
||||
|
||||
use Illuminate\Filesystem\FilesystemManager;
|
||||
use \Mockery as M;
|
||||
|
||||
class FilesystemConfig
|
||||
{
|
||||
|
||||
public string $host;
|
||||
public string $username;
|
||||
public string $password;
|
||||
public string $path;
|
||||
public StorageType $type;
|
||||
|
||||
public function host(string $host): self
|
||||
{
|
||||
$this->host = $host;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function password(string $password): self
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function username(string $username): self
|
||||
{
|
||||
$this->username = $username;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function path(string $path): self
|
||||
{
|
||||
$this->path = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function type(StorageType $type): self
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function swap(): void
|
||||
{
|
||||
if (!app()->has('original-filesystem')) {
|
||||
app()->singleton('original-filesystem', fn () => app(FilesystemManager::class));
|
||||
$mock = M::mock(FilesystemManager::class)->makePartial();
|
||||
app()->instance(FilesystemManager::class, $mock);
|
||||
}
|
||||
|
||||
$mock = app(FilesystemManager::class);
|
||||
|
||||
if ($this->type === StorageType::FTP) {
|
||||
$mock->shouldReceive('createFtpDriver')->withArgs(fn ($config) => $this->host === $config['host'] && $this->username === $config['username'] && $this->password === $config['password'] && $this->path === $config['root'])
|
||||
->andReturnUsing(function () {
|
||||
return app('original-filesystem')->createLocalDriver(['root' => __DIR__ . '/fakes']);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\FilesystemTests;
|
||||
|
||||
enum StorageType
|
||||
{
|
||||
|
||||
case FTP;
|
||||
case FTPS;
|
||||
case SFTP;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\FilesystemTests;
|
||||
|
||||
trait TestsFilesystems
|
||||
{
|
||||
|
||||
public $mockedSystems = [];
|
||||
public bool $mocked = false;
|
||||
|
||||
public function mockFilesystem(string $identifier): FilesystemConfig
|
||||
{
|
||||
$this->beforeApplicationDestroyed(function () {
|
||||
});
|
||||
return $this->mockedSystems[$identifier] = data_get($this->mockedSystems, $identifier, new FilesystemConfig($identifier));
|
||||
}
|
||||
|
||||
public function clearFilesystems(): void
|
||||
{
|
||||
exec('rm -R ' . __DIR__ . '/fakes/*');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue