|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Gaufrette\Extras\Resolvable; |
|
4
|
|
|
|
|
5
|
|
|
use Gaufrette\Extras\Resolvable\ResolvableFilesystem; |
|
6
|
|
|
use Gaufrette\Extras\Resolvable\ResolverInterface; |
|
7
|
|
|
use Gaufrette\Extras\Resolvable\UnresolvableObjectException; |
|
8
|
|
|
use Gaufrette\File; |
|
9
|
|
|
use Gaufrette\FilesystemInterface; |
|
10
|
|
|
use Gaufrette\Stream; |
|
11
|
|
|
use PhpSpec\ObjectBehavior; |
|
12
|
|
|
|
|
13
|
|
|
class ResolvableFilesystemSpec extends ObjectBehavior |
|
14
|
|
|
{ |
|
15
|
|
|
function let(MockedFilesystem $decorated, ResolverInterface $resolver) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->beConstructedWith($decorated, $resolver); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
function it_is_initializable() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->shouldHaveType(ResolvableFilesystem::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
function it_is_a_filesystem() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->shouldImplement(FilesystemInterface::class); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function it_resolves_object_path_into_uri($resolver) |
|
31
|
|
|
{ |
|
32
|
|
|
$resolver->resolve('foo')->willReturn('https://yolo.com/my_image.png'); |
|
33
|
|
|
$this->resolve('foo')->shouldReturn('https://yolo.com/my_image.png'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_throws_unresolvable_object_exception_if_any_error_happen_during_resolution($resolver) |
|
37
|
|
|
{ |
|
38
|
|
|
$resolver->resolve('foo')->willThrow(\Exception::class); |
|
39
|
|
|
$this->shouldThrow(UnresolvableObjectException::class)->duringResolve('foo'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
function it_delegates_has_to_decorated_filesystem($decorated) |
|
43
|
|
|
{ |
|
44
|
|
|
$decorated->has('foo')->willReturn(true); |
|
45
|
|
|
$this->has('foo')->shouldReturn(true); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_delegates_rename_to_decorated_filesystem($decorated) |
|
49
|
|
|
{ |
|
50
|
|
|
$decorated->rename('foo', 'bar')->willReturn(true); |
|
51
|
|
|
$this->rename('foo', 'bar')->shouldReturn(true); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function it_delegates_get_to_decorated_filesystem($decorated, File $file) |
|
55
|
|
|
{ |
|
56
|
|
|
$decorated->get('foo', true)->willReturn($file); |
|
57
|
|
|
$this->get('foo', true)->shouldReturn($file); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
function it_delegates_write_to_decorated_filesystem($decorated) |
|
61
|
|
|
{ |
|
62
|
|
|
$decorated->write('foo', 'content', true)->willReturn(7); |
|
63
|
|
|
$this->write('foo', 'content', true)->shouldReturn(7); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
function it_delegates_read_to_decorated_filesystem($decorated) |
|
67
|
|
|
{ |
|
68
|
|
|
$decorated->read('foo')->willReturn('content'); |
|
69
|
|
|
$this->read('foo')->shouldReturn('content'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
function it_delegates_delete_to_decorated_filesystem($decorated) |
|
73
|
|
|
{ |
|
74
|
|
|
$decorated->delete('foo')->willReturn(true); |
|
75
|
|
|
$this->delete('foo')->shouldReturn(true); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
function it_delegates_keys_to_decorated_filesystem($decorated) |
|
79
|
|
|
{ |
|
80
|
|
|
$decorated->keys()->willReturn(['foo', 'bar']); |
|
81
|
|
|
$this->keys()->shouldReturn(['foo', 'bar']); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
function it_delegates_list_keys_to_decorated_filesystem($decorated) |
|
85
|
|
|
{ |
|
86
|
|
|
$decorated->listKeys('aze/*')->willReturn(['keys' => ['foo', 'bar']]); |
|
87
|
|
|
$this->listKeys('aze/*')->shouldReturn(['keys' => ['foo', 'bar']]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function it_delegates_mime_type_retrieval_to_decorated_filesystem($decorated) |
|
91
|
|
|
{ |
|
92
|
|
|
$decorated->mtime('foo')->willReturn(123); |
|
93
|
|
|
$this->mtime('foo')->shouldReturn(123); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
function it_delegates_checksum_computation_to_decorated_filesystem($decorated) |
|
97
|
|
|
{ |
|
98
|
|
|
$decorated->checksum('foo')->willReturn('abcdef'); |
|
99
|
|
|
$this->checksum('foo')->shouldReturn('abcdef'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
function it_delegates_size_computation_to_decorated_filesystem($decorated) |
|
103
|
|
|
{ |
|
104
|
|
|
$decorated->size('foo')->willReturn(123); |
|
105
|
|
|
$this->size('foo')->shouldReturn(123); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
function it_delegates_stream_creation_to_decorated_filesystem($decorated, Stream $stream) |
|
109
|
|
|
{ |
|
110
|
|
|
$decorated->createStream('foo')->willReturn($stream); |
|
111
|
|
|
$this->createStream('foo')->shouldReturn($stream); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
function it_delegates_file_creation_to_decorated_filesystem($decorated, File $file) |
|
115
|
|
|
{ |
|
116
|
|
|
$decorated->createFile('foo')->willReturn($file); |
|
117
|
|
|
$this->createFile('foo')->shouldReturn($file); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
function it_delegates_mime_type_guessing_to_decorated_filesystem($decorated) |
|
121
|
|
|
{ |
|
122
|
|
|
$decorated->mimeType('foo')->willReturn('application/json'); |
|
123
|
|
|
$this->mimeType('foo')->shouldReturn('application/json'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
function it_delegates_is_directory_to_delegated_filesystem($decorated) |
|
127
|
|
|
{ |
|
128
|
|
|
$decorated->isDirectory('foo')->willReturn(false); |
|
129
|
|
|
$this->isDirectory('foo')->shouldReturn(false); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
function it_delegates_any_other_method_call_to_decorated_filesystem($decorated) |
|
133
|
|
|
{ |
|
134
|
|
|
$decorated->otherMethod()->shouldBeCalled(); |
|
135
|
|
|
|
|
136
|
|
|
$this->otherMethod(); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
interface MockedFilesystem extends FilesystemInterface { |
|
|
|
|
|
|
141
|
|
|
public function otherMethod(); |
|
142
|
|
|
} |
|
143
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.