|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Spiral\Tests\Storage\Unit\Config\DTO; |
|
6
|
|
|
|
|
7
|
|
|
use Spiral\Storage\Config\DTO\BucketInfo; |
|
8
|
|
|
use Spiral\Storage\Exception\StorageException; |
|
9
|
|
|
use Spiral\Tests\Storage\Traits\AwsS3FsBuilderTrait; |
|
10
|
|
|
use Spiral\Tests\Storage\Traits\LocalFsBuilderTrait; |
|
11
|
|
|
use Spiral\Tests\Storage\Unit\UnitTestCase; |
|
12
|
|
|
|
|
13
|
|
|
class BucketInfoTest extends UnitTestCase |
|
14
|
|
|
{ |
|
15
|
|
|
use LocalFsBuilderTrait; |
|
16
|
|
|
use AwsS3FsBuilderTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @throws StorageException |
|
20
|
|
|
*/ |
|
21
|
|
|
public function testGetDirectoryOption(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$directory = '/files/debug/'; |
|
24
|
|
|
|
|
25
|
|
|
$localInfo = $this->buildLocalInfo(); |
|
26
|
|
|
|
|
27
|
|
|
$dtoNull = new BucketInfo('dBucket', $localInfo->getName()); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertNull($dtoNull->getOption(BucketInfo::DIRECTORY_KEY)); |
|
30
|
|
|
|
|
31
|
|
|
$dto = new BucketInfo( |
|
32
|
|
|
'dBucket2', |
|
33
|
|
|
$localInfo->getName(), |
|
34
|
|
|
[ |
|
35
|
|
|
'server' => $localInfo->getName(), |
|
36
|
|
|
'options' => [ |
|
37
|
|
|
'directory' => $directory, |
|
38
|
|
|
], |
|
39
|
|
|
] |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertNull($dto->getFileSystemInfo()); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals($directory, $dto->getOption(BucketInfo::DIRECTORY_KEY)); |
|
45
|
|
|
|
|
46
|
|
|
$dto->setFileSystemInfo($localInfo); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertSame($localInfo, $dto->getFileSystemInfo()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @throws StorageException |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testGetBucket(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$bucket = 'awsBucket1'; |
|
57
|
|
|
|
|
58
|
|
|
$awsInfo = $this->buildAwsS3Info(); |
|
59
|
|
|
|
|
60
|
|
|
$dtoNull = new BucketInfo('dBucket', $awsInfo->getName()); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertNull($dtoNull->getOption(BucketInfo::BUCKET_KEY)); |
|
63
|
|
|
|
|
64
|
|
|
$dto = new BucketInfo( |
|
65
|
|
|
'dBucket2', |
|
66
|
|
|
$awsInfo->getName(), |
|
67
|
|
|
[ |
|
68
|
|
|
'server' => $awsInfo->getName(), |
|
69
|
|
|
'options' => [ |
|
70
|
|
|
'bucket' => $bucket, |
|
71
|
|
|
], |
|
72
|
|
|
] |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertNull($dto->getFileSystemInfo()); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertEquals($bucket, $dto->getOption(BucketInfo::BUCKET_KEY)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @throws StorageException |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testSetFileSystemInfo(): void |
|
84
|
|
|
{ |
|
85
|
|
|
$localInfo = $this->buildLocalInfo(); |
|
86
|
|
|
|
|
87
|
|
|
$dto = new BucketInfo( |
|
88
|
|
|
'dBucket2', |
|
89
|
|
|
$localInfo->getName(), |
|
90
|
|
|
[ |
|
91
|
|
|
'server' => $localInfo->getName(), |
|
92
|
|
|
'options' => [ |
|
93
|
|
|
'directory' => 'someDir/', |
|
94
|
|
|
], |
|
95
|
|
|
] |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertNull($dto->getFileSystemInfo()); |
|
99
|
|
|
|
|
100
|
|
|
$dto->setFileSystemInfo($localInfo); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertSame($localInfo, $dto->getFileSystemInfo()); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|