1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Freyo\Flysystem\QcloudCOSv3\Tests; |
4
|
|
|
|
5
|
|
|
use League\Flysystem\Config; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Freyo\Flysystem\QcloudCOSv3\Adapter; |
8
|
|
|
|
9
|
|
|
class AdapterTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function Provider() |
12
|
|
|
{ |
13
|
|
|
$config = [ |
14
|
|
|
'protocol' => 'http', |
15
|
|
|
'domain' => 'your-domain', |
16
|
|
|
'app_id' => 'your-app-id', |
17
|
|
|
'secret_id' => 'your-secret-id', |
18
|
|
|
'secret_key' => 'your-secret-key', |
19
|
|
|
'timeout' => 60, |
20
|
|
|
'bucket' => 'your-bucket-name', |
21
|
|
|
'debug' => true, |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
$adapter = new Adapter($config); |
25
|
|
|
|
26
|
|
|
return [ |
27
|
|
|
[$adapter, $config], |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @dataProvider Provider |
33
|
|
|
*/ |
34
|
|
|
public function testWrite($adapter) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
//$this->assertTrue((bool)$adapter->write('foo/foo.md', 'content', new Config(['insertOnly' => 0]))); |
|
|
|
|
37
|
|
|
//$this->assertFalse((bool)$adapter->write('foo/foo.md', uniqid(), new Config(['insertOnly' => 1]))); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @dataProvider Provider |
42
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function testWriteStream($adapter) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$temp = tmpfile(); |
47
|
|
|
fwrite($temp, "writing to tempfile"); |
48
|
|
|
$this->assertTrue((bool)$adapter->writeStream('foo/bar.md', $temp, new Config(['insertOnly' => 0]))); |
49
|
|
|
fclose($temp); |
50
|
|
|
|
51
|
|
|
$temp = tmpfile(); |
52
|
|
|
fwrite($temp, uniqid()); |
53
|
|
|
$this->assertFalse((bool)$adapter->writeStream('foo/bar.md', $temp, new Config(['insertOnly' => 1]))); |
54
|
|
|
fclose($temp); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @dataProvider Provider |
59
|
|
|
*/ |
60
|
|
|
public function testUpdate($adapter) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
//$this->assertTrue((bool)$adapter->update('foo/bar.md', uniqid(), new Config(['insertOnly' => 0]))); |
|
|
|
|
63
|
|
|
//$this->assertFalse((bool)$adapter->update('foo/bar.md', uniqid(), new Config(['insertOnly' => 1]))); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @dataProvider Provider |
68
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function testUpdateStream($adapter) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$temp = tmpfile(); |
73
|
|
|
fwrite($temp, "writing to tempfile"); |
74
|
|
|
$this->assertTrue((bool)$adapter->updateStream('foo/bar.md', $temp, new Config(['insertOnly' => 0]))); |
75
|
|
|
fclose($temp); |
76
|
|
|
|
77
|
|
|
$temp = tmpfile(); |
78
|
|
|
fwrite($temp, uniqid()); |
79
|
|
|
$this->assertFalse((bool)$adapter->updateStream('foo/bar.md', $temp, new Config(['insertOnly' => 1]))); |
80
|
|
|
fclose($temp); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @dataProvider Provider |
85
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
86
|
|
|
*/ |
87
|
|
|
public function testRename($adapter) |
88
|
|
|
{ |
89
|
|
|
$this->assertTrue($adapter->rename('foo/foo.md', 'foo/rename.md')); |
90
|
|
|
$this->assertFalse($adapter->rename('foo/notexist.md', 'foo/notexist.md')); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @dataProvider Provider |
95
|
|
|
*/ |
96
|
|
|
public function testCopy($adapter) |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
//$this->assertTrue($adapter->copy('foo/bar.md', 'foo/copy.md')); |
|
|
|
|
99
|
|
|
//$this->assertFalse($adapter->copy('foo/notexist.md', 'foo/notexist.md')); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @dataProvider Provider |
104
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
105
|
|
|
*/ |
106
|
|
|
public function testDelete($adapter) |
107
|
|
|
{ |
108
|
|
|
$this->assertTrue($adapter->delete('foo/rename.md')); |
109
|
|
|
$this->assertFalse($adapter->delete('foo/notexist.md')); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @dataProvider Provider |
114
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
115
|
|
|
*/ |
116
|
|
|
public function testCreateDir($adapter) |
117
|
|
|
{ |
118
|
|
|
$this->assertTrue((bool)$adapter->createDir('bar', new Config())); |
119
|
|
|
$this->assertFalse((bool)$adapter->createDir('bar', new Config())); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @dataProvider Provider |
124
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
125
|
|
|
*/ |
126
|
|
|
public function testDeleteDir($adapter) |
127
|
|
|
{ |
128
|
|
|
$this->assertTrue($adapter->deleteDir('bar')); |
129
|
|
|
$this->assertFalse($adapter->deleteDir('notexist')); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @dataProvider Provider |
134
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
135
|
|
|
*/ |
136
|
|
|
public function testSetVisibility($adapter) |
137
|
|
|
{ |
138
|
|
|
$this->assertTrue($adapter->setVisibility('foo/copy.md', 'private')); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @dataProvider Provider |
143
|
|
|
*/ |
144
|
|
|
public function testHas($adapter) |
145
|
|
|
{ |
146
|
|
|
//$this->assertTrue($adapter->has('foo/bar.md')); |
|
|
|
|
147
|
|
|
$this->assertFalse($adapter->has('foo/noexist.md')); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @dataProvider Provider |
152
|
|
|
*/ |
153
|
|
|
public function testRead($adapter) |
|
|
|
|
154
|
|
|
{ |
155
|
|
|
//$this->assertArrayHasKey('contents', $adapter->read('foo/bar.md')); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @dataProvider Provider |
160
|
|
|
*/ |
161
|
|
|
public function testGetUrl($adapter, $config) |
162
|
|
|
{ |
163
|
|
|
$this->assertSame( |
164
|
|
|
$config['protocol'] . '://' . $config['domain'] . '/foo/bar.md', |
165
|
|
|
$adapter->getUrl('foo/bar.md') |
166
|
|
|
); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @dataProvider Provider |
171
|
|
|
*/ |
172
|
|
|
public function testReadStream($adapter) |
|
|
|
|
173
|
|
|
{ |
174
|
|
|
//$this->assertSame( |
175
|
|
|
// stream_get_contents(fopen($adapter->getUrl('foo/bar.md'), 'r')), |
|
|
|
|
176
|
|
|
// stream_get_contents($adapter->readStream('foo/bar.md')['stream']) |
|
|
|
|
177
|
|
|
//); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @dataProvider Provider |
182
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
183
|
|
|
*/ |
184
|
|
|
public function testListContents($adapter) |
185
|
|
|
{ |
186
|
|
|
$this->assertArrayHasKey('infos', $adapter->listContents('foo')); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @dataProvider Provider |
191
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
192
|
|
|
*/ |
193
|
|
|
public function testGetMetadata($adapter) |
194
|
|
|
{ |
195
|
|
|
$this->assertArrayHasKey('access_url', $adapter->getMetadata('foo/bar.md')); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @dataProvider Provider |
200
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
201
|
|
|
*/ |
202
|
|
|
public function testGetSize($adapter) |
203
|
|
|
{ |
204
|
|
|
$this->assertArrayHasKey('size', $adapter->getSize('foo/bar.md')); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @dataProvider Provider |
209
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
210
|
|
|
*/ |
211
|
|
|
public function testGetMimetype($adapter) |
212
|
|
|
{ |
213
|
|
|
$this->assertNotSame(['mimetype' => ''], $adapter->getMimetype('foo/bar.md')); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @dataProvider Provider |
218
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
219
|
|
|
*/ |
220
|
|
|
public function testGetTimestamp($adapter) |
221
|
|
|
{ |
222
|
|
|
$this->assertNotSame(['timestamp' => 0], $adapter->getTimestamp('foo/bar.md')); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @dataProvider Provider |
227
|
|
|
* @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException |
228
|
|
|
*/ |
229
|
|
|
public function testGetVisibility($adapter) |
230
|
|
|
{ |
231
|
|
|
$this->assertSame(['visibility' => 'private'], $adapter->getVisibility('foo/copy.md')); |
232
|
|
|
} |
233
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.