Skip to content

Commit fd0e889

Browse files
authored
Merge pull request #70 from StasKozar/MFTF-57
#57: Debug flag exists i…
2 parents e01f07e + d1a7feb commit fd0e889

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

RoboFile.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function buildProject()
4444
* @param array $opts
4545
* @return void
4646
*/
47-
function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => null])
47+
function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => null, 'debug' => false])
4848
{
4949
$GLOBALS['GENERATE_TESTS'] = true;
5050

@@ -59,7 +59,8 @@ function generateTests($opts = ['config' => null, 'force' => true, 'nodes' => nu
5959
throw new Exception('Please run vendor/bin/robo build:project and configure your environment (.env) first.');
6060
}
6161

62-
\Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance()->createAllTestFiles($opts['config'], $opts['nodes']);
62+
\Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance()
63+
->createAllTestFiles($opts['config'], $opts['nodes'], $opts['debug']);
6364
$this->say("Generate Tests Command Run");
6465
}
6566

src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,21 @@ public function getOrderedActions()
159159
$mergeUtil = new ActionMergeUtil($this->getName(), "Test");
160160
return $mergeUtil->resolveActionSteps($this->parsedSteps);
161161
}
162+
163+
/**
164+
* Get information about actions and steps in test.
165+
*
166+
* @return array
167+
*/
168+
public function getDebugInformation()
169+
{
170+
$debugInformation = [];
171+
$orderList = $this->getOrderedActions();
172+
173+
foreach ($orderList as $action) {
174+
$debugInformation[] = "\t" . $action->getType() . ' ' . $action->getStepKey();
175+
}
176+
177+
return $debugInformation;
178+
}
162179
}

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class TestGenerator
5252
*/
5353
private $tests;
5454

55+
/**
56+
* Symfony console output interface.
57+
*
58+
* @var \Symfony\Component\Console\Output\ConsoleOutput
59+
*/
60+
private $consoleOutput;
61+
5562
/**
5663
* TestGenerator constructor.
5764
*
@@ -69,6 +76,7 @@ private function __construct($exportDir, $tests)
6976
. DIRECTORY_SEPARATOR
7077
. $exportDir;
7178
$this->tests = $tests;
79+
$this->consoleOutput = new \Symfony\Component\Console\Output\ConsoleOutput();
7280
}
7381

7482
/**
@@ -135,11 +143,12 @@ private function createCestFile($testPhp, $filename)
135143
*
136144
* @param string $runConfig
137145
* @param int $nodes
146+
* @param bool $debug
138147
* @return void
139148
* @throws TestReferenceException
140149
* @throws \Exception
141150
*/
142-
public function createAllTestFiles($runConfig = null, $nodes = null)
151+
public function createAllTestFiles($runConfig = null, $nodes = null, $debug = false)
143152
{
144153
DirSetupUtil::createGroupDir($this->exportDirectory);
145154

@@ -149,7 +158,7 @@ public function createAllTestFiles($runConfig = null, $nodes = null)
149158
$this->exportDirectory,
150159
$runConfig
151160
);
152-
$testPhpArray = $this->assembleAllTestPhp($testManifest, $nodes);
161+
$testPhpArray = $this->assembleAllTestPhp($testManifest, $nodes, $debug);
153162

154163
foreach ($testPhpArray as $testPhpFile) {
155164
$this->createCestFile($testPhpFile[1], $testPhpFile[0]);
@@ -196,29 +205,52 @@ private function assembleTestPhp($testObject)
196205
*
197206
* @param BaseTestManifest $testManifest
198207
* @param int $nodes
208+
* @param bool $debug
199209
* @return array
200210
* @throws TestReferenceException
201211
* @throws \Exception
202212
*/
203-
private function assembleAllTestPhp($testManifest, $nodes)
213+
private function assembleAllTestPhp($testManifest, $nodes, $debug = false)
204214
{
205215
/** @var TestObject[] $testObjects */
206216
$testObjects = $this->loadAllTestObjects();
207217
$cestPhpArray = [];
208218

209219
foreach ($testObjects as $test) {
220+
$this->debug('Start creating test: ' . $test->getCodeceptionName(), $debug);
210221
$php = $this->assembleTestPhp($test);
211222
$cestPhpArray[] = [$test->getCodeceptionName(), $php];
212223

213224
//write to manifest here if config is not single run
214225
$testManifest->addTest($test);
226+
$debugInformation = $test->getDebugInformation();
227+
228+
$this->debug($debugInformation, $debug);
229+
$this->debug('Finish creating test ' . $test->getCodeceptionName() . PHP_EOL, $debug);
215230
}
216231

217232
$testManifest->generate($nodes);
218233

219234
return $cestPhpArray;
220235
}
221236

237+
/**
238+
* Output information in console when debug flag is enabled.
239+
*
240+
* @param array|string $messages
241+
* @param bool $debug
242+
* @return void
243+
*/
244+
private function debug($messages, $debug = false)
245+
{
246+
if ($debug && $messages) {
247+
$messages = (array) $messages;
248+
foreach ($messages as $message) {
249+
$this->consoleOutput->writeln($message);
250+
}
251+
}
252+
}
253+
222254
/**
223255
* Creates a PHP string for the necessary Allure and AcceptanceTester use statements.
224256
* Since we don't support other dependencies at this time, this function takes no parameter.

0 commit comments

Comments
 (0)