1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\units\BePark\Flysystem\ReadOnlyFallback; |
4
|
|
|
|
5
|
|
|
use League\Flysystem\AdapterInterface; |
6
|
|
|
use League\Flysystem\Config; |
7
|
|
|
|
8
|
|
|
class ReadOnlyFallbackAdapter extends \atoum\test |
9
|
|
|
{ |
10
|
|
|
public function testAdapters(AdapterInterface $mainAdapter, AdapterInterface $readOnlyAdapter) |
11
|
|
|
{ |
12
|
|
|
$this |
13
|
|
|
->given($this->newTestedInstance($mainAdapter, $readOnlyAdapter)) |
14
|
|
|
->then |
15
|
|
|
->object($this->testedInstance->getMainAdapter())->isIdenticalTo($mainAdapter) |
16
|
|
|
->object($this->testedInstance->getReadOnlyAdapter())->isIdenticalTo($readOnlyAdapter); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testHasPath(AdapterInterface $mainAdapter, AdapterInterface $readOnlyAdapter) |
20
|
|
|
{ |
21
|
|
|
$this |
22
|
|
|
->assert('test path existence on readOnly') |
23
|
|
|
->given( |
24
|
|
|
$this->newTestedInstance($mainAdapter, $readOnlyAdapter), |
25
|
|
|
$this->calling($readOnlyAdapter)->has = true, |
|
|
|
|
26
|
|
|
$this->calling($mainAdapter)->has = false |
|
|
|
|
27
|
|
|
) |
28
|
|
|
->then |
29
|
|
|
->boolean($this->testedInstance->has('/foo'))->isTrue |
30
|
|
|
->mock($readOnlyAdapter)->receive('has')->withIdenticalArguments('/foo')->once |
31
|
|
|
->mock($mainAdapter)->receive('has')->withIdenticalArguments('/foo')->once; |
32
|
|
|
|
33
|
|
|
$this |
34
|
|
|
->assert('test path existence on mainAdapter') |
35
|
|
|
->given($this->calling($mainAdapter)->has = true, |
|
|
|
|
36
|
|
|
$this->calling($readOnlyAdapter)->has = false) |
|
|
|
|
37
|
|
|
->then |
38
|
|
|
->boolean($this->testedInstance->has('/foo'))->isTrue |
39
|
|
|
->mock($mainAdapter)->receive('has')->withIdenticalArguments('/foo')->once |
40
|
|
|
->mock($readOnlyAdapter)->call('has')->never; |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
$this |
44
|
|
|
->assert('test none existing path') |
45
|
|
|
->given($this->calling($mainAdapter)->has = false, |
|
|
|
|
46
|
|
|
$this->calling($readOnlyAdapter)->has = false) |
|
|
|
|
47
|
|
|
->then |
48
|
|
|
->boolean($this->testedInstance->has('/foo'))->isFalse |
49
|
|
|
->mock($mainAdapter)->receive('has')->withIdenticalArguments('/foo')->once |
50
|
|
|
->mock($readOnlyAdapter)->receive('has')->withIdenticalArguments('/foo')->once; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testWriteAndWriteStream(AdapterInterface $mainAdapter, AdapterInterface $readOnlyAdapter) |
54
|
|
|
{ |
55
|
|
|
$this->calling($mainAdapter)->write = true; |
|
|
|
|
56
|
|
|
$this->calling($readOnlyAdapter)->write = false; |
|
|
|
|
57
|
|
|
|
58
|
|
|
$this->calling($mainAdapter)->writeStream = true; |
|
|
|
|
59
|
|
|
$this->calling($readOnlyAdapter)->writeStream = false; |
|
|
|
|
60
|
|
|
|
61
|
|
|
$this |
62
|
|
|
->assert('test write') |
63
|
|
|
->given($this->newTestedInstance($mainAdapter, $readOnlyAdapter)) |
64
|
|
|
->then |
65
|
|
|
->boolean($this->testedInstance->write('/foo', 'bar', new Config()))->isTrue |
66
|
|
|
->mock($readOnlyAdapter)->wasNotCalled |
67
|
|
|
->mock($mainAdapter)->receive('write')->withAtLeastArguments(['/foo', 'bar'])->once; |
68
|
|
|
|
69
|
|
|
$this |
70
|
|
|
->assert('test write stream') |
71
|
|
|
->given($this->newTestedInstance($mainAdapter, $readOnlyAdapter)) |
72
|
|
|
->then |
73
|
|
|
->boolean($this->testedInstance->writeStream('/foo', 'bar', new Config()))->isTrue |
74
|
|
|
->mock($readOnlyAdapter)->wasNotCalled |
75
|
|
|
->mock($mainAdapter)->receive('writeStream')->withAtLeastArguments(['/foo', 'bar'])->once; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testUpdate(AdapterInterface $mainAdapter, AdapterInterface $readOnlyAdapter) |
79
|
|
|
{ |
80
|
|
|
$this |
81
|
|
|
->assert('test update only on main if exist on main') |
82
|
|
|
->given( |
83
|
|
|
$this->newTestedInstance($mainAdapter, $readOnlyAdapter), |
84
|
|
|
$this->calling($mainAdapter)->has = true, |
|
|
|
|
85
|
|
|
$this->calling($readOnlyAdapter)->has = true, |
|
|
|
|
86
|
|
|
$this->calling($mainAdapter)->update = true |
|
|
|
|
87
|
|
|
) |
88
|
|
|
->then |
89
|
|
|
->boolean($this->testedInstance->update('/foo', 'bar', new Config()))->isTrue |
90
|
|
|
->mock($readOnlyAdapter)->wasNotCalled |
91
|
|
|
->mock($mainAdapter)->receive('update')->withAtLeastArguments(['/foo', 'bar'])->once; |
92
|
|
|
|
93
|
|
|
$this |
94
|
|
|
->assert('test update only on main but not exist on main') |
95
|
|
|
->given( |
96
|
|
|
$this->calling($mainAdapter)->has = false, |
|
|
|
|
97
|
|
|
$this->calling($readOnlyAdapter)->has = true, |
|
|
|
|
98
|
|
|
$this->calling($mainAdapter)->update = true |
|
|
|
|
99
|
|
|
) |
100
|
|
|
->then |
101
|
|
|
->boolean($this->testedInstance->update('/foo', 'bar', new Config()))->isTrue |
102
|
|
|
->mock($readOnlyAdapter)->call('update')->never |
103
|
|
|
->mock($mainAdapter)->receive('update')->withAtLeastArguments(['/foo', 'bar'])->once; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testDelete(AdapterInterface $mainAdapter, AdapterInterface $readOnlyAdapter) |
107
|
|
|
{ |
108
|
|
|
$this->newTestedInstance($mainAdapter, $readOnlyAdapter); |
109
|
|
|
|
110
|
|
|
$this->assert('test delete on non existing on main') |
111
|
|
|
->given( |
112
|
|
|
$this->calling($mainAdapter)->has = false, |
|
|
|
|
113
|
|
|
$this->calling($readOnlyAdapter)->has = true, |
|
|
|
|
114
|
|
|
$this->calling($mainAdapter)->delete = true |
|
|
|
|
115
|
|
|
) |
116
|
|
|
->boolean($this->testedInstance->delete('foo/bar'))->isTrue |
117
|
|
|
->mock($mainAdapter)->receive('delete')->never |
118
|
|
|
->mock($readOnlyAdapter)->receive('delete')->never; |
119
|
|
|
|
120
|
|
|
$this->assert('test delete on existing on main') |
121
|
|
|
->given( |
122
|
|
|
$this->calling($mainAdapter)->has = true, |
|
|
|
|
123
|
|
|
$this->calling($mainAdapter)->delete = true |
|
|
|
|
124
|
|
|
) |
125
|
|
|
->boolean($this->testedInstance->delete('foo/bar'))->isTrue |
126
|
|
|
->mock($mainAdapter)->receive('delete')->withIdenticalArguments('foo/bar')->once; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testRead(AdapterInterface $mainAdapter, AdapterInterface $readOnlyAdapter) |
130
|
|
|
{ |
131
|
|
|
$this->newTestedInstance($mainAdapter, $readOnlyAdapter); |
132
|
|
|
$this->assert('test read on existing on main') |
133
|
|
|
->given( |
134
|
|
|
$this->calling($readOnlyAdapter)->has = true, |
|
|
|
|
135
|
|
|
$this->calling($mainAdapter)->has = true, |
|
|
|
|
136
|
|
|
$this->calling($mainAdapter)->read = 'foo' |
|
|
|
|
137
|
|
|
) |
138
|
|
|
->string($this->testedInstance->read('foo/bar'))->isEqualTo('foo') |
139
|
|
|
->mock($readOnlyAdapter)->wasNotCalled; |
140
|
|
|
|
141
|
|
|
$this->assert('test read on existing only on read only') |
142
|
|
|
->given( |
143
|
|
|
$this->calling($readOnlyAdapter)->has = true, |
|
|
|
|
144
|
|
|
$this->calling($mainAdapter)->has = false, |
|
|
|
|
145
|
|
|
$this->calling($readOnlyAdapter)->read = 'baz', |
|
|
|
|
146
|
|
|
$this->calling($mainAdapter)->read = false |
|
|
|
|
147
|
|
|
) |
148
|
|
|
->string($this->testedInstance->read('foo/bar'))->isEqualTo('baz'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function testGetMetadata(AdapterInterface $mainAdapter, AdapterInterface $readOnlyAdapter) |
152
|
|
|
{ |
153
|
|
|
$this->given( |
154
|
|
|
$this->newTestedInstance($mainAdapter, $readOnlyAdapter), |
155
|
|
|
$this->calling($mainAdapter)->has = true, |
|
|
|
|
156
|
|
|
$this->calling($mainAdapter)->getMetadata = array('metadata') |
|
|
|
|
157
|
|
|
) |
158
|
|
|
->then |
159
|
|
|
->array($this->testedInstance->getMetadata('foo'))->isEqualTo(['metadata']) |
160
|
|
|
->mock($readOnlyAdapter)->wasNotCalled |
161
|
|
|
->mock($mainAdapter)->receive('getMetadata')->once; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function testListContent(AdapterInterface $mainAdapter, AdapterInterface $readOnlyAdapter) |
165
|
|
|
{ |
166
|
|
|
$a = [ |
167
|
|
|
[ |
168
|
|
|
'type' => 'file', |
169
|
|
|
'path' => 'foo', |
170
|
|
|
'size' => 0, |
171
|
|
|
'timestamp' => time(), |
172
|
|
|
], |
173
|
|
|
[ |
174
|
|
|
'type' => 'file', |
175
|
|
|
'path' => 'bar', |
176
|
|
|
'size' => 100, |
177
|
|
|
'timestamp' => time() - 100, |
178
|
|
|
], |
179
|
|
|
[ |
180
|
|
|
'type' => 'dir', |
181
|
|
|
'path' => 'baz', |
182
|
|
|
'size' => 0, |
183
|
|
|
'timestamp' => time() - 200, |
184
|
|
|
], |
185
|
|
|
]; |
186
|
|
|
|
187
|
|
|
$b = [ |
188
|
|
|
[ |
189
|
|
|
'type' => 'file', |
190
|
|
|
'path' => 'foo', |
191
|
|
|
'size' => 10, |
192
|
|
|
'timestamp' => time(), |
193
|
|
|
], |
194
|
|
|
[ |
195
|
|
|
'type' => 'file', |
196
|
|
|
'path' => 'baz', |
197
|
|
|
'size' => 150, |
198
|
|
|
'timestamp' => time() - 150, |
199
|
|
|
] |
200
|
|
|
]; |
201
|
|
|
|
202
|
|
|
$this->given( |
203
|
|
|
$this->newTestedInstance($mainAdapter, $readOnlyAdapter), |
204
|
|
|
$this->calling($mainAdapter)->listContents = $a, |
|
|
|
|
205
|
|
|
$this->calling($readOnlyAdapter)->listContents = $a |
|
|
|
|
206
|
|
|
) |
207
|
|
|
->then |
208
|
|
|
->array($this->testedInstance->listContents()) |
209
|
|
|
->isIdenticalTo($a + $b); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: