Skip to content

Commit 5afa47e

Browse files
committed
MQE-1017: Better Error Messaging When Non-Whitespace Characters Are
Outside XML Elements - Abstracted validation code in Filesystem
1 parent 596efbe commit 5afa47e

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\FunctionalTestingFramework\Config\Reader;
77

8+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
9+
810
/**
911
* Filesystem configuration loader. Loads configuration from XML files, split by scopes.
1012
*/
@@ -150,24 +152,14 @@ protected function readFiles($fileList)
150152
} else {
151153
$configMerger->merge($content);
152154
}
153-
if ($this->validationState->isValidationRequired()) {
154-
$errors = [];
155-
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
156-
$message = $fileList->getFilename() . PHP_EOL . "Invalid Document \n";
157-
throw new \Exception($message . implode("\n", $errors));
158-
}
155+
if (MftfApplicationConfig::getConfig()->debugEnabled()) {
156+
$this->validateSchema($configMerger, $fileList->getFilename());
159157
}
160158
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
161159
throw new \Exception("Invalid XML in file " . $fileList->getFilename() . ":\n" . $e->getMessage());
162160
}
163161
}
164-
if ($this->validationState->isValidationRequired()) {
165-
$errors = [];
166-
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
167-
$message = "Invalid Document \n";
168-
throw new \Exception($message . implode("\n", $errors));
169-
}
170-
}
162+
$this->validateSchema($configMerger);
171163

172164
$output = [];
173165
if ($configMerger) {
@@ -199,4 +191,23 @@ protected function createConfigMerger($mergerClass, $initialContents)
199191
}
200192
return $result;
201193
}
194+
195+
/**
196+
* Validate read xml against expected schema
197+
*
198+
* @param string $configMerger
199+
* @param string $filename
200+
* @throws \Exception
201+
* @return void
202+
*/
203+
protected function validateSchema($configMerger, $filename = null)
204+
{
205+
if ($this->validationState->isValidationRequired()) {
206+
$errors = [];
207+
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
208+
$message = $filename ? $filename . PHP_EOL . "Invalid Document \n" : PHP_EOL . "Invalid Document \n";
209+
throw new \Exception($message . implode("\n", $errors));
210+
}
211+
}
212+
}
202213
}

src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class MftfFilesystem extends \Magento\FunctionalTestingFramework\Config\Reader\F
2222
public function readFiles($fileList)
2323
{
2424
$exceptionCollector = new ExceptionCollector();
25-
$errors = [];
2625
/** @var \Magento\FunctionalTestingFramework\Test\Config\Dom $configMerger */
2726
$configMerger = null;
2827
foreach ($fileList as $key => $content) {
@@ -38,24 +37,14 @@ public function readFiles($fileList)
3837
$configMerger->merge($content, $fileList->getFilename(), $exceptionCollector);
3938
}
4039
if (MftfApplicationConfig::getConfig()->debugEnabled()) {
41-
if ($this->validationState->isValidationRequired()) {
42-
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
43-
$message = "Invalid Document: " . PHP_EOL . $fileList->getFilename() . PHP_EOL;
44-
throw new \Exception($message . implode("\n", $errors));
45-
}
46-
}
40+
$this->validateSchema($configMerger, $fileList->getFilename());
4741
}
4842
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
4943
throw new \Exception("Invalid XML in file " . $key . ":\n" . $e->getMessage());
5044
}
5145
}
5246
$exceptionCollector->throwException();
53-
if ($this->validationState->isValidationRequired()) {
54-
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
55-
$message = "Invalid Document: " . PHP_EOL;
56-
throw new \Exception($message . implode("\n", $errors));
57-
}
58-
}
47+
$this->validateSchema($configMerger, $fileList->getFilename());
5948

6049
$output = [];
6150
if ($configMerger) {

0 commit comments

Comments
 (0)