|
1
|
|
|
<?php |
|
2
|
|
|
namespace RazonYang\Yii2\Flysystem\Tests; |
|
3
|
|
|
|
|
4
|
|
|
use Codeception\Test\Unit; |
|
5
|
|
|
use RazonYang\Yii2\Flysystem\AliyunOssFilesystem; |
|
6
|
|
|
use yii\base\InvalidArgumentException; |
|
7
|
|
|
|
|
8
|
|
|
class AliyunOssFilesystemTest extends Unit |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @dataProvider dataInit |
|
12
|
|
|
*/ |
|
13
|
|
|
public function testInit(string $accessKeyId, string $accessKeySecret, string $endpoint, string $bucket, ?\Throwable $exception = null): void |
|
14
|
|
|
{ |
|
15
|
|
|
if ($exception) { |
|
16
|
|
|
$this->expectException(get_class($exception)); |
|
17
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
|
18
|
|
|
$this->createFlysystem($accessKeyId, $accessKeySecret, $endpoint, $bucket); |
|
19
|
|
|
return; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
$filesystem = $this->createFlysystem($accessKeyId, $accessKeySecret, $endpoint, $bucket); |
|
23
|
|
|
$this->assertSame($accessKeyId, $filesystem->getAccessKeyId()); |
|
24
|
|
|
$this->assertSame($accessKeySecret, $filesystem->getAccessKeySecret()); |
|
25
|
|
|
$this->assertSame($endpoint, $filesystem->getEndpoint()); |
|
26
|
|
|
$this->assertSame($bucket, $filesystem->getBucket()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function dataInit(): array |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
['', 'secret', 'endpoint', 'bucket', new InvalidArgumentException('accessKeyId is required')], |
|
33
|
|
|
['accessKeyId', '', 'endpoint', 'bucket', new InvalidArgumentException('accessKeySecret is required')], |
|
34
|
|
|
['accessKeyId', 'secret', '', 'bucket', new InvalidArgumentException('endpoint is required')], |
|
35
|
|
|
['accessKeyId', 'secret', 'endpoint', '', new InvalidArgumentException('bucket is required')], |
|
36
|
|
|
['accessKeyId', 'secret', 'endpoint', 'bucket'], |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function createFlysystem(string $accessKeyId, string $accessKeySecret, string $endpoint, string $bucket): AliyunOssFilesystem |
|
41
|
|
|
{ |
|
42
|
|
|
return new AliyunOssFilesystem([ |
|
43
|
|
|
'accessKeyId' => $accessKeyId, |
|
44
|
|
|
'accessKeySecret' => $accessKeySecret, |
|
45
|
|
|
'endpoint' => $endpoint, |
|
46
|
|
|
'bucket' => $bucket, |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @dataProvider dataSetGet |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testSetGet( |
|
54
|
|
|
string $accessKeyId, |
|
55
|
|
|
string $accessKeySecret, |
|
56
|
|
|
string $endpoint, |
|
57
|
|
|
bool $isCName, |
|
58
|
|
|
string $securityToken, |
|
59
|
|
|
string $bucket, |
|
60
|
|
|
string $prefix, |
|
61
|
|
|
array $options |
|
62
|
|
|
): void { |
|
63
|
|
|
$filesystem = $this->createFlysystem('1', '2', '3', '4'); |
|
64
|
|
|
$filesystem->setAccessKeyId($accessKeyId); |
|
65
|
|
|
$this->assertSame($accessKeyId, $filesystem->getAccessKeyId()); |
|
66
|
|
|
|
|
67
|
|
|
$filesystem->setAccessKeySecret($accessKeySecret); |
|
68
|
|
|
$this->assertSame($accessKeySecret, $filesystem->getAccessKeySecret()); |
|
69
|
|
|
|
|
70
|
|
|
$filesystem->setEndpoint($endpoint); |
|
71
|
|
|
$this->assertSame($endpoint, $filesystem->getEndpoint()); |
|
72
|
|
|
|
|
73
|
|
|
$filesystem->setIsCName($isCName); |
|
74
|
|
|
$this->assertSame($isCName, $filesystem->getIsCName()); |
|
75
|
|
|
|
|
76
|
|
|
$filesystem->setSecurityToken($securityToken); |
|
77
|
|
|
$this->assertSame($securityToken, $filesystem->getSecurityToken()); |
|
78
|
|
|
|
|
79
|
|
|
$filesystem->setBucket($bucket); |
|
80
|
|
|
$this->assertSame($bucket, $filesystem->getBucket()); |
|
81
|
|
|
|
|
82
|
|
|
$filesystem->setPrefix($prefix); |
|
83
|
|
|
$this->assertSame($prefix, $filesystem->getPrefix()); |
|
84
|
|
|
|
|
85
|
|
|
$filesystem->setOptions($options); |
|
86
|
|
|
$this->assertSame($options, $filesystem->getOptions()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function dataSetGet(): array |
|
90
|
|
|
{ |
|
91
|
|
|
return [ |
|
92
|
|
|
['id', 'secret1', 'endpoint1', false, 'token1', 'bucket1', 'prefix1', []], |
|
93
|
|
|
['id2', 'secret2', 'endpoint2', true, 'token2', 'bucket2', 'prefix2', ['k1' => 'v1']], |
|
94
|
|
|
]; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|