1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2014 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
15
15
use Magento \Framework \Config \ValidationStateInterface ;
16
16
use PHPUnit \Framework \MockObject \MockObject ;
17
17
use PHPUnit \Framework \TestCase ;
18
+ use Magento \Framework \Config \Dom ;
18
19
19
20
/**
20
21
* Test for
@@ -53,6 +54,11 @@ class FilesystemTest extends TestCase
53
54
*/
54
55
protected $ _file ;
55
56
57
+ /**
58
+ * @var Filesystem
59
+ */
60
+ private $ filesystem ;
61
+
56
62
protected function setUp (): void
57
63
{
58
64
if (!function_exists ('libxml_set_external_entity_loader ' )) {
@@ -64,6 +70,16 @@ protected function setUp(): void
64
70
$ this ->_schemaLocatorMock = $ this ->getMockForAbstractClass (SchemaLocatorInterface::class);
65
71
$ this ->_validationStateMock = $ this ->getMockForAbstractClass (ValidationStateInterface::class);
66
72
$ this ->urnResolver = new UrnResolver ();
73
+ $ this ->filesystem = new Filesystem (
74
+ $ this ->_fileResolverMock ,
75
+ $ this ->_converterMock ,
76
+ $ this ->_schemaLocatorMock ,
77
+ $ this ->_validationStateMock ,
78
+ 'test.xml ' ,
79
+ ['/test/node ' => 'id ' ],
80
+ Dom::class,
81
+ 'global '
82
+ );
67
83
}
68
84
69
85
public function testRead ()
@@ -170,4 +186,32 @@ public function testReadException()
170
186
);
171
187
$ model ->read ();
172
188
}
189
+
190
+ public function testCreateConfigMergerSuccess ()
191
+ {
192
+ $ initialContents = '<?xml version="1.0"?><config><test id="1"/></config> ' ;
193
+ $ reflection = new \ReflectionClass ($ this ->filesystem );
194
+ $ method = $ reflection ->getMethod ('_createConfigMerger ' );
195
+ $ result = $ method ->invokeArgs (
196
+ $ this ->filesystem ,
197
+ [Dom::class, $ initialContents ]
198
+ );
199
+ $ this ->assertInstanceOf (\Magento \Framework \Config \Dom::class, $ result );
200
+ $ domReflection = new \ReflectionClass ($ result );
201
+ $ typeAttributeProperty = $ domReflection ->getProperty ('typeAttributeName ' );
202
+ $ this ->assertEquals ('xsi:type ' , $ typeAttributeProperty ->getValue ($ result ));
203
+ }
204
+
205
+ public function testCreateConfigMergerThrowsException ()
206
+ {
207
+ $ initialContents = '<?xml version="1.0"?><config><test id="1"/></config> ' ;
208
+ $ wrongClass = \stdClass::class;
209
+ $ reflection = new \ReflectionClass ($ this ->filesystem );
210
+ $ method = $ reflection ->getMethod ('_createConfigMerger ' );
211
+ $ this ->expectException (\UnexpectedValueException::class);
212
+ $ this ->expectExceptionMessage (
213
+ "Instance of the DOM config merger is expected, got {$ wrongClass } instead. "
214
+ );
215
+ $ method ->invokeArgs ($ this ->filesystem , [$ wrongClass , $ initialContents ]);
216
+ }
173
217
}
0 commit comments