|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Bldr.io |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Aaron Scherer <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Bldr\Test\DependencyInjection\Loader; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Rob Loach <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class FileLoaderTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* The name of the class to test. |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $class; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The extension for the file. |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $extension; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The expected result from loading the file. |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $expected = [ |
|
33
|
|
|
'bldr' => [ |
|
34
|
|
|
'description' => 'Description for your project', |
|
35
|
|
|
'name' => 'acme/demo-project', |
|
36
|
|
|
'profiles' => [ |
|
37
|
|
|
'default' => [ |
|
38
|
|
|
'description' => 'Sample Profile', |
|
39
|
|
|
'jobs' => [ |
|
40
|
|
|
0 => 'sampleJob', |
|
41
|
|
|
], |
|
42
|
|
|
], |
|
43
|
|
|
], |
|
44
|
|
|
'jobs' => [ |
|
45
|
|
|
'sampleJob' => [ |
|
46
|
|
|
'description' => 'Runs a sleep for 5 seconds, then sends a message to the screen', |
|
47
|
|
|
'tasks' => [ |
|
48
|
|
|
0 => [ |
|
49
|
|
|
'type' => 'sleep', |
|
50
|
|
|
'seconds' => 5, |
|
51
|
|
|
], |
|
52
|
|
|
1 => [ |
|
53
|
|
|
'type' => 'notify', |
|
54
|
|
|
'message' => 'Finished Sleeping. Ending now.' |
|
55
|
|
|
], |
|
56
|
|
|
], |
|
57
|
|
|
], |
|
58
|
|
|
] |
|
59
|
|
|
], |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Set up the FileLoader. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function setUp() |
|
66
|
|
|
{ |
|
67
|
|
|
// Mock the Container Builder. |
|
68
|
|
|
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); |
|
69
|
|
|
$container->method('hasExtension')->willReturn(true); |
|
70
|
|
|
|
|
71
|
|
|
// Mock the Locator. |
|
72
|
|
|
$locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface'); |
|
73
|
|
|
|
|
74
|
|
|
// Build the FileLoader. |
|
75
|
|
|
$this->loader = new $this->class($container, $locator); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Tests the protected loadFile() function from the FileLoader. |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testLoadFile() |
|
82
|
|
|
{ |
|
83
|
|
|
$actual = $this->invokeMethod($this->loader, 'loadFile', [ |
|
84
|
|
|
__DIR__.'/Fixtures/test.'.$this->extension |
|
85
|
|
|
]); |
|
86
|
|
|
$this->assertEquals($this->expected, $actual); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Tests the getFileExtension function. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testGetFileExtension() |
|
93
|
|
|
{ |
|
94
|
|
|
$actual = $this->invokeMethod($this->loader, 'getFileExtension'); |
|
95
|
|
|
$this->assertEquals($this->extension, $actual); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Invoke a protected or private method from a class. |
|
100
|
|
|
*/ |
|
101
|
|
|
private function invokeMethod(&$object, $methodName, array $parameters = []) |
|
102
|
|
|
{ |
|
103
|
|
|
$reflection = new \ReflectionClass(get_class($object)); |
|
104
|
|
|
$method = $reflection->getMethod($methodName); |
|
105
|
|
|
$method->setAccessible(true); |
|
106
|
|
|
|
|
107
|
|
|
return $method->invokeArgs($object, $parameters); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|