|
6 | 6 |
|
7 | 7 | namespace Magento\FunctionalTestingFramework\StaticCheck;
|
8 | 8 |
|
9 |
| -use Magento\FunctionalTestingFramework\Config\Data; |
10 | 9 | use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
|
11 | 10 | use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
|
| 11 | +use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException; |
| 12 | +use Magento\FunctionalTestingFramework\Exceptions\XmlException; |
12 | 13 | use Magento\FunctionalTestingFramework\Page\Handlers\PageObjectHandler;
|
13 | 14 | use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler;
|
14 |
| -use Magento\FunctionalTestingFramework\Page\Objects\SectionObject; |
15 | 15 | use Magento\FunctionalTestingFramework\Test\Handlers\ActionGroupObjectHandler;
|
16 | 16 | use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
|
17 | 17 | use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
|
18 | 18 | use Magento\FunctionalTestingFramework\Util\ModuleResolver;
|
19 | 19 | use Magento\FunctionalTestingFramework\Util\TestGenerator;
|
20 | 20 | use Symfony\Component\Console\Input\InputInterface;
|
21 |
| -use Symfony\Component\Filesystem\Filesystem; |
22 | 21 | use Symfony\Component\Finder\Finder;
|
| 22 | +use Exception; |
23 | 23 |
|
24 | 24 | /**
|
25 | 25 | * Class TestDependencyCheck
|
@@ -62,11 +62,24 @@ class TestDependencyCheck implements StaticCheckInterface
|
62 | 62 | */
|
63 | 63 | private $alreadyExtractedDependencies;
|
64 | 64 |
|
| 65 | + /** |
| 66 | + * Array containing all errors found after running the execute() function. |
| 67 | + * @var array |
| 68 | + */ |
| 69 | + private $errors; |
| 70 | + |
| 71 | + /** |
| 72 | + * String representing the output summary found after running the execute() function. |
| 73 | + * @var string |
| 74 | + */ |
| 75 | + private $output; |
| 76 | + |
65 | 77 | /**
|
66 | 78 | * Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module
|
67 | 79 | *
|
68 | 80 | * @param InputInterface $input
|
69 | 81 | * @return string
|
| 82 | + * @throws Exception; |
70 | 83 | * @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
71 | 84 | */
|
72 | 85 | public function execute(InputInterface $input)
|
@@ -98,21 +111,39 @@ public function execute(InputInterface $input)
|
98 | 111 | $actionGroupXmlFiles = $this->buildFileList($allModules, $filePaths[1]);
|
99 | 112 | $dataXmlFiles= $this->buildFileList($allModules, $filePaths[2]);
|
100 | 113 |
|
101 |
| - $testErrors = []; |
102 |
| - $testErrors += $this->findErrorsInFileSet($testXmlFiles); |
103 |
| - $testErrors += $this->findErrorsInFileSet($actionGroupXmlFiles); |
104 |
| - $testErrors += $this->findErrorsInFileSet($dataXmlFiles); |
| 114 | + $this->errors = []; |
| 115 | + $this->errors += $this->findErrorsInFileSet($testXmlFiles); |
| 116 | + $this->errors += $this->findErrorsInFileSet($actionGroupXmlFiles); |
| 117 | + $this->errors += $this->findErrorsInFileSet($dataXmlFiles); |
105 | 118 |
|
106 |
| - //print all errors to file |
107 |
| - return $this->printErrorsToFile($testErrors); |
| 119 | + // hold on to the output and print any errors to a file |
| 120 | + $this->output = $this->printErrorsToFile(); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Return array containing all errors found after running the execute() function. |
| 125 | + * @return array |
| 126 | + */ |
| 127 | + public function getErrors() |
| 128 | + { |
| 129 | + return $this->errors; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Return string of a short human readable result of the check. For example: "No Dependency errors found." |
| 134 | + * @return string |
| 135 | + */ |
| 136 | + public function getOutput() |
| 137 | + { |
| 138 | + return $this->output; |
108 | 139 | }
|
109 | 140 |
|
110 | 141 | /**
|
111 | 142 | * Finds all reference errors in given set of files
|
112 | 143 | * @param Finder $files
|
113 | 144 | * @return array
|
114 |
| - * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException |
115 |
| - * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException |
| 145 | + * @throws TestReferenceException |
| 146 | + * @throws XmlException |
116 | 147 | */
|
117 | 148 | private function findErrorsInFileSet($files)
|
118 | 149 | {
|
@@ -333,8 +364,7 @@ private function buildFileList($modulePaths, $path)
|
333 | 364 | * Attempts to find any MFTF entity by its name. Returns null if none are found.
|
334 | 365 | * @param string $name
|
335 | 366 | * @return mixed
|
336 |
| - * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException |
337 |
| - * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException |
| 367 | + * @throws XmlException |
338 | 368 | */
|
339 | 369 | private function findEntity($name)
|
340 | 370 | {
|
@@ -363,24 +393,29 @@ private function findEntity($name)
|
363 | 393 |
|
364 | 394 | /**
|
365 | 395 | * Prints out given errors to file, and returns summary result string
|
366 |
| - * @param array $errors |
367 | 396 | * @return string
|
368 | 397 | */
|
369 |
| - private function printErrorsToFile($errors) |
| 398 | + private function printErrorsToFile() |
370 | 399 | {
|
| 400 | + $errors = $this->getErrors(); |
| 401 | + |
371 | 402 | if (empty($errors)) {
|
372 | 403 | return "No Dependency errors found.";
|
373 | 404 | }
|
| 405 | + |
374 | 406 | $outputPath = getcwd() . DIRECTORY_SEPARATOR . "mftf-dependency-checks.txt";
|
375 | 407 | $fileResource = fopen($outputPath, 'w');
|
376 | 408 | $header = "MFTF File Dependency Check:\n";
|
377 | 409 | fwrite($fileResource, $header);
|
| 410 | + |
378 | 411 | foreach ($errors as $test => $error) {
|
379 | 412 | fwrite($fileResource, $error[0] . PHP_EOL);
|
380 | 413 | }
|
| 414 | + |
381 | 415 | fclose($fileResource);
|
382 | 416 | $errorCount = count($errors);
|
383 | 417 | $output = "Dependency errors found across {$errorCount} file(s). Error details output to {$outputPath}";
|
| 418 | + |
384 | 419 | return $output;
|
385 | 420 | }
|
386 | 421 | }
|
0 commit comments