Skip to content

MQE-917: Eliminate usage of XSD relative paths #152

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 15 commits into from
Jun 19, 2018
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
31 changes: 17 additions & 14 deletions bin/mftf
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@ if (PHP_SAPI !== 'cli') {
exit(1);
}

$autoload_path = realpath(__DIR__ . '/../../../autoload.php');
$test_bootstrap_path = realpath(__DIR__ . '/../dev/tests/functional/_bootstrap.php');
$autoloadPath = realpath(__DIR__ . '/../../../autoload.php');
$testBootstrapPath = realpath(__DIR__ . '/../dev/tests/functional/_bootstrap.php');

if (file_exists($autoload_path)) {
require_once $autoload_path;
} else {
require_once $test_bootstrap_path;
try {
if (file_exists($autoloadPath)) {
require_once $autoloadPath;
} else {
require_once $testBootstrapPath;
}
} catch (\Exception $e) {
echo 'Autoload error: ' . $e->getMessage();
exit(1);
}


try {
$application = new Symfony\Component\Console\Application();
$application->setName('Magento Functional Testing Framework CLI');
$application->setVersion('1.0.0');
$application->add(new Magento\FunctionalTestingFramework\Console\SetupEnvCommand());
$application->add(new Magento\FunctionalTestingFramework\Console\CleanProjectCommand());
$application->add(new Magento\FunctionalTestingFramework\Console\BuildProjectCommand());
$application->add(new Magento\FunctionalTestingFramework\Console\GenerateSuiteCommand());
$application->add(new Magento\FunctionalTestingFramework\Console\GenerateTestsCommand());
$application->add(new Magento\FunctionalTestingFramework\Console\RunTestGroupCommand());
$application->add(new Magento\FunctionalTestingFramework\Console\RunTestCommand());
$application->setVersion('2.3.0');
/** @var \Magento\FunctionalTestingFramework\Console\CommandListInterface $commandList */
$commandList = new \Magento\FunctionalTestingFramework\Console\CommandList;
foreach ($commandList->getCommands() as $command) {
$application->add($command);
}
$application->run();
} catch (\Exception $e) {
while ($e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class BuildProjectCommand extends Command
protected function configure()
{
$this->setName('build:project')
->setDescription('Generate configuration files for the project. Build the Codeception project.');
->setDescription('Generate configuration files for the project. Build the Codeception project.')
->addOption("upgrade", 'u', InputOption::VALUE_NONE, 'upgrade existing MFTF tests according to last major release requiements');
$this->envProcessor = new EnvProcessor(TESTS_BP . DIRECTORY_SEPARATOR . '.env');
$env = $this->envProcessor->getEnv();
foreach ($env as $key => $value) {
Expand All @@ -58,6 +59,10 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$resetCommand = new CleanProjectCommand();
$resetOptions = new ArrayInput([]);
$resetCommand->run($resetOptions, $output);

$this->generateConfigFiles($output);

$setupEnvCommand = new SetupEnvCommand();
Expand Down Expand Up @@ -87,6 +92,12 @@ function ($type, $buffer) use ($output) {
}
}
);

if ($input->getOption('upgrade')) {
$upgradeCommand = new UpgradeTestsCommand();
$upgradeOptions = new ArrayInput(['path' => TESTS_MODULE_PATH]);
$upgradeCommand->run($upgradeOptions, $output);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

class CleanProjectCommand extends Command
{
Expand Down
50 changes: 50 additions & 0 deletions src/Magento/FunctionalTestingFramework/Console/CommandList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\FunctionalTestingFramework\Console;

/**
* Class CommandList has a list of commands.
* @codingStandardsIgnoreFile
*/
class CommandList implements CommandListInterface
{
/**
* List of Commands
* @var \Symfony\Component\Console\Command\Command[]
*/
private $commands;

/**
* Constructor
*
* @param array $commands
*/
public function __construct(array $commands = [])
{
$this->commands = [
'build:project' => new BuildProjectCommand(),
'reset' => new CleanProjectCommand(),
'generate:urn-catalog' => new GenerateDevUrnCommand(),
'generate:suite' => new GenerateSuiteCommand(),
'generate:tests' => new GenerateTestsCommand(),
'run:test' => new RunTestCommand(),
'run:group' => new RunTestGroupCommand(),
'setup:env' => new SetupEnvCommand(),
'upgrade:tests' => new UpgradeTestsCommand(),
] + $commands;
}

/**
* {@inheritdoc}
*/
public function getCommands()
{
return $this->commands;
}
}
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\Console;

/**
* Contains a list of Console commands
* @api
*/
interface CommandListInterface
{
/**
* Gets list of command instances
*
* @return \Symfony\Component\Console\Command\Command[]
*/
public function getCommands();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?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\Exceptions\TestFrameworkException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateDevUrnCommand extends Command
{
/**
* Configures the current command.
*
* @return void
*/
protected function configure()
{
$this->setName('generate:urn-catalog')
->setDescription('This command generates an URN catalog to enable PHPStorm to recognize and highlight URNs.')
->addArgument('path', InputArgument::REQUIRED, 'path to PHPStorm misc.xml file (typically located in [ProjectRoot]/.idea/misc.xml)');
}

/**
* Executes the current command.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$miscXmlFilePath = $input->getArgument('path') . DIRECTORY_SEPARATOR . "misc.xml";
$miscXmlFile = realpath($miscXmlFilePath);

if ($miscXmlFile === false) {
$exceptionMessage = "misc.xml not found in given path '{$miscXmlFilePath}'";
LoggingUtil::getInstance()->getLogger(GenerateDevUrnCommand::class)
->error($exceptionMessage);
throw new TestFrameworkException($exceptionMessage);
}
$dom = new \DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML(file_get_contents($miscXmlFile));

//Locate ProjectResources node, create one if none are found.
$nodeForWork = null;
foreach($dom->getElementsByTagName('component') as $child) {
if ($child->getAttribute('name') === 'ProjectResources') {
$nodeForWork = $child;
}
}
if ($nodeForWork === null) {
$project = $dom->getElementsByTagName('project')->item(0);
$nodeForWork = $dom->createElement('component');
$nodeForWork->setAttribute('name', 'ProjectResources');
$project->appendChild($nodeForWork);
}

//Extract url=>location mappings that already exist, add MFTF URNs and reappend
$resources = [];
$resourceNodes = $nodeForWork->getElementsByTagName('resource');
$resourceCount = $resourceNodes->length;
for ($i = 0; $i < $resourceCount; $i++) {
$child = $resourceNodes[0];
$resources[$child->getAttribute('url')] = $child->getAttribute('location');
$child->parentNode->removeChild($child);
}

$resources = array_merge($resources, $this->generateResourcesArray());

foreach ($resources as $url => $location) {
$resourceNode = $dom->createElement('resource');
$resourceNode->setAttribute('url', $url);
$resourceNode->setAttribute('location', $location);
$nodeForWork->appendChild($resourceNode);
}

//Save output
$dom->save($miscXmlFile);
$output->writeln("MFTF URN mapping successfully added to {$miscXmlFile}.");
}

/**
* Generates urn => location array for all MFTF schema.
* @return array
*/
private function generateResourcesArray()
{
$resourcesArray = [
'urn:magento:mftf:DataGenerator/etc/dataOperation.xsd' =>
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd'),
'urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd' =>
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd'),
'urn:magento:mftf:Page/etc/PageObject.xsd' =>
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd'),
'urn:magento:mftf:Page/etc/SectionObject.xsd' =>
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd'),
'urn:magento:mftf:Test/etc/actionGroupSchema.xsd' =>
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd'),
'urn:magento:mftf:Test/etc/testSchema.xsd' =>
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd'),
'urn:magento:mftf:Suite/etc/suiteSchema.xsd' =>
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd')
];
return $resourcesArray;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected function configure()
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
* @throws \Symfony\Component\Console\Exception\LogicException
* @return int|null|void
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ protected function configure()
* @param InputInterface $input
* @param OutputInterface $output
* @return void
* @throws \Symfony\Component\Console\Exception\LogicException|TestFrameworkException
* @throws TestFrameworkException
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down Expand Up @@ -97,6 +99,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @param bool $debug
* @param bool $verbose
* @return array
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
*/
private function createTestConfiguration($json, array $tests, bool $force, bool $debug, bool $verbose)
{
Expand Down Expand Up @@ -134,10 +138,10 @@ private function createTestConfiguration($json, array $tests, bool $force, bool
*
* @param string $json
* @param array $testConfiguration
* @throws TestFrameworkException
* @return array
*/
private function parseTestsConfigJson($json, array $testConfiguration) {
private function parseTestsConfigJson($json, array $testConfiguration)
{
if ($json === null) {
return $testConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected function configure()
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
* @throws \Symfony\Component\Console\Exception\LogicException
* @return int|null|void
* @throws \Exception
*
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected function configure()
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
* @throws \Symfony\Component\Console\Exception\LogicException
* @return int|null|void
* @throws \Exception
*
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
Expand Down Expand Up @@ -82,6 +82,7 @@ function ($type, $buffer) use ($output) {
*
* @param array $groups
* @return string
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
*/
private function getGroupAndSuiteConfiguration(array $groups)
{
Expand Down
Loading