Skip to content

MQE-810: Create a static test to validate references between modules #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(array $commands = [])
'run:failed' => new RunTestFailedCommand(),
'setup:env' => new SetupEnvCommand(),
'upgrade:tests' => new UpgradeTestsCommand(),
'static-checks' => new StaticChecksCommand(),
] + $commands;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
// @codingStandardsIgnoreFile
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);

namespace Magento\FunctionalTestingFramework\Console;

use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

class StaticChecksCommand extends Command
{
/**
* Pool of static check scripts to run
*
* @var \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface
*/
private $staticChecksList;

/**
* Configures the current command.
*
* @return void
*/
protected function configure()
{
$this->setName('static-checks')
->setDescription('This command will run all static checks on xml test materials.');
$this->staticChecksList = new StaticChecksList();
}

/**
*
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$staticCheckObjects = $this->staticChecksList->getStaticChecks();
foreach ($staticCheckObjects as $staticCheck) {
$staticOutput = $staticCheck->execute($input);
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info($staticOutput);
$output->writeln($staticOutput);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DataObjectHandler implements ObjectHandlerInterface
const _ENTITY_KEY = 'entityKey';
const _SEPARATOR = '->';
const _REQUIRED_ENTITY = 'requiredEntity';
const _FILENAME = 'filename';
const DATA_NAME_ERROR_MSG = "Entity names cannot contain non alphanumeric characters.\tData='%s'";

/**
Expand Down Expand Up @@ -134,6 +135,7 @@ private function processParserOutput($parserOutput)
$uniquenessData = [];
$vars = [];
$parentEntity = null;
$filename = $rawEntity[self::_FILENAME] ?? null;

if (array_key_exists(self::_DATA, $rawEntity)) {
$data = $this->processDataElements($rawEntity);
Expand Down Expand Up @@ -167,7 +169,8 @@ private function processParserOutput($parserOutput)
$linkedEntities,
$uniquenessData,
$vars,
$parentEntity
$parentEntity,
$filename
);

$entityDataObjects[$entityDataObject->getName()] = $entityDataObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class EntityDataObject
*/
private $parentEntity;

/**
* String of filename
* @var string
*/
private $filename;

/**
* Constructor
*
Expand All @@ -82,9 +88,18 @@ class EntityDataObject
* @param string[] $uniquenessData
* @param string[] $vars
* @param string $parentEntity
* @param string $filename
*/
public function __construct($name, $type, $data, $linkedEntities, $uniquenessData, $vars = [], $parentEntity = null)
{
public function __construct(
$name,
$type,
$data,
$linkedEntities,
$uniquenessData,
$vars = [],
$parentEntity = null,
$filename = null
) {
$this->name = $name;
$this->type = $type;
$this->data = $data;
Expand All @@ -95,6 +110,7 @@ public function __construct($name, $type, $data, $linkedEntities, $uniquenessDat

$this->vars = $vars;
$this->parentEntity = $parentEntity;
$this->filename = $filename;
}

/**
Expand All @@ -107,6 +123,16 @@ public function getName()
return $this->name;
}

/**
* Getter for the Entity Filename
*
* @return string
*/
public function getFilename()
{
return $this->filename;
}

/**
* Get the type of this entity data object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public function extendEntity($entityObject)
$newLinkedReferences,
$newUniqueReferences,
$newVarReferences,
$entityObject->getParentName()
$entityObject->getParentName(),
$entityObject->getFilename()
);
return $extendedEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PageObjectHandler implements ObjectHandlerInterface
const MODULE = 'module';
const PARAMETERIZED = 'parameterized';
const AREA = 'area';
const FILENAME = 'filename';
const NAME_BLACKLIST_ERROR_MSG = "Page names cannot contain non alphanumeric characters.\tPage='%s'";

/**
Expand Down Expand Up @@ -66,9 +67,10 @@ private function __construct()
$module = $pageData[self::MODULE];
$sectionNames = array_keys($pageData[self::SECTION] ?? []);
$parameterized = $pageData[self::PARAMETERIZED] ?? false;
$filename = $pageData[self::FILENAME] ?? null;

$this->pageObjects[$pageName] =
new PageObject($pageName, $url, $module, $sectionNames, $parameterized, $area);
new PageObject($pageName, $url, $module, $sectionNames, $parameterized, $area, $filename);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SectionObjectHandler implements ObjectHandlerInterface
const LOCATOR_FUNCTION = 'locatorFunction';
const TIMEOUT = 'timeout';
const PARAMETERIZED = 'parameterized';
const FILENAME = 'filename';
const SECTION_NAME_ERROR_MSG = "Section names cannot contain non alphanumeric characters.\tSection='%s'";
const ELEMENT_NAME_ERROR_MSG = "Element names cannot contain non alphanumeric characters.\tElement='%s'";

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

$this->sectionObjects[$sectionName] = new SectionObject($sectionName, $elements);
$filename = $sectionData[self::FILENAME] ?? null;
$this->sectionObjects[$sectionName] = new SectionObject($sectionName, $elements, $filename);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ class PageObject
*/
private $area;

/**
* Filename of where the page came from
*
* @var string
*/
private $filename;

/**
* PageObject constructor.
* @param string $name
Expand All @@ -66,15 +73,17 @@ class PageObject
* @param array $sections
* @param boolean $parameterized
* @param string $area
* @param string $filename
*/
public function __construct($name, $url, $module, $sections, $parameterized, $area)
public function __construct($name, $url, $module, $sections, $parameterized, $area, $filename = null)
{
$this->name = $name;
$this->url = $url;
$this->module = $module;
$this->sectionNames = $sections;
$this->parameterized = $parameterized;
$this->area = $area;
$this->filename = $filename;
}

/**
Expand All @@ -87,6 +96,16 @@ public function getName()
return $this->name;
}

/**
* Getter for the Page Filename
*
* @return string
*/
public function getFilename()
{
return $this->filename;
}

/**
* Getter for Page URL
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@ class SectionObject
*/
private $elements = [];

/**
* Filename of where the section came from
*
* @var string
*/
private $filename;

/**
* SectionObject constructor.
* @param string $name
* @param array $elements
* @param string $filename
*/
public function __construct($name, $elements)
public function __construct($name, $elements, $filename = null)
{
$this->name = $name;
$this->elements = $elements;
$this->filename = $filename;
}

/**
Expand All @@ -46,6 +55,16 @@ public function getName()
return $this->name;
}

/**
* Getter for the Section Filename
*
* @return string
*/
public function getFilename()
{
return $this->filename;
}

/**
* Getter for an array containing all of a section's elements.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\FunctionalTestingFramework\StaticCheck;

use Symfony\Component\Console\Input\InputInterface;

/**
* Static check script interface
*/
interface StaticCheckInterface
{
/**
* Executes static check script, returns output.
* @param InputInterface $input
* @return string
*/
public function execute(InputInterface $input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\StaticCheck;

/**
* Contains a list of Static Check Scripts
* @api
*/
interface StaticCheckListInterface
{
/**
* Gets list of static check script instances
*
* @return \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface[]
*/
public function getStaticChecks();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\FunctionalTestingFramework\StaticCheck;

/**
* Class StaticChecksList has a list of static checks to run on test xml
* @codingStandardsIgnoreFile
*/
class StaticChecksList implements StaticCheckListInterface
{
/**
* Property contains all static check scripts.
*
* @var \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface[]
*/
private $checks;

/**
* Constructor
*
* @param array $scripts
*/
public function __construct(array $checks = [])
{
$this->checks = [
'testDependencies' => new TestDependencyCheck(),
] + $checks;
}

/**
* {@inheritdoc}
*/
public function getStaticChecks()
{
return $this->checks;
}
}
Loading