Skip to content

Commit dcb7b91

Browse files
committed
MQE-975: Bump MFTF version in Magento and deliver all related changes to new version
- remove explicity exit code in function - fix _bootstrap file - catch up with current robofile - repoint to new MFTF version
1 parent ee611e6 commit dcb7b91

File tree

6 files changed

+260
-55
lines changed

6 files changed

+260
-55
lines changed

dev/tests/acceptance/RoboFile.php

Lines changed: 157 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
use Symfony\Component\Yaml\Yaml;
8+
79
/** This is project's console commands configuration for Robo task runner.
810
*
911
* @codingStandardsIgnoreStart
@@ -13,6 +15,12 @@ class RoboFile extends \Robo\Tasks
1315
{
1416
use Robo\Task\Base\loadShortcuts;
1517

18+
public function __construct()
19+
{
20+
require 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php';
21+
define('VENDOR_BIN_PATH', PROJECT_ROOT . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR);
22+
23+
}
1624
/**
1725
* Duplicate the Example configuration files used to customize the Project for customization.
1826
*
@@ -25,6 +33,66 @@ function cloneFiles()
2533
$this->_exec('cp -vf tests'. DIRECTORY_SEPARATOR .'functional.suite.dist.yml tests'. DIRECTORY_SEPARATOR .'functional.suite.yml');
2634
}
2735

36+
/**
37+
* Finds relative paths between codeception.yml file and MFTF path, and overwrites the default paths.
38+
*
39+
* @return void
40+
*/
41+
private function buildCodeceptionPaths()
42+
{
43+
$relativePathFunc = function ($from, $to)
44+
{
45+
$from = is_dir($from) ? rtrim($from, '\/') . '/' : $from;
46+
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
47+
$from = str_replace('\\', '/', $from);
48+
$to = str_replace('\\', '/', $to);
49+
50+
$from = explode('/', $from);
51+
$to = explode('/', $to);
52+
$relPath = $to;
53+
54+
foreach($from as $depth => $dir) {
55+
// find first non-matching dir
56+
if($dir === $to[$depth]) {
57+
// ignore this directory
58+
array_shift($relPath);
59+
} else {
60+
// get number of remaining dirs to $from
61+
$remaining = count($from) - $depth;
62+
if($remaining > 1) {
63+
// add traversals up to first matching dir
64+
$padLength = (count($relPath) + $remaining - 1) * -1;
65+
$relPath = array_pad($relPath, $padLength, '..');
66+
break;
67+
} else {
68+
$relPath[0] = './' . $relPath[0];
69+
}
70+
}
71+
}
72+
return implode('/', $relPath);
73+
};
74+
75+
//Find travel path from codeception.yml to FW_BP
76+
$configYmlPath = dirname(dirname(TESTS_BP)) . DIRECTORY_SEPARATOR;
77+
$relativePath = call_user_func($relativePathFunc, $configYmlPath, FW_BP);
78+
$configYmlFile = $configYmlPath . "codeception.yml";
79+
$defaultConfigYmlFile = $configYmlPath . "codeception.dist.yml";
80+
81+
if (file_exists($configYmlFile)) {
82+
$ymlContents = file_get_contents($configYmlFile);
83+
} else {
84+
$ymlContents = file_get_contents($defaultConfigYmlFile);
85+
}
86+
$ymlArray = Yaml::parse($ymlContents) ?? [];
87+
if (!array_key_exists("paths", $ymlArray)) {
88+
$ymlArray["paths"] = [];
89+
}
90+
$ymlArray["paths"]["support"] = $relativePath . 'src/Magento/FunctionalTestingFramework';
91+
$ymlArray["paths"]["envs"] = $relativePath . 'etc/_envs';
92+
$ymlText = Yaml::dump($ymlArray, 10);
93+
file_put_contents($configYmlFile, $ymlText);
94+
}
95+
2896
/**
2997
* Duplicate the Example configuration files for the Project.
3098
* Build the Codeception project.
@@ -34,7 +102,8 @@ function cloneFiles()
34102
function buildProject()
35103
{
36104
$this->cloneFiles();
37-
$this->_exec('vendor'. DIRECTORY_SEPARATOR .'bin'. DIRECTORY_SEPARATOR .'codecept build');
105+
$this->buildCodeceptionPaths();
106+
$this->_exec(VENDOR_BIN_PATH .'codecept build');
38107
}
39108

40109
/**
@@ -44,27 +113,97 @@ function buildProject()
44113
* @param array $opts
45114
* @return void
46115
*/
116+
function generateTests(array $tests, $opts = [
117+
'config' => null,
118+
'force' => false,
119+
'nodes' => null,
120+
'lines' => 500,
121+
'tests' => null
122+
])
123+
{
124+
require 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php';
125+
$testConfiguration = $this->createTestConfiguration($tests, $opts);
126+
127+
// maintain backwards compatability for devops by not removing the nodes option yet
128+
$lines = $opts['lines'];
47129

48-
function generateTests(array $tests, $opts = ['config' => null, 'force' => false, 'nodes' => null])
130+
// create our manifest file here
131+
$testManifest = \Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory::makeManifest($opts['config'],$testConfiguration['suites']);
132+
\Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance(null, $testConfiguration['tests'])->createAllTestFiles($testManifest);
133+
134+
if ($opts['config'] == 'parallel') {
135+
$testManifest->createTestGroups($lines);
136+
}
49137

138+
\Magento\FunctionalTestingFramework\Suite\SuiteGenerator::getInstance()->generateAllSuites($testManifest);
139+
$testManifest->generate();
140+
141+
$this->say("Generate Tests Command Run");
142+
}
143+
144+
145+
/**
146+
* Function which builds up a configuration including test and suites for consumption of Magento generation methods.
147+
*
148+
* @param array $tests
149+
* @param array $opts
150+
* @return array
151+
*/
152+
private function createTestConfiguration($tests, $opts)
50153
{
51-
$GLOBALS['GENERATE_TESTS'] = true;
52-
require 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php';
53-
$testsObjects = [];
54-
if (!empty($tests))
154+
// set our application configuration so we can references the user options in our framework
155+
Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::create(
156+
$opts['force'],
157+
Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::GENERATION_PHASE,
158+
$opts['verbose']
159+
);
160+
161+
$testConfiguration = [];
162+
$testConfiguration['tests'] = $tests;
163+
$testConfiguration['suites'] = [];
164+
165+
$testConfiguration = $this->parseTestsConfigJson($opts['tests'], $testConfiguration);
166+
167+
// if we have references to specific tests, we resolve the test objects and pass them to the config
168+
if (!empty($testConfiguration['tests']))
55169
{
56-
foreach ($tests as $test)
170+
$testObjects = [];
171+
172+
foreach ($testConfiguration['tests'] as $test)
57173
{
58-
$testsObjects[] = Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler::getInstance()->getObject($test);
174+
$testObjects[$test] = Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler::getInstance()->getObject($test);
59175
}
176+
177+
$testConfiguration['tests'] = $testObjects;
60178
}
61-
if ($opts['force'])
62-
{
63-
$GLOBALS['FORCE_PHP_GENERATE'] = true;
179+
180+
return $testConfiguration;
181+
}
182+
183+
/**
184+
* Function which takes a json string of potential custom configuration and parses/validates the resulting json
185+
* passed in by the user. The result is a testConfiguration array.
186+
*
187+
* @param string $json
188+
* @param array $testConfiguration
189+
* @return array
190+
*/
191+
private function parseTestsConfigJson($json, $testConfiguration) {
192+
if ($json == null) {
193+
return $testConfiguration;
64194
}
65195

66-
\Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance(null, $testsObjects)->createAllTestFiles($opts['config'], $opts['nodes']);
67-
$this->say("Generate Tests Command Run");
196+
$jsonTestConfiguration = [];
197+
$testConfigArray = json_decode($json, true);
198+
199+
// stop execution if we have failed to properly parse any json
200+
if (json_last_error() != JSON_ERROR_NONE) {
201+
throw new \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException("JSON could not be parsed: " . json_last_error_msg());
202+
}
203+
204+
$jsonTestConfiguration['tests'] = $testConfigArray['tests'] ?? null;;
205+
$jsonTestConfiguration['suites'] = $testConfigArray['suites'] ?? null;
206+
return $jsonTestConfiguration;
68207
}
69208

70209
/**
@@ -80,7 +219,6 @@ function generateSuite(array $args)
80219
throw new Exception("Please provide suite name(s) after generate:suite command");
81220
}
82221

83-
require 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php';
84222
$sg = \Magento\FunctionalTestingFramework\Suite\SuiteGenerator::getInstance();
85223

86224
foreach ($args as $arg) {
@@ -95,18 +233,18 @@ function generateSuite(array $args)
95233
*/
96234
function functional()
97235
{
98-
$this->_exec('.' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'codecept run functional --skip-group skip');
236+
$this->_exec(VENDOR_BIN_PATH . 'codecept run functional');
99237
}
100238

101239
/**
102-
* Run all Tests with the specified @group tag, excluding @group 'skip'.
240+
* Run all Tests with the specified @group tag'.
103241
*
104242
* @param string $args
105243
* @return void
106244
*/
107245
function group($args = '')
108246
{
109-
$this->taskExec('.' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'codecept run functional --verbose --steps --skip-group skip --group')->args($args)->run();
247+
$this->taskExec(VENDOR_BIN_PATH . 'codecept run functional --verbose --steps --group')->args($args)->run();
110248
}
111249

112250
/**
@@ -117,7 +255,7 @@ function group($args = '')
117255
*/
118256
function folder($args = '')
119257
{
120-
$this->taskExec('.' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'codecept run functional')->args($args)->run();
258+
$this->taskExec(VENDOR_BIN_PATH . 'codecept run functional')->args($args)->run();
121259
}
122260

123261
/**
@@ -127,7 +265,7 @@ function folder($args = '')
127265
*/
128266
function example()
129267
{
130-
$this->_exec('.' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'codecept run --group example --skip-group skip');
268+
$this->_exec(VENDOR_BIN_PATH . 'codecept run --group example');
131269
}
132270

133271
/**
@@ -207,6 +345,4 @@ function preInstall()
207345
{
208346
$this->_exec('php pre-install.php');
209347
}
210-
211-
212348
}

dev/tests/acceptance/composer.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717
}
1818
],
1919
"require": {
20-
"allure-framework/allure-codeception": "~1.2.6",
21-
"codeception/codeception": "~2.3.4",
22-
"consolidation/robo": "^1.0.0",
23-
"symfony/process": ">=2.7 <3.4",
24-
"henrikbjorn/lurker": "^1.2",
25-
"magento/magento2-functional-testing-framework": "~2.1.1",
26-
"php": "~7.0.13|~7.1.0",
27-
"vlucas/phpdotenv": "~2.4"
20+
"magento/magento2-functional-testing-framework": "~2.2.0",
21+
"php": "~7.0.13|~7.1.0"
2822
},
2923
"replace": {
3024
"magento/magento2-functional-test-module-marketplace": "100.0.0-dev",

dev/tests/acceptance/composer.lock

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)