Skip to content

Commit 7f82e4d

Browse files
authored
MQE-810: Create a static test to validate references between modules
- Implemented static-checks command - Checks test material dependencies of MAGENTO_BP modules
1 parent 44aecc6 commit 7f82e4d

18 files changed

+637
-16
lines changed

src/Magento/FunctionalTestingFramework/Console/CommandList.php

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function __construct(array $commands = [])
3838
'run:failed' => new RunTestFailedCommand(),
3939
'setup:env' => new SetupEnvCommand(),
4040
'upgrade:tests' => new UpgradeTestsCommand(),
41+
'static-checks' => new StaticChecksCommand(),
4142
] + $commands;
4243
}
4344

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
// @codingStandardsIgnoreFile
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types = 1);
8+
9+
namespace Magento\FunctionalTestingFramework\Console;
10+
11+
use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
12+
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
13+
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
18+
class StaticChecksCommand extends Command
19+
{
20+
/**
21+
* Pool of static check scripts to run
22+
*
23+
* @var \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface
24+
*/
25+
private $staticChecksList;
26+
27+
/**
28+
* Configures the current command.
29+
*
30+
* @return void
31+
*/
32+
protected function configure()
33+
{
34+
$this->setName('static-checks')
35+
->setDescription('This command will run all static checks on xml test materials.');
36+
$this->staticChecksList = new StaticChecksList();
37+
}
38+
39+
/**
40+
*
41+
*
42+
* @param InputInterface $input
43+
* @param OutputInterface $output
44+
* @return int|null|void
45+
* @throws \Exception
46+
*/
47+
protected function execute(InputInterface $input, OutputInterface $output)
48+
{
49+
$staticCheckObjects = $this->staticChecksList->getStaticChecks();
50+
foreach ($staticCheckObjects as $staticCheck) {
51+
$staticOutput = $staticCheck->execute($input);
52+
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info($staticOutput);
53+
$output->writeln($staticOutput);
54+
}
55+
}
56+
}

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/DataObjectHandler.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class DataObjectHandler implements ObjectHandlerInterface
3232
const _ENTITY_KEY = 'entityKey';
3333
const _SEPARATOR = '->';
3434
const _REQUIRED_ENTITY = 'requiredEntity';
35+
const _FILENAME = 'filename';
3536
const DATA_NAME_ERROR_MSG = "Entity names cannot contain non alphanumeric characters.\tData='%s'";
3637

3738
/**
@@ -134,6 +135,7 @@ private function processParserOutput($parserOutput)
134135
$uniquenessData = [];
135136
$vars = [];
136137
$parentEntity = null;
138+
$filename = $rawEntity[self::_FILENAME] ?? null;
137139

138140
if (array_key_exists(self::_DATA, $rawEntity)) {
139141
$data = $this->processDataElements($rawEntity);
@@ -167,7 +169,8 @@ private function processParserOutput($parserOutput)
167169
$linkedEntities,
168170
$uniquenessData,
169171
$vars,
170-
$parentEntity
172+
$parentEntity,
173+
$filename
171174
);
172175

173176
$entityDataObjects[$entityDataObject->getName()] = $entityDataObject;

src/Magento/FunctionalTestingFramework/DataGenerator/Objects/EntityDataObject.php

+28-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ class EntityDataObject
7272
*/
7373
private $parentEntity;
7474

