Skip to content

Commit eb95a3f

Browse files
committed
Reader integration test refactor. Dependency on actual config removed.
1 parent 6f32de1 commit eb95a3f

File tree

6 files changed

+165
-2768
lines changed

6 files changed

+165
-2768
lines changed

dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/ConverterStub.php renamed to dev/tests/integration/testsuite/Magento/Config/Model/Config/Structure/Reader/ConverterStub.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Paypal\Model\Config\Structure\Reader;
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Model\Config\Structure\Reader;
9+
10+
use Magento\Config\Model\Config\Structure\Converter;
711

812
/**
9-
* Class ConverterStub
13+
* Class ConverterStub used for ReaderTest.
1014
*/
11-
class ConverterStub extends \Magento\Config\Model\Config\Structure\Converter
15+
class ConverterStub extends Converter
1216
{
1317
/**
18+
* Convert dom document wrapper.
19+
*
1420
* @param \DOMDocument $document
1521
* @return array|null
1622
*/
@@ -20,7 +26,7 @@ public function getArrayData(\DOMDocument $document)
2026
}
2127

2228
/**
23-
* Convert dom document
29+
* Convert dom document.
2430
*
2531
* @param \DOMNode $source
2632
* @return array

dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/ReaderStub.php renamed to dev/tests/integration/testsuite/Magento/Config/Model/Config/Structure/Reader/ReaderStub.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Paypal\Model\Config\Structure\Reader;
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Model\Config\Structure\Reader;
9+
10+
use Magento\Config\Model\Config\Structure\Reader;
711

812
/**
9-
* Class ReaderStub
13+
* Class ReaderStub used for testing protected Reader::_readFiles() method.
1014
*/
11-
class ReaderStub extends \Magento\Config\Model\Config\Structure\Reader
15+
class ReaderStub extends Reader
1216
{
1317
/**
18+
* Wrapper for protected Reader::_readFiles() method.
19+
*
1420
* @param array $fileList
1521
* @return array
1622
* @throws \Magento\Framework\Exception\LocalizedException
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Model\Config\Structure\Reader;
9+
10+
use Magento\Config\Model\Config\SchemaLocator;
11+
use Magento\Framework\App\Utility\Files;
12+
use Magento\Framework\Config\Dom;
13+
use Magento\Framework\Config\FileResolverInterface;
14+
use Magento\Framework\Config\ValidationStateInterface;
15+
use Magento\Framework\ObjectManagerInterface;
16+
use Magento\Framework\View\TemplateEngine\Xhtml\CompilerInterface;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
19+
/**
20+
* Class ReaderTest check Magento\Config\Model\Config\Structure\Reader::_readFiles() method.
21+
*/
22+
class ReaderTest extends \PHPUnit\Framework\TestCase
23+
{
24+
/**
25+
* Test config location.
26+
*
27+
* @string
28+
*/
29+
const CONFIG = '/dev/tests/integration/testsuite/Magento/Config/Model/Config/Structure/Reader/_files/';
30+
31+
/**
32+
* @var ObjectManagerInterface
33+
*/
34+
private $objectManager;
35+
36+
/**
37+
* @var Files
38+
*/
39+
private $fileUtility;
40+
41+
/**
42+
* @var ValidationStateInterface
43+
*/
44+
private $validationStateMock;
45+
46+
/**
47+
* @var \Magento\Framework\Config\SchemaLocatorInterface
48+
*/
49+
private $schemaLocatorMock;
50+
51+
/**
52+
* @var FileResolverInterface
53+
*/
54+
private $fileResolverMock;
55+
56+
/**
57+
* @var ReaderStub
58+
*/
59+
private $reader;
60+
61+
/**
62+
* @var ConverterStub
63+
*/
64+
private $converter;
65+
66+
/**
67+
* @var CompilerInterface|\PHPUnit_Framework_MockObject_MockObject
68+
*/
69+
private $compiler;
70+
71+
/**
72+
* @inheritdoc
73+
*/
74+
protected function setUp()
75+
{
76+
$this->objectManager = Bootstrap::getObjectManager();
77+
$this->fileUtility = Files::init();
78+
79+
$this->validationStateMock = $this->getMockBuilder(ValidationStateInterface::class)
80+
->setMethods(['isValidationRequired'])
81+
->getMockForAbstractClass();
82+
$this->schemaLocatorMock = $this->getMockBuilder(SchemaLocator::class)
83+
->disableOriginalConstructor()
84+
->setMethods(['getPerFileSchema'])
85+
->getMock();
86+
$this->fileResolverMock = $this->getMockBuilder(FileResolverInterface::class)
87+
->getMockForAbstractClass();
88+
89+
$this->validationStateMock->expects($this->atLeastOnce())
90+
->method('isValidationRequired')
91+
->willReturn(false);
92+
$this->schemaLocatorMock->expects($this->atLeastOnce())
93+
->method('getPerFileSchema')
94+
->willReturn(false);
95+
96+
$this->converter = $this->objectManager->create(ConverterStub::class);
97+
98+
//Isolate test from actual configuration, and leave only sample data.
99+
$this->compiler = $this->getMockBuilder(CompilerInterface::class)
100+
->disableOriginalConstructor()
101+
->setMethods(['compile'])
102+
->getMockForAbstractClass();
103+
104+
$this->reader = $this->objectManager->create(
105+
ReaderStub::class,
106+
[
107+
'fileResolver' => $this->fileResolverMock,
108+
'converter' => $this->converter,
109+
'schemaLocator' => $this->schemaLocatorMock,
110+
'validationState' => $this->validationStateMock,
111+
'fileName' => 'no_existing_file.xml',
112+
'compiler' => $this->compiler,
113+
'domDocumentClass' => Dom::class
114+
]
115+
);
116+
}
117+
118+
/**
119+
* The test checks the file structure after processing the nodes responsible for inserting content.
120+
*
121+
* @return void
122+
*/
123+
public function testXmlConvertedConfigurationAndCompereStructure()
124+
{
125+
$actual = $this->reader->readFiles(['actual' => $this->getContent()]);
126+
127+
$document = new \DOMDocument();
128+
$document->loadXML($this->getContent());
129+
130+
$expected = $this->converter->getArrayData($document);
131+
132+
$this->assertEquals($expected, $actual);
133+
}
134+
135+
/**
136+
* Get config sample data for test.
137+
*
138+
* @return string
139+
*/
140+
protected function getContent()
141+
{
142+
$files = $this->fileUtility->getFiles([BP . static::CONFIG], 'config.xml');
143+
144+
return file_get_contents(reset($files));
145+
}
146+
}

dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/ReaderTest.php

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)