diff --git a/RoboFile.php b/RoboFile.php index 99d27a639..2823e2c23 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -44,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; @@ -59,7 +59,8 @@ function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => nu throw new Exception('Please run vendor/bin/robo build:project and configure your environment (.env) first.'); } - \Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance()->createAllTestFiles($opts['config'], $opts['nodes']); + \Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance() + ->createAllTestFiles($opts['config'], $opts['nodes'], $opts['debug']); $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..70a138d35 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php @@ -159,4 +159,21 @@ 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 = []; + $orderList = $this->getOrderedActions(); + + 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 b6c2071ea..b98f2bf5b 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -52,6 +52,13 @@ class TestGenerator */ private $tests; + /** + * Symfony console output interface. + * + * @var \Symfony\Component\Console\Output\ConsoleOutput + */ + private $consoleOutput; + /** * TestGenerator constructor. * @@ -69,6 +76,7 @@ private function __construct($exportDir, $tests) . DIRECTORY_SEPARATOR . $exportDir; $this->tests = $tests; + $this->consoleOutput = new \Symfony\Component\Console\Output\ConsoleOutput(); } /** @@ -135,11 +143,12 @@ private function createCestFile($testPhp, $filename) * * @param string $runConfig * @param int $nodes + * @param bool $debug * @return void * @throws TestReferenceException * @throws \Exception */ - public function createAllTestFiles($runConfig = null, $nodes = null) + public function createAllTestFiles($runConfig = null, $nodes = null, $debug = false) { DirSetupUtil::createGroupDir($this->exportDirectory); @@ -149,7 +158,7 @@ public function createAllTestFiles($runConfig = null, $nodes = null) $this->exportDirectory, $runConfig ); - $testPhpArray = $this->assembleAllTestPhp($testManifest, $nodes); + $testPhpArray = $this->assembleAllTestPhp($testManifest, $nodes, $debug); foreach ($testPhpArray as $testPhpFile) { $this->createCestFile($testPhpFile[1], $testPhpFile[0]); @@ -196,22 +205,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() . PHP_EOL, $debug); } $testManifest->generate($nodes); @@ -219,6 +234,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->consoleOutput->writeln($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.