1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Spiral\Tests\Storage\Unit\Builder; |
6
|
|
|
|
7
|
|
|
use League\Flysystem\AwsS3V3\AwsS3V3Adapter; |
8
|
|
|
use League\Flysystem\Local\LocalFilesystemAdapter; |
9
|
|
|
use League\Flysystem\PathPrefixer; |
10
|
|
|
use League\Flysystem\UnixVisibility\PortableVisibilityConverter; |
11
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
12
|
|
|
use Spiral\Storage\Builder\AdapterFactory; |
13
|
|
|
use Spiral\Storage\Config\DTO\FileSystemInfo; |
14
|
|
|
use Spiral\Storage\Exception\StorageException; |
15
|
|
|
use Spiral\Tests\Storage\Traits\AwsS3FsBuilderTrait; |
16
|
|
|
use Spiral\Tests\Storage\Traits\LocalFsBuilderTrait; |
17
|
|
|
use Spiral\Tests\Storage\Unit\UnitTestCase; |
18
|
|
|
|
19
|
|
|
class AdapterFactoryTest extends UnitTestCase |
20
|
|
|
{ |
21
|
|
|
use LocalFsBuilderTrait; |
22
|
|
|
use AwsS3FsBuilderTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @throws StorageException |
26
|
|
|
*/ |
27
|
|
|
public function testBuildSimpleLocalFs(): void |
28
|
|
|
{ |
29
|
|
|
$info = $this->buildLocalInfo(); |
30
|
|
|
|
31
|
|
|
$adapter = AdapterFactory::build($info); |
32
|
|
|
|
33
|
|
|
$this->assertInstanceOf(LocalFilesystemAdapter::class, $adapter); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @throws StorageException |
38
|
|
|
* @throws \ReflectionException |
39
|
|
|
*/ |
40
|
|
|
public function testBuildAdvancedLocalFs(): void |
41
|
|
|
{ |
42
|
|
|
$options = [ |
43
|
|
|
FileSystemInfo\LocalInfo::ROOT_DIR_KEY => self::ROOT_DIR, |
44
|
|
|
FileSystemInfo\LocalInfo::HOST_KEY => self::CONFIG_HOST, |
45
|
|
|
FileSystemInfo\LocalInfo::WRITE_FLAGS_KEY => LOCK_NB, |
46
|
|
|
FileSystemInfo\LocalInfo::LINK_HANDLING_KEY => LocalFilesystemAdapter::SKIP_LINKS, |
47
|
|
|
FileSystemInfo\LocalInfo::VISIBILITY_KEY => [ |
48
|
|
|
'file' => [ |
49
|
|
|
'public' => 0777, |
50
|
|
|
'private' => 0644, |
51
|
|
|
], |
52
|
|
|
'dir' => [ |
53
|
|
|
'public' => 0776, |
54
|
|
|
'private' => 0444, |
55
|
|
|
], |
56
|
|
|
], |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
$info = new FileSystemInfo\LocalInfo( |
60
|
|
|
'debugLocal', |
61
|
|
|
[ |
62
|
|
|
FileSystemInfo\LocalInfo::ADAPTER_KEY => LocalFilesystemAdapter::class, |
63
|
|
|
FileSystemInfo\LocalInfo::OPTIONS_KEY => $options, |
64
|
|
|
] |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$adapter = AdapterFactory::build($info); |
68
|
|
|
|
69
|
|
|
$this->assertInstanceOf(LocalFilesystemAdapter::class, $adapter); |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
$this->assertEquals( |
73
|
|
|
$options[FileSystemInfo\LocalInfo::LINK_HANDLING_KEY], |
74
|
|
|
$this->getNotPublicProperty($adapter, 'linkHandling') |
|
|
|
|
75
|
|
|
); |
76
|
|
|
$this->assertEquals( |
77
|
|
|
$options[FileSystemInfo\LocalInfo::WRITE_FLAGS_KEY], |
78
|
|
|
$this->getNotPublicProperty($adapter, 'writeFlags') |
|
|
|
|
79
|
|
|
); |
80
|
|
|
$this->assertEquals( |
81
|
|
|
PortableVisibilityConverter::fromArray($options[FileSystemInfo\LocalInfo::VISIBILITY_KEY]), |
|
|
|
|
82
|
|
|
$this->getNotPublicProperty($adapter, 'visibility') |
|
|
|
|
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @throws StorageException |
88
|
|
|
* @throws \ReflectionException |
89
|
|
|
*/ |
90
|
|
|
public function testBuildSimpleAwsS3Fs(): void |
91
|
|
|
{ |
92
|
|
|
$fsDescription = $this->buildAwsS3ServerDescription(); |
93
|
|
|
$fsInfo = new FileSystemInfo\Aws\AwsS3Info('awsS3', $fsDescription); |
94
|
|
|
|
95
|
|
|
$adapter = AdapterFactory::build($fsInfo); |
96
|
|
|
|
97
|
|
|
$this->assertInstanceOf(AwsS3V3Adapter::class, $adapter); |
98
|
|
|
|
99
|
|
|
$this->assertEquals( |
100
|
|
|
$fsDescription[FileSystemInfo\Aws\AwsS3Info::OPTIONS_KEY][FileSystemInfo\Aws\AwsS3Info::BUCKET_KEY], |
101
|
|
|
$this->getNotPublicProperty($adapter, 'bucket') |
|
|
|
|
102
|
|
|
); |
103
|
|
|
$this->assertSame( |
104
|
|
|
$fsInfo->getClient(), |
105
|
|
|
$this->getNotPublicProperty($adapter, 'client') |
|
|
|
|
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @throws StorageException |
111
|
|
|
* @throws \ReflectionException |
112
|
|
|
*/ |
113
|
|
|
public function testBuildAdvancedAwsS3Fs(): void |
114
|
|
|
{ |
115
|
|
|
$options = [ |
116
|
|
|
FileSystemInfo\Aws\AwsS3Info::BUCKET_KEY => 'testBucket', |
117
|
|
|
FileSystemInfo\Aws\AwsS3Info::CLIENT_KEY => $this->getAwsS3Client(), |
118
|
|
|
FileSystemInfo\Aws\AwsS3Info::PATH_PREFIX_KEY => '/some/prefix/', |
119
|
|
|
FileSystemInfo\Aws\AwsS3Info::VISIBILITY_KEY => $this->getAwsS3VisibilityOption(), |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
$info = new FileSystemInfo\Aws\AwsS3Info( |
123
|
|
|
'debugAwsS3', |
124
|
|
|
[ |
125
|
|
|
FileSystemInfo\LocalInfo::ADAPTER_KEY => AwsS3V3Adapter::class, |
126
|
|
|
FileSystemInfo\LocalInfo::OPTIONS_KEY => $options, |
127
|
|
|
] |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$adapter = AdapterFactory::build($info); |
131
|
|
|
|
132
|
|
|
$this->assertInstanceOf(AwsS3V3Adapter::class, $adapter); |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
$this->assertEquals( |
136
|
|
|
new PathPrefixer($options[FileSystemInfo\Aws\AwsS3Info::PATH_PREFIX_KEY]), |
137
|
|
|
$this->getNotPublicProperty($adapter, 'prefixer') |
|
|
|
|
138
|
|
|
); |
139
|
|
|
$this->assertEquals( |
140
|
|
|
$info->getVisibilityConverter(), |
141
|
|
|
$this->getNotPublicProperty($adapter, 'visibility') |
|
|
|
|
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function testWrongFsInfoUsage(): void |
146
|
|
|
{ |
147
|
|
|
$this->expectException(StorageException::class); |
148
|
|
|
$this->expectExceptionMessage('Adapter can\'t be built by filesystem info'); |
149
|
|
|
|
150
|
|
|
/** @var MockObject|FileSystemInfo\FileSystemInfo $info */ |
151
|
|
|
$info = $this->getMockForAbstractClass( |
152
|
|
|
FileSystemInfo\FileSystemInfo::class, |
153
|
|
|
[ |
154
|
|
|
'someName', |
155
|
|
|
[ |
156
|
|
|
FileSystemInfo\FileSystemInfo::ADAPTER_KEY => LocalFilesystemAdapter::class, |
157
|
|
|
FileSystemInfo\FileSystemInfo::OPTIONS_KEY => [], |
158
|
|
|
], |
159
|
|
|
] |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
AdapterFactory::build($info); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.