-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathMftfFilesystem.php
93 lines (87 loc) · 3.43 KB
/
MftfFilesystem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Config\Reader;
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
use Magento\FunctionalTestingFramework\Exceptions\Collector\ExceptionCollector;
use Magento\FunctionalTestingFramework\Util\Iterator\File;
class MftfFilesystem extends \Magento\FunctionalTestingFramework\Config\Reader\Filesystem
{
/**
* Method to redirect file name passing into Dom class
*
* @param File $fileList
* @return array
* @throws \Exception
*/
public function readFiles($fileList)
{
$exceptionCollector = new ExceptionCollector();
/** @var \Magento\FunctionalTestingFramework\Test\Config\Dom $configMerger */
$configMerger = null;
$debugLevel = MftfApplicationConfig::getConfig()->getDebugLevel();
foreach ($fileList as $key => $content) {
//check if file is empty and continue to next if it is
if (!parent::verifyFileEmpty($content, $fileList->getFilename())) {
continue;
}
try {
if (!$configMerger) {
$configMerger = $this->createConfigMerger(
$this->domDocumentClass,
$content,
$fileList->getFilename(),
$exceptionCollector
);
} else {
$configMerger->merge($content, $fileList->getFilename(), $exceptionCollector);
}
// run per file validation with generate:tests -d
if (strcasecmp($debugLevel, MftfApplicationConfig::LEVEL_DEVELOPER) == 0) {
$this->validateSchema($configMerger, $fileList->getFilename());
}
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
throw new \Exception("Invalid XML in file " . $key . ":\n" . $e->getMessage());
}
}
$exceptionCollector->throwException();
//run validation on merged file with generate:tests
if (strcasecmp($debugLevel, MftfApplicationConfig::LEVEL_DEFAULT) == 0) {
$this->validateSchema($configMerger);
}
$output = [];
if ($configMerger) {
$output = $this->converter->convert($configMerger->getDom());
}
return $output;
}
/**
* Return newly created instance of a config merger
*
* @param string $mergerClass
* @param string $initialContents
* @param string $filename
* @param ExceptionCollector $exceptionCollector
* @return \Magento\FunctionalTestingFramework\Config\Dom
* @throws \UnexpectedValueException
*/
protected function createConfigMerger($mergerClass, $initialContents, $filename = null, $exceptionCollector = null)
{
$result = new $mergerClass(
$initialContents,
$filename,
$exceptionCollector,
$this->idAttributes,
null,
$this->perFileSchema
);
if (!$result instanceof \Magento\FunctionalTestingFramework\Config\Dom) {
throw new \UnexpectedValueException(
"Instance of the DOM config merger is expected, got {$mergerClass} instead."
);
}
return $result;
}
}