11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2014 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
1515use Magento \Framework \Config \ValidationStateInterface ;
1616use PHPUnit \Framework \MockObject \MockObject ;
1717use PHPUnit \Framework \TestCase ;
18+ use Magento \Framework \Config \Dom ;
1819
1920/**
2021 * Test for
@@ -53,6 +54,11 @@ class FilesystemTest extends TestCase
5354 */
5455 protected $ _file ;
5556
57+ /**
58+ * @var Filesystem
59+ */
60+ private $ filesystem ;
61+
5662 protected function setUp (): void
5763 {
5864 if (!function_exists ('libxml_set_external_entity_loader ' )) {
@@ -64,6 +70,16 @@ protected function setUp(): void
6470 $ this ->_schemaLocatorMock = $ this ->getMockForAbstractClass (SchemaLocatorInterface::class);
6571 $ this ->_validationStateMock = $ this ->getMockForAbstractClass (ValidationStateInterface::class);
6672 $ 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+ );
6783 }
6884
6985 public function testRead ()
@@ -170,4 +186,32 @@ public function testReadException()
170186 );
171187 $ model ->read ();
172188 }
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+ }
173217}
0 commit comments