1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\units\BePark\Flysystem\ReadOnlyFallback; |
4
|
|
|
|
5
|
|
|
use League\Flysystem\Config; |
6
|
|
|
|
7
|
|
|
class ReadOnlyFallbackAdapter extends \atoum\test |
8
|
|
|
{ |
9
|
|
|
public function testAdapters() |
10
|
|
|
{ |
11
|
|
|
$readOnlyAdapter = $this->newMockInstance('\League\Flysystem\AdapterInterface'); |
12
|
|
|
$mainAdapter = $this->newMockInstance('\League\Flysystem\AdapterInterface'); |
13
|
|
|
|
14
|
|
|
$this |
15
|
|
|
->given($this->newTestedInstance($mainAdapter, $readOnlyAdapter)) |
16
|
|
|
->then |
17
|
|
|
->object($this->testedInstance->getMainAdapter())->isIdenticalTo($mainAdapter) |
18
|
|
|
->object($this->testedInstance->getReadOnlyAdapter())->isIdenticalTo($readOnlyAdapter); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testHasPath() |
22
|
|
|
{ |
23
|
|
|
$readOnlyAdapter = $this->newMockInstance('\League\Flysystem\AdapterInterface'); |
24
|
|
|
$mainAdapter = $this->newMockInstance('\League\Flysystem\AdapterInterface'); |
25
|
|
|
|
26
|
|
|
$this |
27
|
|
|
->assert('test path existence on readOnly') |
28
|
|
|
->given( |
29
|
|
|
$this->newTestedInstance($mainAdapter, $readOnlyAdapter), |
30
|
|
|
$this->calling($readOnlyAdapter)->has = true, |
|
|
|
|
31
|
|
|
$this->calling($mainAdapter)->has = false |
|
|
|
|
32
|
|
|
) |
33
|
|
|
->then |
34
|
|
|
->boolean($this->testedInstance->has('/foo'))->isTrue |
35
|
|
|
->mock($readOnlyAdapter)->receive('has')->withIdenticalArguments('/foo')->once |
36
|
|
|
->mock($mainAdapter)->receive('has')->withIdenticalArguments('/foo')->once; |
37
|
|
|
|
38
|
|
|
$this |
39
|
|
|
->assert('test path existence on mainAdapter') |
40
|
|
|
->given($this->calling($mainAdapter)->has = true, |
|
|
|
|
41
|
|
|
$this->calling($readOnlyAdapter)->has = false) |
|
|
|
|
42
|
|
|
->then |
43
|
|
|
->boolean($this->testedInstance->has('/foo'))->isTrue |
44
|
|
|
->mock($mainAdapter)->receive('has')->withIdenticalArguments('/foo')->once |
45
|
|
|
->mock($readOnlyAdapter)->call('has')->never; |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
$this |
49
|
|
|
->assert('test none existing path') |
50
|
|
|
->given($this->calling($mainAdapter)->has = false, |
|
|
|
|
51
|
|
|
$this->calling($readOnlyAdapter)->has = false) |
|
|
|
|
52
|
|
|
->then |
53
|
|
|
->boolean($this->testedInstance->has('/foo'))->isFalse |
54
|
|
|
->mock($mainAdapter)->receive('has')->withIdenticalArguments('/foo')->once |
55
|
|
|
->mock($readOnlyAdapter)->receive('has')->withIdenticalArguments('/foo')->once; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testWriteAndWriteStream() |
59
|
|
|
{ |
60
|
|
|
$readOnlyAdapter = $this->newMockInstance('\League\Flysystem\AdapterInterface'); |
61
|
|
|
$mainAdapter = $this->newMockInstance('\League\Flysystem\AdapterInterface'); |
62
|
|
|
|
63
|
|
|
$this->calling($mainAdapter)->write = true; |
|
|
|
|
64
|
|
|
$this->calling($readOnlyAdapter)->write = false; |
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->calling($mainAdapter)->writeStream = true; |
|
|
|
|
67
|
|
|
$this->calling($readOnlyAdapter)->writeStream = false; |
|
|
|
|
68
|
|
|
|
69
|
|
|
$this |
70
|
|
|
->assert('test write') |
71
|
|
|
->given($this->newTestedInstance($mainAdapter, $readOnlyAdapter)) |
72
|
|
|
->then |
73
|
|
|
->boolean($this->testedInstance->write('/foo', 'bar', new Config()))->isTrue |
74
|
|
|
->mock($readOnlyAdapter)->wasNotCalled |
75
|
|
|
->mock($mainAdapter)->receive('write')->withAtLeastArguments(['/foo', 'bar'])->once; |
76
|
|
|
|
77
|
|
|
$this |
78
|
|
|
->assert('test write stream') |
79
|
|
|
->given($this->newTestedInstance($mainAdapter, $readOnlyAdapter)) |
80
|
|
|
->then |
81
|
|
|
->boolean($this->testedInstance->write('/foo', 'bar', new Config()))->isTrue |
82
|
|
|
->mock($readOnlyAdapter)->wasNotCalled |
83
|
|
|
->mock($mainAdapter)->receive('writeStream')->withAtLeastArguments(['/foo', 'bar'])->once; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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: