8
8
9
9
use Magento \Framework \App \DeploymentConfig \Reader ;
10
10
use Magento \Framework \App \Filesystem \DirectoryList ;
11
+ use Magento \Framework \Config \File \ConfigFilePool ;
12
+ use Magento \Framework \Filesystem \Driver \File ;
13
+ use Magento \Framework \Filesystem \DriverPool ;
11
14
12
15
class ReaderTest extends \PHPUnit \Framework \TestCase
13
16
{
14
17
/**
15
- * @var \PHPUnit_Framework_MockObject_MockObject
18
+ * @var \Magento\Framework\App\Filesystem\DirectoryList|\ PHPUnit_Framework_MockObject_MockObject
16
19
*/
17
20
private $ dirList ;
18
21
19
22
/**
20
- * @var \Magento\Framework\Filesystem\ DriverPool|\PHPUnit_Framework_MockObject_MockObject
23
+ * @var DriverPool|\PHPUnit_Framework_MockObject_MockObject
21
24
*/
22
25
private $ driverPool ;
23
26
24
27
/**
25
- * @var \Magento\Framework\Filesystem\Driver\ File|\PHPUnit_Framework_MockObject_MockObject
28
+ * @var File|\PHPUnit_Framework_MockObject_MockObject
26
29
*/
27
30
private $ fileDriver ;
28
31
29
32
/**
30
- * @var \PHPUnit_Framework_MockObject_MockObject
33
+ * @var ConfigFilePool| \PHPUnit_Framework_MockObject_MockObject
31
34
*/
32
35
private $ configFilePool ;
33
36
@@ -38,7 +41,7 @@ protected function setUp()
38
41
->method ('getPath ' )
39
42
->with (DirectoryList::CONFIG )
40
43
->willReturn (__DIR__ . '/_files ' );
41
- $ this ->fileDriver = $ this ->createMock (\ Magento \ Framework \ Filesystem \ Driver \ File::class);
44
+ $ this ->fileDriver = $ this ->createMock (File::class);
42
45
$ this ->fileDriver
43
46
->expects ($ this ->any ())
44
47
->method ('isExists ' )
@@ -51,12 +54,12 @@ protected function setUp()
51
54
[__DIR__ . '/_files/mergeTwo.php ' , true ],
52
55
[__DIR__ . '/_files/nonexistent.php ' , false ]
53
56
]));
54
- $ this ->driverPool = $ this ->createMock (\ Magento \ Framework \ Filesystem \ DriverPool::class);
57
+ $ this ->driverPool = $ this ->createMock (DriverPool::class);
55
58
$ this ->driverPool
56
59
->expects ($ this ->any ())
57
60
->method ('getDriver ' )
58
61
->willReturn ($ this ->fileDriver );
59
- $ this ->configFilePool = $ this ->createMock (\ Magento \ Framework \ Config \ File \ ConfigFilePool::class);
62
+ $ this ->configFilePool = $ this ->createMock (ConfigFilePool::class);
60
63
$ this ->configFilePool
61
64
->expects ($ this ->any ())
62
65
->method ('getPaths ' )
@@ -100,13 +103,97 @@ public function testLoad()
100
103
*/
101
104
public function testCustomLoad ($ file , $ expected )
102
105
{
103
- $ configFilePool = $ this ->createMock (\ Magento \ Framework \ Config \ File \ ConfigFilePool::class);
106
+ $ configFilePool = $ this ->createMock (ConfigFilePool::class);
104
107
$ configFilePool ->expects ($ this ->any ())->method ('getPaths ' )->willReturn ([$ file ]);
105
108
$ configFilePool ->expects ($ this ->any ())->method ('getPath ' )->willReturn ($ file );
106
109
$ object = new Reader ($ this ->dirList , $ this ->driverPool , $ configFilePool , $ file );
107
110
$ this ->assertSame ($ expected , $ object ->load ($ file ));
108
111
}
109
112
113
+ /**
114
+ * Test Reader::load() will throw exception in case of invalid configuration file(single file).
115
+ *
116
+ * @expectedException \Magento\Framework\Exception\RuntimeException
117
+ * @expectedExceptionMessageRegExp /Invalid configuration file: \'.*\/\_files\/emptyConfig\.php\'/
118
+ * @return void
119
+ */
120
+ public function testLoadInvalidConfigurationFileWithFileKey ()
121
+ {
122
+ $ fileDriver = $ this ->getMockBuilder (File::class)
123
+ ->disableOriginalConstructor ()
124
+ ->getMock ();
125
+ $ fileDriver ->expects ($ this ->once ())
126
+ ->method ('isExists ' )
127
+ ->willReturn (true );
128
+ /** @var DriverPool|\PHPUnit_Framework_MockObject_MockObject $driverPool */
129
+ $ driverPool = $ this ->getMockBuilder (DriverPool::class)
130
+ ->disableOriginalConstructor ()
131
+ ->getMock ();
132
+ $ driverPool
133
+ ->expects ($ this ->once ())
134
+ ->method ('getDriver ' )
135
+ ->willReturn ($ fileDriver );
136
+ /** @var ConfigFilePool|\PHPUnit_Framework_MockObject_MockObject $configFilePool */
137
+ $ configFilePool = $ this ->getMockBuilder (ConfigFilePool::class)
138
+ ->disableOriginalConstructor ()
139
+ ->getMock ();
140
+ $ configFilePool
141
+ ->expects ($ this ->once ())
142
+ ->method ('getPath ' )
143
+ ->with ($ this ->identicalTo ('testConfig ' ))
144
+ ->willReturn ('emptyConfig.php ' );
145
+ $ object = new Reader ($ this ->dirList , $ driverPool , $ configFilePool );
146
+ $ object ->load ('testConfig ' );
147
+ }
148
+
149
+ /**
150
+ * Test Reader::load() will throw exception in case of invalid configuration file(multiple files).
151
+ *
152
+ * @expectedException \Magento\Framework\Exception\RuntimeException
153
+ * @expectedExceptionMessageRegExp /Invalid configuration file: \'.*\/\_files\/emptyConfig\.php\'/
154
+ * @return void
155
+ */
156
+ public function testLoadInvalidConfigurationFile ()
157
+ {
158
+ $ fileDriver = $ this ->getMockBuilder (File::class)
159
+ ->disableOriginalConstructor ()
160
+ ->getMock ();
161
+ $ fileDriver ->expects ($ this ->exactly (2 ))
162
+ ->method ('isExists ' )
163
+ ->willReturn (true );
164
+ /** @var DriverPool|\PHPUnit_Framework_MockObject_MockObject $driverPool */
165
+ $ driverPool = $ this ->getMockBuilder (DriverPool::class)
166
+ ->disableOriginalConstructor ()
167
+ ->getMock ();
168
+ $ driverPool
169
+ ->expects ($ this ->once ())
170
+ ->method ('getDriver ' )
171
+ ->willReturn ($ fileDriver );
172
+ /** @var ConfigFilePool|\PHPUnit_Framework_MockObject_MockObject $configFilePool */
173
+ $ configFilePool = $ this ->getMockBuilder (ConfigFilePool::class)
174
+ ->disableOriginalConstructor ()
175
+ ->getMock ();
176
+ $ configFilePool ->expects ($ this ->exactly (2 ))
177
+ ->method ('getPaths ' )
178
+ ->willReturn (
179
+ [
180
+ 'configKeyOne ' => 'config.php ' ,
181
+ 'testConfig ' => 'emptyConfig.php '
182
+ ]
183
+ );
184
+ $ configFilePool ->expects ($ this ->exactly (2 ))
185
+ ->method ('getPath ' )
186
+ ->withConsecutive (
187
+ [$ this ->identicalTo ('configKeyOne ' )],
188
+ [$ this ->identicalTo ('testConfig ' )]
189
+ )->willReturnOnConsecutiveCalls (
190
+ 'config.php ' ,
191
+ 'emptyConfig.php '
192
+ );
193
+ $ object = new Reader ($ this ->dirList , $ driverPool , $ configFilePool );
194
+ $ object ->load ();
195
+ }
196
+
110
197
/**
111
198
* @return array
112
199
*/
0 commit comments