|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Framework\Storage; |
|
6
|
|
|
|
|
7
|
|
|
use League\Flysystem\FilesystemAdapter; |
|
8
|
|
|
use League\Flysystem\Local\LocalFilesystemAdapter; |
|
9
|
|
|
use Mockery as m; |
|
10
|
|
|
use Spiral\Bootloader\Storage\StorageConfig; |
|
11
|
|
|
use Spiral\Distribution\UriResolverInterface; |
|
12
|
|
|
use Spiral\Storage\BucketFactoryInterface; |
|
13
|
|
|
use Spiral\Storage\BucketInterface; |
|
14
|
|
|
use Spiral\Storage\StorageInterface; |
|
15
|
|
|
use Spiral\Tests\Framework\BaseTest; |
|
16
|
|
|
|
|
17
|
|
|
final class StorageBootloaderTest extends BaseTest |
|
18
|
|
|
{ |
|
19
|
|
|
private \Spiral\App\TestApp $app; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp(): void |
|
22
|
|
|
{ |
|
23
|
|
|
parent::setUp(); |
|
24
|
|
|
|
|
25
|
|
|
$this->app = $this->makeApp(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testCreatesStorageWithBucket(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->app->getContainer()->bind( |
|
31
|
|
|
StorageConfig::class, |
|
32
|
|
|
new StorageConfig([ |
|
33
|
|
|
'servers' => [ |
|
34
|
|
|
'local' => [ |
|
35
|
|
|
'adapter' => 'local', |
|
36
|
|
|
'directory' => 'uploads', |
|
37
|
|
|
], |
|
38
|
|
|
], |
|
39
|
|
|
'buckets' => [ |
|
40
|
|
|
'default' => [ |
|
41
|
|
|
'server' => 'local', |
|
42
|
|
|
] |
|
43
|
|
|
], |
|
44
|
|
|
]) |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$this->app->getContainer()->bind( |
|
48
|
|
|
BucketFactoryInterface::class, |
|
49
|
|
|
$bucket = m::mock(BucketFactoryInterface::class) |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$bucket->shouldReceive('createFromAdapter')->withArgs(function ( |
|
53
|
|
|
FilesystemAdapter $adapter, |
|
54
|
|
|
string $name, |
|
55
|
|
|
UriResolverInterface $resolver = null |
|
56
|
|
|
) { |
|
57
|
|
|
return $adapter instanceof LocalFilesystemAdapter |
|
58
|
|
|
&& $name === 'default' |
|
59
|
|
|
&& $resolver === null; |
|
60
|
|
|
})->once()->andReturn($bucket = m::mock(BucketInterface::class)); |
|
61
|
|
|
|
|
62
|
|
|
$storage = $this->app->get(StorageInterface::class); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertSame($bucket, $storage->bucket('default')); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|