Passed
Pull Request — master (#601)
by butschster
06:54
created

StorageBootloaderTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testCreatesStorageWithBucket() 0 37 3
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([
0 ignored issues
show
Bug introduced by
new Spiral\Bootloader\St...'server' => 'local')))) of type Spiral\Bootloader\Storage\StorageConfig is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
            /** @scrutinizer ignore-type */ new StorageConfig([
Loading history...
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)
0 ignored issues
show
Bug introduced by
$bucket = Mockery::mock(...actoryInterface::class) of type Mockery\LegacyMockInterface|Mockery\MockInterface is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
            /** @scrutinizer ignore-type */ $bucket = m::mock(BucketFactoryInterface::class)
Loading history...
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