|
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()) |
|
|
|
|
|
|
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
|
|
|
|
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.