Skip to content

Commit fa56508

Browse files
authored
Merge pull request #386 from magento/MQE-1606
MQE-1606: Mftf static check script should return error exit code when check fails
2 parents cd04795 + accceb8 commit fa56508

File tree

6 files changed

+87
-25
lines changed

6 files changed

+87
-25
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ dev/tests/functional/MFTF.suite.yml
1616
dev/tests/functional/_output
1717
dev/mftf.log
1818
dev/tests/mftf.log
19-
dev/tests/docs/*
19+
dev/tests/docs/*
20+
dev/tests/_output
21+
dev/tests/functional.suite.yml

src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
namespace Magento\FunctionalTestingFramework\Console;
1010

1111
use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
12+
use Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface;
1213
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
1314
use Symfony\Component\Console\Command\Command;
1415
use Symfony\Component\Console\Input\InputInterface;
15-
use Symfony\Component\Console\Input\InputArgument;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Exception;
1718

1819
class StaticChecksCommand extends Command
1920
{
2021
/**
2122
* Pool of static check scripts to run
2223
*
23-
* @var \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface
24+
* @var StaticCheckListInterface
2425
*/
2526
private $staticChecksList;
2627

@@ -41,16 +42,28 @@ protected function configure()
4142
*
4243
* @param InputInterface $input
4344
* @param OutputInterface $output
44-
* @return int|null|void
45-
* @throws \Exception
45+
* @return int
46+
* @throws Exception
4647
*/
4748
protected function execute(InputInterface $input, OutputInterface $output)
4849
{
4950
$staticCheckObjects = $this->staticChecksList->getStaticChecks();
51+
52+
$errors = [];
53+
5054
foreach ($staticCheckObjects as $staticCheck) {
51-
$staticOutput = $staticCheck->execute($input);
55+
$staticCheck->execute($input);
56+
57+
$staticOutput = $staticCheck->getOutput();
5258
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info($staticOutput);
5359
$output->writeln($staticOutput);
60+
$errors += $staticCheck->getErrors();
61+
}
62+
63+
if (empty($errors)) {
64+
return 0;
65+
} else {
66+
return 1;
5467
}
5568
}
5669
}

src/Magento/FunctionalTestingFramework/StaticCheck/StaticCheckInterface.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ interface StaticCheckInterface
1616
/**
1717
* Executes static check script, returns output.
1818
* @param InputInterface $input
19-
* @return string
19+
* @return void
2020
*/
2121
public function execute(InputInterface $input);
22+
23+
/**
24+
* Return array containing all errors found after running the execute() function.
25+
* @return array
26+
*/
27+
public function getErrors();
28+
29+
/**
30+
* Return string of a short human readable result of the check. For example: "No Dependency errors found."
31+
* @return string
32+
*/
33+
public function getOutput();
2234
}

src/Magento/FunctionalTestingFramework/StaticCheck/StaticCheckListInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface StaticCheckListInterface
1414
/**
1515
* Gets list of static check script instances
1616
*
17-
* @return \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface[]
17+
* @return StaticCheckInterface[]
1818
*/
1919
public function getStaticChecks();
2020
}

src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class StaticChecksList implements StaticCheckListInterface
1616
/**
1717
* Property contains all static check scripts.
1818
*
19-
* @var \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface[]
19+
* @var StaticCheckInterface[]
2020
*/
2121
private $checks;
2222

2323
/**
2424
* Constructor
2525
*
26-
* @param array $scripts
26+
* @param array $checks
2727
*/
2828
public function __construct(array $checks = [])
2929
{

src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
namespace Magento\FunctionalTestingFramework\StaticCheck;
88

9-
use Magento\FunctionalTestingFramework\Config\Data;
109
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
1110
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
11+
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
12+
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
1213
use Magento\FunctionalTestingFramework\Page\Handlers\PageObjectHandler;
1314
use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler;
14-
use Magento\FunctionalTestingFramework\Page\Objects\SectionObject;
1515
use Magento\FunctionalTestingFramework\Test\Handlers\ActionGroupObjectHandler;
1616
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
1717
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1818
use Magento\FunctionalTestingFramework\Util\ModuleResolver;
1919
use Magento\FunctionalTestingFramework\Util\TestGenerator;
2020
use Symfony\Component\Console\Input\InputInterface;
21-
use Symfony\Component\Filesystem\Filesystem;
2221
use Symfony\Component\Finder\Finder;
22+
use Exception;
2323

2424
/**
2525
* Class TestDependencyCheck
@@ -62,11 +62,24 @@ class TestDependencyCheck implements StaticCheckInterface
6262
*/
6363
private $alreadyExtractedDependencies;
6464

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+
6577
/**
6678
* Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module
6779
*
6880
* @param InputInterface $input
6981
* @return string
82+
* @throws Exception;
7083
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7184
*/
7285
public function execute(InputInterface $input)
@@ -98,21 +111,39 @@ public function execute(InputInterface $input)
98111
$actionGroupXmlFiles = $this->buildFileList($allModules, $filePaths[1]);
99112
$dataXmlFiles= $this->buildFileList($allModules, $filePaths[2]);
100113

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);
105118

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;
108139
}
109140

110141
/**
111142
* Finds all reference errors in given set of files
112143
* @param Finder $files
113144
* @return array
114-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
115-
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
145+
* @throws TestReferenceException
146+
* @throws XmlException
116147
*/
117148
private function findErrorsInFileSet($files)
118149
{
@@ -333,8 +364,7 @@ private function buildFileList($modulePaths, $path)
333364
* Attempts to find any MFTF entity by its name. Returns null if none are found.
334365
* @param string $name
335366
* @return mixed
336-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
337-
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
367+
* @throws XmlException
338368
*/
339369
private function findEntity($name)
340370
{
@@ -363,24 +393,29 @@ private function findEntity($name)
363393

364394
/**
365395
* Prints out given errors to file, and returns summary result string
366-
* @param array $errors
367396
* @return string
368397
*/
369-
private function printErrorsToFile($errors)
398+
private function printErrorsToFile()
370399
{
400+
$errors = $this->getErrors();
401+
371402
if (empty($errors)) {
372403
return "No Dependency errors found.";
373404
}
405+
374406
$outputPath = getcwd() . DIRECTORY_SEPARATOR . "mftf-dependency-checks.txt";
375407
$fileResource = fopen($outputPath, 'w');
376408
$header = "MFTF File Dependency Check:\n";
377409
fwrite($fileResource, $header);
410+
378411
foreach ($errors as $test => $error) {
379412
fwrite($fileResource, $error[0] . PHP_EOL);
380413
}
414+
381415
fclose($fileResource);
382416
$errorCount = count($errors);
383417
$output = "Dependency errors found across {$errorCount} file(s). Error details output to {$outputPath}";
418+
384419
return $output;
385420
}
386421
}

0 commit comments

Comments
 (0)