Passed
Push — master ( 5204b5...bf9fba )
by Alice
37s
created

ServiceLoaderTest::test_loadFileError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wonderland\Container\Tests\Configuration;
4
5
use PHPUnit\Framework\TestCase;
6
use Wonderland\Container\Configuration\Parser\YamlParser;
7
use Wonderland\Container\Configuration\ServiceLoader;
8
use Wonderland\Container\Exception\InvalidConfigFormatException;
9
use Wonderland\Container\Service\ServiceDefinition;
10
11
/**
12
 * Class ServiceLoader
13
 * @package Wonderland\Container\Tests\Configuration
14
 * @author Alice Praud <[email protected]>
15
 */
16
class ServiceLoaderTest extends TestCase
17
{
18
	/** @var ServiceLoader */
19
	private $loaderYml;
20
21
	public function setUp()
22
	{
23
		$this->loaderYml = new ServiceLoader(new YamlParser());
24
	}
25
26
	/**
27
	 * @return array
28
	 */
29
	public function ymlProvider()
30
	{
31
		return [
32
			[__DIR__ . '/data/yml/test-empty.yml'],
33
			[__DIR__ . '/data/yml/test-full.yml']
34
		];
35
	}
36
37
	/**
38
	 * @dataProvider ymlProvider
39
	 * @param string $testFile
40
	 * @throws \Wonderland\Container\Exception\InvalidConfigFormatException
41
	 */
42
	public function test_loadFile($testFile)
43
	{
44
		$services = $this->loaderYml->loadFile($testFile);
45
		$this->assertInternalType('array', $services);
46
		foreach ($services as $service) {
47
			$this->assertInstanceOf(ServiceDefinition::class, $service);
48
		}
49
	}
50
51
	/**
52
	 * @return array
53
	 */
54
	public function ymlErrorProvider()
55
	{
56
		return [
57
			[__DIR__ . '/data/yml-error/empty.yml'],
58
			[__DIR__ . '/data/yml-error/err1.yml'],
59
			[__DIR__ . '/data/yml-error/err2.yml'],
60
			[__DIR__ . '/data/yml-error/err3.yml'],
61
			[__DIR__ . '/data/yml-error/err4.yml'],
62
			[__DIR__ . '/data/yml-error/err5.yml'],
63
			[__DIR__ . '/data/yml-error/err6.yml'],
64
			[__DIR__ . '/data/yml-error/err7.yml'],
65
			[__DIR__ . '/data/yml-error/err8.yml']
66
		];
67
	}
68
69
	/**
70
	 * @dataProvider ymlErrorProvider
71
	 * @param string $testFile
72
	 * @throws \Wonderland\Container\Exception\InvalidConfigFormatException
73
	 */
74
	public function test_loadFileError($testFile)
75
	{
76
		$this->expectException(InvalidConfigFormatException::class);
77
		$this->loaderYml->loadFile($testFile);
78
	}
79
80
	/**
81
	 * @throws InvalidConfigFormatException
82
	 */
83
	public function test_loadDirectory()
84
	{
85
		$services = $this->loaderYml->loadDirectory(__DIR__ . '/data/yml');
86
		$this->assertInternalType('array', $services);
87
		foreach ($services as $service) {
88
			$this->assertInstanceOf(ServiceDefinition::class, $service);
89
		}
90
	}
91
92
}
93