|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\DataFile\Test\Unit\Node\FileSystem; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\DataFile\Node\FileSystem\FilesystemWrapper; |
|
6
|
|
|
use Graze\DataFile\Node\FileSystem\FilesystemWrapperInterface; |
|
7
|
|
|
use Graze\DataFile\Test\TestCase; |
|
8
|
|
|
use InvalidArgumentException; |
|
9
|
|
|
use League\Flysystem\AdapterInterface; |
|
10
|
|
|
use League\Flysystem\Filesystem; |
|
11
|
|
|
use League\Flysystem\FilesystemInterface; |
|
12
|
|
|
use League\Flysystem\Handler; |
|
13
|
|
|
use League\Flysystem\PluginInterface; |
|
14
|
|
|
use Mockery as m; |
|
15
|
|
|
|
|
16
|
|
|
class FilesystemWrapperTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testInstanceOf() |
|
19
|
|
|
{ |
|
20
|
|
|
$filesystem = m::mock(FilesystemInterface::class); |
|
21
|
|
|
$wrapper = new FilesystemWrapper($filesystem); |
|
22
|
|
|
|
|
23
|
|
|
static::assertInstanceOf(FilesystemWrapperInterface::class, $wrapper); |
|
24
|
|
|
static::assertNotInstanceOf(FilesystemWrapperInterface::class, $filesystem); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testGetAdapter() |
|
28
|
|
|
{ |
|
29
|
|
|
$filesystem = m::mock(Filesystem::class); |
|
30
|
|
|
$adapter = m::mock(AdapterInterface::class); |
|
31
|
|
|
$filesystem->shouldReceive('getAdapter') |
|
32
|
|
|
->andReturn($adapter); |
|
33
|
|
|
$wrapper = new FilesystemWrapper($filesystem); |
|
34
|
|
|
|
|
35
|
|
|
static::assertSame($adapter, $wrapper->getAdapter()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetAdapterWithANonFileSystemWillThrowAnException() |
|
39
|
|
|
{ |
|
40
|
|
|
$filesystem = m::mock(FileSystemInterface::class); |
|
41
|
|
|
$wrapper = new FilesystemWrapper($filesystem); |
|
42
|
|
|
|
|
43
|
|
|
static::expectException(InvalidArgumentException::class); |
|
44
|
|
|
$wrapper->getAdapter(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testAllMethodsGetPassedToFileSystem() |
|
48
|
|
|
{ |
|
49
|
|
|
$fileSystem = m::mock(FilesystemInterface::class); |
|
50
|
|
|
$wrapper = new FilesystemWrapper($fileSystem); |
|
51
|
|
|
|
|
52
|
|
|
$methods = [ |
|
53
|
|
|
'has' => ['some/path'], |
|
54
|
|
|
'read' => ['some/path'], |
|
55
|
|
|
'readStream' => ['some/path'], |
|
56
|
|
|
'listContents' => ['some/path', false], |
|
57
|
|
|
'getMetadata' => ['some/path'], |
|
58
|
|
|
'getSize' => ['some/path'], |
|
59
|
|
|
'getMimetype' => ['some/path'], |
|
60
|
|
|
'getTimestamp' => ['some/path'], |
|
61
|
|
|
'getVisibility' => ['some/path'], |
|
62
|
|
|
'write' => ['some/path', 'contents', []], |
|
63
|
|
|
'writeStream' => ['some/path', 'resource', []], |
|
64
|
|
|
'update' => ['some/path', 'contents', []], |
|
65
|
|
|
'updateStream' => ['some/path', 'resource', []], |
|
66
|
|
|
'rename' => ['some/path', 'some/newpath'], |
|
67
|
|
|
'copy' => ['some/path', 'some/newpath'], |
|
68
|
|
|
'delete' => ['some/path'], |
|
69
|
|
|
'deleteDir' => ['some/path'], |
|
70
|
|
|
'createDir' => ['some/path', []], |
|
71
|
|
|
'setVisibility' => ['some/path', 'public'], |
|
72
|
|
|
'put' => ['some/path', 'contents', []], |
|
73
|
|
|
'putStream' => ['some/path', 'resource', []], |
|
74
|
|
|
'readAndDelete' => ['some/path'], |
|
75
|
|
|
'get' => ['some/path', m::mock(Handler::class)], |
|
76
|
|
|
'addPlugin' => [m::mock(PluginInterface::class)], |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
foreach ($methods as $method => $args) { |
|
80
|
|
|
$fileSystem->shouldReceive($method) |
|
81
|
|
|
->withArgs($args) |
|
82
|
|
|
->once(); |
|
83
|
|
|
call_user_func_array([$wrapper, $method], $args); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|