testCreateAdapterConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Filesystem\Test\Unit;
15
16
use Micro\Framework\Kernel\Configuration\ApplicationConfigurationInterface;
17
use Micro\Framework\Kernel\Configuration\Exception\InvalidConfigurationException;
18
use Micro\Framework\Kernel\Configuration\PluginRoutingKeyConfiguration;
19
use Micro\Plugin\Filesystem\Configuration\Adapter\FilesystemAdapterConfigurationInterface;
20
use Micro\Plugin\Filesystem\Configuration\FilesystemPluginConfigurationInterface;
21
use Micro\Plugin\Filesystem\FilesystemPluginConfiguration;
22
use PHPUnit\Framework\TestCase;
23
24
class FilesystemPluginConfigurationTest extends TestCase
25
{
26
    private ApplicationConfigurationInterface $applicationConfiguration;
27
    private FilesystemPluginConfigurationInterface $pluginConfiguration;
28
29
    protected function setUp(): void
30
    {
31
        $this->applicationConfiguration = $this->createMock(ApplicationConfigurationInterface::class);
32
        $this->pluginConfiguration = new FilesystemPluginConfiguration($this->applicationConfiguration);
33
    }
34
35
    public function testGetAdapterType()
36
    {
37
        $this->applicationConfiguration
38
            ->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Micro\Framework\Kernel\C...nConfigurationInterface. ( Ignorable by Annotation )

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

38
            ->/** @scrutinizer ignore-call */ 
39
              expects($this->once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
            ->method('get')
40
            ->with('MICRO_FS_TEST_TYPE')
41
            ->willReturn('example');
42
43
        $this->assertEquals('example', $this->pluginConfiguration->getAdapterType('test'));
44
    }
45
46
    public function testGetNoExistsAdapterConfiguration()
47
    {
48
        $this->expectException(InvalidConfigurationException::class);
49
        $this->pluginConfiguration->getAdapterConfiguration('no-exists');
50
    }
51
52
    public function testGetAdapterConfiguration()
53
    {
54
        $adapterCfg = $this->pluginConfiguration->createAdapterConfiguration(
55
            'test',
56
            ExampleFilesystemAdapterConfiguration::class
57
        );
58
59
        $this->assertEquals('hello', $adapterCfg->getPublicUrl());
60
    }
61
62
    public function testAdapterInvalidConfiguration()
63
    {
64
        $this->expectException(\TypeError::class);
65
        $this->pluginConfiguration->createAdapterConfiguration(
66
            'test',
67
            \stdClass::class
68
        );
69
    }
70
71
    public function testCreateAdapterConfiguration()
72
    {
73
        $this->expectException(InvalidConfigurationException::class);
74
        $this->pluginConfiguration->createAdapterConfiguration('test', 'ClassNoExists');
75
    }
76
}
77
78
class ExampleFilesystemAdapterConfiguration extends PluginRoutingKeyConfiguration implements FilesystemAdapterConfigurationInterface
79
{
80
    public function getPublicUrl(): null|string
81
    {
82
        return 'hello';
83
    }
84
}
85