|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Northwoods\Config\Loader; |
|
4
|
|
|
|
|
5
|
|
|
use Eloquent\Phony\Phpunit\Phony; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class FactoryTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var LoaderFactory |
|
12
|
|
|
*/ |
|
13
|
|
|
private $factory; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
public function setUp() |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
$this->factory = new LoaderFactory(); |
|
18
|
|
|
} |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
public function testTypes() |
|
21
|
|
|
{ |
|
22
|
|
|
$loader = $this->factory->forType('php'); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertInstanceOf(LoaderInterface::class, $loader); |
|
25
|
|
|
$this->assertInstanceOf(PhpLoader::class, $loader); |
|
26
|
|
|
$this->assertTrue($loader::isSupported()); |
|
27
|
|
|
|
|
28
|
|
|
$loader = $this->factory->forType('yaml'); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertInstanceOf(LoaderInterface::class, $loader); |
|
31
|
|
|
$this->assertInstanceOf(YamlLoader::class, $loader); |
|
32
|
|
|
$this->assertTrue($loader::isSupported()); |
|
33
|
|
|
} |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
public function testPhpLoader() |
|
36
|
|
|
{ |
|
37
|
|
|
$loader = $this->factory->forType('php'); |
|
38
|
|
|
|
|
39
|
|
|
$config = $loader->load(__DIR__ . '/../../examples/app'); |
|
40
|
|
|
$this->assertArrayHasKey('timezone', $config); |
|
41
|
|
|
|
|
42
|
|
|
$config = $loader->load(__DIR__ . '/failure/fail'); |
|
43
|
|
|
$this->assertSame([], $config); |
|
44
|
|
|
} |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function testYamlLoader() |
|
47
|
|
|
{ |
|
48
|
|
|
$loader = $this->factory->forType('yaml'); |
|
49
|
|
|
|
|
50
|
|
|
$config = $loader->load(__DIR__ . '/../../examples/users'); |
|
51
|
|
|
$this->assertArrayHasKey('admins', $config); |
|
52
|
|
|
|
|
53
|
|
|
$config = $loader->load(__DIR__ . '/failure/fail'); |
|
54
|
|
|
$this->assertSame([], $config); |
|
55
|
|
|
} |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
public function testInvalidLoader() |
|
58
|
|
|
{ |
|
59
|
|
|
$factory = new LoaderFactory([ |
|
|
|
|
|
|
60
|
|
|
'test' => \stdclass::class, |
|
61
|
|
|
]); |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
$this->expectException(LoaderException::class); |
|
64
|
|
|
$this->expectExceptionCode(LoaderException::INVALID_LOADER); |
|
65
|
|
|
|
|
66
|
|
|
$loader = $factory->forType('test'); |
|
|
|
|
|
|
67
|
|
|
} |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public function testUnsupportedLoader() |
|
70
|
|
|
{ |
|
71
|
|
|
$loader = Phony::mock(LoaderInterface::class); |
|
72
|
|
|
$loader = Phony::onStatic($loader); |
|
73
|
|
|
$loader->isSupported->returns(false); |
|
74
|
|
|
|
|
75
|
|
|
$factory = new LoaderFactory([ |
|
|
|
|
|
|
76
|
|
|
'test' => $loader->className(), |
|
77
|
|
|
]); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$this->expectException(LoaderException::class); |
|
80
|
|
|
$this->expectExceptionCode(LoaderException::UNSUPPORTED_LOADER); |
|
81
|
|
|
|
|
82
|
|
|
$loader = $factory->forType('test'); |
|
|
|
|
|
|
83
|
|
|
} |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|