75+
/**
76+
* String of filename
77+
* @var string
78+
*/
79+
private $filename;
80+
7581
/**
7682
* Constructor
7783
*
@@ -82,9 +88,18 @@ class EntityDataObject
8288
* @param string[] $uniquenessData
8389
* @param string[] $vars
8490
* @param string $parentEntity
91+
* @param string $filename
8592
*/
86-
public function __construct($name, $type, $data, $linkedEntities, $uniquenessData, $vars = [], $parentEntity = null)
87-
{
93+
public function __construct(
94+
$name,
95+
$type,
96+
$data,
97+
$linkedEntities,
98+
$uniquenessData,
99+
$vars = [],
100+
$parentEntity = null,
101+
$filename = null
102+
) {
88103
$this->name = $name;
89104
$this->type = $type;
90105
$this->data = $data;
@@ -95,6 +110,7 @@ public function __construct($name, $type, $data, $linkedEntities, $uniquenessDat
95110

96111
$this->vars = $vars;
97112
$this->parentEntity = $parentEntity;
113+
$this->filename = $filename;
98114
}
99115

100116
/**
@@ -107,6 +123,16 @@ public function getName()
107123
return $this->name;
108124
}
109125

126+
/**
127+
* Getter for the Entity Filename
128+
*
129+
* @return string
130+
*/
131+
public function getFilename()
132+
{
133+
return $this->filename;
134+
}
135+
110136
/**
111137
* Get the type of this entity data object
112138
*

src/Magento/FunctionalTestingFramework/DataGenerator/Util/DataExtensionUtil.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public function extendEntity($entityObject)
9292
$newLinkedReferences,
9393
$newUniqueReferences,
9494
$newVarReferences,
95-
$entityObject->getParentName()
95+
$entityObject->getParentName(),
96+
$entityObject->getFilename()
9697
);
9798
return $extendedEntity;
9899
}

src/Magento/FunctionalTestingFramework/Page/Handlers/PageObjectHandler.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PageObjectHandler implements ObjectHandlerInterface
2020
const MODULE = 'module';
2121
const PARAMETERIZED = 'parameterized';
2222
const AREA = 'area';
23+
const FILENAME = 'filename';
2324
const NAME_BLACKLIST_ERROR_MSG = "Page names cannot contain non alphanumeric characters.\tPage='%s'";
2425

2526
/**
@@ -66,9 +67,10 @@ private function __construct()
6667
$module = $pageData[self::MODULE];
6768
$sectionNames = array_keys($pageData[self::SECTION] ?? []);
6869
$parameterized = $pageData[self::PARAMETERIZED] ?? false;
70+
$filename = $pageData[self::FILENAME] ?? null;
6971

7072
$this->pageObjects[$pageName] =
71-
new PageObject($pageName, $url, $module, $sectionNames, $parameterized, $area);
73+
new PageObject($pageName, $url, $module, $sectionNames, $parameterized, $area, $filename);
7274
}
7375
}
7476

src/Magento/FunctionalTestingFramework/Page/Handlers/SectionObjectHandler.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class SectionObjectHandler implements ObjectHandlerInterface
2222
const LOCATOR_FUNCTION = 'locatorFunction';
2323
const TIMEOUT = 'timeout';
2424
const PARAMETERIZED = 'parameterized';
25+
const FILENAME = 'filename';
2526
const SECTION_NAME_ERROR_MSG = "Section names cannot contain non alphanumeric characters.\tSection='%s'";
2627
const ELEMENT_NAME_ERROR_MSG = "Element names cannot contain non alphanumeric characters.\tElement='%s'";
2728

@@ -86,7 +87,8 @@ private function __construct()
8687
throw new XmlException($exception->getMessage() . " in Section '{$sectionName}'");
8788
}
8889

89-
$this->sectionObjects[$sectionName] = new SectionObject($sectionName, $elements);
90+
$filename = $sectionData[self::FILENAME] ?? null;
91+
$this->sectionObjects[$sectionName] = new SectionObject($sectionName, $elements, $filename);
9092
}
9193
}
9294

src/Magento/FunctionalTestingFramework/Page/Objects/PageObject.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class PageObject
5858
*/
5959
private $area;
6060

61+
/**
62+
* Filename of where the page came from
63+
*
64+
* @var string
65+
*/
66+
private $filename;
67+
6168
/**
6269
* PageObject constructor.
6370
* @param string $name
@@ -66,15 +73,17 @@ class PageObject
6673
* @param array $sections
6774
* @param boolean $parameterized
6875
* @param string $area
76+
* @param string $filename
6977
*/
70-
public function __construct($name, $url, $module, $sections, $parameterized, $area)
78+
public function __construct($name, $url, $module, $sections, $parameterized, $area, $filename = null)
7179
{
7280
$this->name = $name;
7381
$this->url = $url;
7482
$this->module = $module;
7583
$this->sectionNames = $sections;
7684
$this->parameterized = $parameterized;
7785
$this->area = $area;
86+
$this->filename = $filename;
7887
}
7988

8089
/**
@@ -87,6 +96,16 @@ public function getName()
8796
return $this->name;
8897
}
8998

99+
/**
100+
* Getter for the Page Filename
101+
*
102+
* @return string
103+
*/
104+
public function getFilename()
105+
{
106+
return $this->filename;
107+
}
108+
90109
/**
91110
* Getter for Page URL
92111
*

src/Magento/FunctionalTestingFramework/Page/Objects/SectionObject.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,24 @@ class SectionObject
2525
*/
2626
private $elements = [];
2727

28+
/**
29+
* Filename of where the section came from
30+
*
31+
* @var string
32+
*/
33+
private $filename;
34+
2835
/**
2936
* SectionObject constructor.
3037
* @param string $name
3138
* @param array $elements
39+
* @param string $filename
3240
*/
33-
public function __construct($name, $elements)
41+
public function __construct($name, $elements, $filename = null)
3442
{
3543
$this->name = $name;
3644
$this->elements = $elements;
45+
$this->filename = $filename;
3746
}
3847

3948
/**
@@ -46,6 +55,16 @@ public function getName()
4655
return $this->name;
4756
}
4857

58+
/**
59+
* Getter for the Section Filename
60+
*
61+
* @return string
62+
*/
63+
public function getFilename()
64+
{
65+
return $this->filename;
66+
}
67+
4968
/**
5069
* Getter for an array containing all of a section's elements.
5170
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\StaticCheck;
8+
9+
use Symfony\Component\Console\Input\InputInterface;
10+
11+
/**
12+
* Static check script interface
13+
*/
14+
interface StaticCheckInterface
15+
{
16+
/**
17+
* Executes static check script, returns output.
18+
* @param InputInterface $input
19+
* @return string
20+
*/
21+
public function execute(InputInterface $input);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\FunctionalTestingFramework\StaticCheck;
7+
8+
/**
9+
* Contains a list of Static Check Scripts
10+
* @api
11+
*/
12+
interface StaticCheckListInterface
13+
{
14+
/**
15+
* Gets list of static check script instances
16+
*
17+
* @return \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface[]
18+
*/
19+
public function getStaticChecks();
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\FunctionalTestingFramework\StaticCheck;
9+
10+
/**
11+
* Class StaticChecksList has a list of static checks to run on test xml
12+
* @codingStandardsIgnoreFile
13+
*/
14+
class StaticChecksList implements StaticCheckListInterface
15+
{
16+
/**
17+
* Property contains all static check scripts.
18+
*
19+
* @var \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface[]
20+
*/
21+
private $checks;
22+
23+
/**
24+
* Constructor
25+
*
26+
* @param array $scripts
27+
*/
28+
public function __construct(array $checks = [])
29+
{
30+
$this->checks = [
31+
'testDependencies' => new TestDependencyCheck(),
32+
] + $checks;
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function getStaticChecks()
39+
{
40+
return $this->checks;
41+
}
42+
}

0 commit comments

Comments
 (0)