Skip to content

magento/magento2-functional-testing-framework#57: Debug flag exists i… #70

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 5 commits into from
Mar 29, 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
5 changes: 3 additions & 2 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
}

Expand Down
17 changes: 17 additions & 0 deletions src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
38 changes: 35 additions & 3 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class TestGenerator
*/
private $tests;

/**
* Symfony console output interface.
*
* @var \Symfony\Component\Console\Output\ConsoleOutput
*/
private $consoleOutput;

/**
* TestGenerator constructor.
*
Expand All @@ -69,6 +76,7 @@ private function __construct($exportDir, $tests)
. DIRECTORY_SEPARATOR
. $exportDir;
$this->tests = $tests;
$this->consoleOutput = new \Symfony\Component\Console\Output\ConsoleOutput();
}

/**
Expand Down Expand Up @@ -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);

Expand All @@ -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]);
Expand Down Expand Up @@ -196,29 +205,52 @@ 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);

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.
Expand Down