From 8c8a7718539674cebc211736b2bab22c0af665be Mon Sep 17 00:00:00 2001 From: StasKozar Date: Sat, 24 Mar 2018 16:25:14 +0200 Subject: [PATCH 1/4] magento/magento2-functional-testing-framework#57: Debug flag exists in robo generate:tests to print action sequence of test steps --- RoboFile.php | 8 +++- .../Test/Objects/TestObject.php | 18 +++++++++ .../Util/TestGenerator.php | 38 +++++++++++++++++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 0b891094b..9b4570b7b 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser; /** This is project's console commands configuration for Robo task runner. * @@ -43,7 +44,7 @@ function buildProject() * @param array $opts * @return void */ - function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => null]) + function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => null, 'debug' => false]) { $GLOBALS['GENERATE_TESTS'] = true; @@ -51,9 +52,12 @@ function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => nu { $GLOBALS['FORCE_PHP_GENERATE'] = true; } + + $output = $this->getOutput() ?? null; require 'dev' . DIRECTORY_SEPARATOR . 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php'; - \Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance()->createAllTestFiles($opts['config'], $opts['nodes']); + \Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance() + ->createAllTestFiles($opts['config'], $opts['nodes'], $opts['debug'], $output); $this->say("Generate Tests Command Run"); } diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php index de64100b8..8afdfd3d1 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php @@ -159,4 +159,22 @@ public function getOrderedActions() $mergeUtil = new ActionMergeUtil($this->getName(), "Test"); return $mergeUtil->resolveActionSteps($this->parsedSteps); } + + /** + * Get information about actions and steps in test. + * + * @return array + */ + public function getDebugInformation() + { + $debugInformation = []; + $mergeUtil = new ActionMergeUtil($this->getName(), "Test"); + $orderList = $mergeUtil->resolveActionSteps($this->parsedSteps); + + foreach ($orderList as $action) { + $debugInformation[] = "\t" . $action->getType() . ' ' . $action->getStepKey(); + } + + return $debugInformation; + } } diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 2ac2d0abd..0fb54a992 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -20,6 +20,8 @@ use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor; use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor; use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil; +use Robo\Common\IO; +use Symfony\Component\Console\Output\OutputInterface; /** * Class TestGenerator @@ -27,6 +29,8 @@ */ class TestGenerator { + use IO; + const REQUIRED_ENTITY_REFERENCE = 'createDataKey'; const GENERATED_DIR = '_generated'; @@ -132,17 +136,22 @@ private function createCestFile($testPhp, $filename) * * @param string $runConfig * @param int $nodes + * @param bool $debug + * @param OutputInterface|null $output * @return void * @throws TestReferenceException * @throws \Exception */ - public function createAllTestFiles($runConfig = null, $nodes = null) + public function createAllTestFiles($runConfig = null, $nodes = null, $debug = false, $output = null) { DirSetupUtil::createGroupDir($this->exportDirectory); + if ($output !== null) { + $this->setOutput($output); + } // create our manifest file here $testManifest = TestManifestFactory::makeManifest($this->exportDirectory, $runConfig); - $testPhpArray = $this->assembleAllTestPhp($testManifest, $nodes); + $testPhpArray = $this->assembleAllTestPhp($testManifest, $nodes, $debug); foreach ($testPhpArray as $testPhpFile) { $this->createCestFile($testPhpFile[1], $testPhpFile[0]); @@ -189,22 +198,28 @@ private function assembleTestPhp($testObject) * * @param BaseTestManifest $testManifest * @param int $nodes + * @param bool $debug * @return array * @throws TestReferenceException * @throws \Exception */ - private function assembleAllTestPhp($testManifest, $nodes) + private function assembleAllTestPhp($testManifest, $nodes, $debug = false) { /** @var TestObject[] $testObjects */ $testObjects = $this->loadAllTestObjects(); $cestPhpArray = []; foreach ($testObjects as $test) { + $this->debug('Start creating test: ' . $test->getCodeceptionName(), $debug); $php = $this->assembleTestPhp($test); $cestPhpArray[] = [$test->getCodeceptionName(), $php]; //write to manifest here if config is not single run $testManifest->addTest($test); + $debugInformation = $test->getDebugInformation(); + + $this->debug($debugInformation, $debug); + $this->debug('Finish creating test ' . $test->getCodeceptionName(), $debug); } $testManifest->generate($nodes); @@ -212,6 +227,23 @@ private function assembleAllTestPhp($testManifest, $nodes) return $cestPhpArray; } + /** + * Output information in console when debug flag is enabled. + * + * @param array|string $messages + * @param bool $debug + * @return void + */ + private function debug($messages, $debug = false) + { + if ($debug && $messages) { + $messages = (array) $messages; + foreach ($messages as $message) { + $this->say($message); + } + } + } + /** * Creates a PHP string for the necessary Allure and AcceptanceTester use statements. * Since we don't support other dependencies at this time, this function takes no parameter. From 91ef18865c46877a80cb39e4013d908c9e8650bb Mon Sep 17 00:00:00 2001 From: StasKozar Date: Sat, 24 Mar 2018 17:33:03 +0200 Subject: [PATCH 2/4] magento/magento2-functional-testing-framework#57: Debug flag exists in robo generate:tests to print action sequence of test steps --- RoboFile.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 9b4570b7b..2f5c7988d 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser; /** This is project's console commands configuration for Robo task runner. * @@ -52,12 +51,10 @@ function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => nu { $GLOBALS['FORCE_PHP_GENERATE'] = true; } - - $output = $this->getOutput() ?? null; require 'dev' . DIRECTORY_SEPARATOR . 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php'; \Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance() - ->createAllTestFiles($opts['config'], $opts['nodes'], $opts['debug'], $output); + ->createAllTestFiles($opts['config'], $opts['nodes'], $opts['debug'], $this->getOutput()); $this->say("Generate Tests Command Run"); } From 5f3438cf22ac2ff999328f00a937ac36caaab547 Mon Sep 17 00:00:00 2001 From: StasKozar Date: Sat, 24 Mar 2018 17:40:28 +0200 Subject: [PATCH 3/4] magento/magento2-functional-testing-framework#57: Debug flag exists in robo generate:tests to print action sequence of test steps --- .../FunctionalTestingFramework/Test/Objects/TestObject.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php index 8afdfd3d1..70a138d35 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php @@ -168,8 +168,7 @@ public function getOrderedActions() public function getDebugInformation() { $debugInformation = []; - $mergeUtil = new ActionMergeUtil($this->getName(), "Test"); - $orderList = $mergeUtil->resolveActionSteps($this->parsedSteps); + $orderList = $this->getOrderedActions(); foreach ($orderList as $action) { $debugInformation[] = "\t" . $action->getType() . ' ' . $action->getStepKey(); From 12ca5e4effb3786f786b87084a1aa90dd91c557a Mon Sep 17 00:00:00 2001 From: Alex Kolesnyk Date: Thu, 29 Mar 2018 19:29:06 +0300 Subject: [PATCH 4/4] MQE-904: Deliver changes from Magento Contribution Day --- RoboFile.php | 2 +- .../Util/TestGenerator.php | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 2f5c7988d..db3d4de40 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -54,7 +54,7 @@ function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => nu require 'dev' . DIRECTORY_SEPARATOR . 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php'; \Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance() - ->createAllTestFiles($opts['config'], $opts['nodes'], $opts['debug'], $this->getOutput()); + ->createAllTestFiles($opts['config'], $opts['nodes'], $opts['debug']); $this->say("Generate Tests Command Run"); } diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 0fb54a992..0e73b8a4d 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -20,8 +20,6 @@ use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor; use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor; use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil; -use Robo\Common\IO; -use Symfony\Component\Console\Output\OutputInterface; /** * Class TestGenerator @@ -29,8 +27,6 @@ */ class TestGenerator { - use IO; - const REQUIRED_ENTITY_REFERENCE = 'createDataKey'; const GENERATED_DIR = '_generated'; @@ -55,6 +51,13 @@ class TestGenerator */ private $tests; + /** + * Symfony console output interface. + * + * @var \Symfony\Component\Console\Output\ConsoleOutput + */ + private $consoleOutput; + /** * TestGenerator constructor. * @@ -70,6 +73,7 @@ private function __construct($exportDir, $tests) DIRECTORY_SEPARATOR ); $this->tests = $tests; + $this->consoleOutput = new \Symfony\Component\Console\Output\ConsoleOutput(); } /** @@ -137,20 +141,19 @@ private function createCestFile($testPhp, $filename) * @param string $runConfig * @param int $nodes * @param bool $debug - * @param OutputInterface|null $output * @return void * @throws TestReferenceException * @throws \Exception */ - public function createAllTestFiles($runConfig = null, $nodes = null, $debug = false, $output = null) + public function createAllTestFiles($runConfig = null, $nodes = null, $debug = false) { DirSetupUtil::createGroupDir($this->exportDirectory); - if ($output !== null) { - $this->setOutput($output); - } - // create our manifest file here - $testManifest = TestManifestFactory::makeManifest($this->exportDirectory, $runConfig); + $testManifest = TestManifestFactory::makeManifest( + dirname($this->exportDirectory), + $this->exportDirectory, + $runConfig + ); $testPhpArray = $this->assembleAllTestPhp($testManifest, $nodes, $debug); foreach ($testPhpArray as $testPhpFile) { @@ -219,7 +222,7 @@ private function assembleAllTestPhp($testManifest, $nodes, $debug = false) $debugInformation = $test->getDebugInformation(); $this->debug($debugInformation, $debug); - $this->debug('Finish creating test ' . $test->getCodeceptionName(), $debug); + $this->debug('Finish creating test ' . $test->getCodeceptionName() . PHP_EOL, $debug); } $testManifest->generate($nodes); @@ -239,7 +242,7 @@ private function debug($messages, $debug = false) if ($debug && $messages) { $messages = (array) $messages; foreach ($messages as $message) { - $this->say($message); + $this->consoleOutput->writeln($message); } } }