Skip to content

Commit c598015

Browse files
committed
MQE-1606: Mftf static check script should return error exit code when check fails
- Refactoring from code review
1 parent dfc7713 commit c598015

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php

Lines changed: 8 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,8 +42,8 @@ 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
{
@@ -51,7 +52,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
5152
$errors = [];
5253

5354
foreach ($staticCheckObjects as $staticCheck) {
54-
$staticOutput = $staticCheck->execute($input);
55+
$staticCheck->execute($input);
56+
57+
$staticOutput = $staticCheck->getOutput();
5558
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info($staticOutput);
5659
$output->writeln($staticOutput);
5760
$errors += $staticCheck->getErrors();

src/Magento/FunctionalTestingFramework/StaticCheck/StaticCheckInterface.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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);
2222

@@ -25,4 +25,10 @@ public function execute(InputInterface $input);
2525
* @return array
2626
*/
2727
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();
2834
}

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: 27 additions & 11 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
@@ -68,11 +68,18 @@ class TestDependencyCheck implements StaticCheckInterface
6868
*/
6969
private $errors;
7070

71+
/**
72+
* String representing the output summary found after running the execute() function.
73+
* @var string
74+
*/
75+
private $output;
76+
7177
/**
7278
* Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module
7379
*
7480
* @param InputInterface $input
7581
* @return string
82+
* @throws Exception;
7683
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7784
*/
7885
public function execute(InputInterface $input)
@@ -109,8 +116,8 @@ public function execute(InputInterface $input)
109116
$this->errors += $this->findErrorsInFileSet($actionGroupXmlFiles);
110117
$this->errors += $this->findErrorsInFileSet($dataXmlFiles);
111118

112-
//print all errors to file
113-
return $this->printErrorsToFile($this->getErrors());
119+
// hold on to the output and print any errors to a file
120+
$this->output = $this->printErrorsToFile();
114121
}
115122

116123
/**
@@ -122,12 +129,17 @@ public function getErrors()
122129
return $this->errors;
123130
}
124131

132+
public function getOutput()
133+
{
134+
return $this->output;
135+
}
136+
125137
/**
126138
* Finds all reference errors in given set of files
127139
* @param Finder $files
128140
* @return array
129-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
130-
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
141+
* @throws TestReferenceException
142+
* @throws XmlException
131143
*/
132144
private function findErrorsInFileSet($files)
133145
{
@@ -348,8 +360,7 @@ private function buildFileList($modulePaths, $path)
348360
* Attempts to find any MFTF entity by its name. Returns null if none are found.
349361
* @param string $name
350362
* @return mixed
351-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
352-
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
363+
* @throws XmlException
353364
*/
354365
private function findEntity($name)
355366
{
@@ -378,24 +389,29 @@ private function findEntity($name)
378389

379390
/**
380391
* Prints out given errors to file, and returns summary result string
381-
* @param array $errors
382392
* @return string
383393
*/
384-
private function printErrorsToFile($errors)
394+
private function printErrorsToFile()
385395
{
396+
$errors = $this->getErrors();
397+
386398
if (empty($errors)) {
387399
return "No Dependency errors found.";
388400
}
401+
389402
$outputPath = getcwd() . DIRECTORY_SEPARATOR . "mftf-dependency-checks.txt";
390403
$fileResource = fopen($outputPath, 'w');
391404
$header = "MFTF File Dependency Check:\n";
392405
fwrite($fileResource, $header);
406+
393407
foreach ($errors as $test => $error) {
394408
fwrite($fileResource, $error[0] . PHP_EOL);
395409
}
410+
396411
fclose($fileResource);
397412
$errorCount = count($errors);
398413
$output = "Dependency errors found across {$errorCount} file(s). Error details output to {$outputPath}";
414+
399415
return $output;
400416
}
401417
}

0 commit comments

Comments
 (0)