Skip to content

Commit 890b392

Browse files
authored
MQE-1110: MFTF run:group does not work with a standalone configuration
- added require_once of proper bootstrap for codeception execution.
1 parent e68c41d commit 890b392

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

dev/tests/functional/_bootstrap.php

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

7+
//Do not continue running this bootstrap if PHPUnit is calling it
8+
$fullTrace = debug_backtrace();
9+
$rootFile = array_values(array_slice($fullTrace, -1))[0]['file'];
10+
if (strpos($rootFile, "phpunit") !== false) {
11+
return;
12+
}
13+
714
defined('PROJECT_ROOT') || define('PROJECT_ROOT', dirname(dirname(dirname(__DIR__))));
815
require_once realpath(PROJECT_ROOT . '/vendor/autoload.php');
916

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ protected function configure()
3131
'name',
3232
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
3333
"name of tests to generate and execute"
34-
)->addOption('skip-generate', 'k', InputOption::VALUE_NONE, "skip generation and execute existing test");
34+
)->addOption('skip-generate', 'k', InputOption::VALUE_NONE, "skip generation and execute existing test")
35+
->addOption(
36+
"force",
37+
'f',
38+
InputOption::VALUE_NONE,
39+
'force generation of tests regardless of Magento Instance Configuration'
40+
);
3541
}
3642

3743
/**
@@ -47,17 +53,18 @@ protected function configure()
4753
protected function execute(InputInterface $input, OutputInterface $output)
4854
{
4955
$tests = $input->getArgument('name');
50-
$skipGeneration = $input->getOption('skip-generate') ?? false;
56+
$skipGeneration = $input->getOption('skip-generate');
57+
$force = $input->getOption('force');
5158

5259
if (!$skipGeneration) {
5360
$command = $this->getApplication()->find('generate:tests');
5461
$args = [
5562
'--tests' => json_encode([
5663
'tests' => $tests,
5764
'suites' => null
58-
])
65+
]),
66+
'--force' => $force
5967
];
60-
6168
$command->run(new ArrayInput($args), $output);
6269
}
6370

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\FunctionalTestingFramework\Console;
99

1010
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
11+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
1112
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\ArrayInput;
@@ -33,6 +34,11 @@ protected function configure()
3334
'k',
3435
InputOption::VALUE_NONE,
3536
"only execute a group of tests without generating from source xml"
37+
)->addOption(
38+
"force",
39+
'f',
40+
InputOption::VALUE_NONE,
41+
'force generation of tests regardless of Magento Instance Configuration'
3642
)->addArgument(
3743
'groups',
3844
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
@@ -52,13 +58,25 @@ protected function configure()
5258
*/
5359
protected function execute(InputInterface $input, OutputInterface $output)
5460
{
55-
$skipGeneration = $input->getOption('skip-generate') ?? false;
61+
$skipGeneration = $input->getOption('skip-generate');
62+
$force = $input->getOption('force');
5663
$groups = $input->getArgument('groups');
5764

65+
// Create Mftf Configuration
66+
MftfApplicationConfig::create(
67+
$force,
68+
MftfApplicationConfig::GENERATION_PHASE,
69+
false,
70+
false
71+
);
72+
5873
if (!$skipGeneration) {
5974
$testConfiguration = $this->getGroupAndSuiteConfiguration($groups);
6075
$command = $this->getApplication()->find('generate:tests');
61-
$args = ['--tests' => $testConfiguration];
76+
$args = [
77+
'--tests' => $testConfiguration,
78+
'--force' => $force
79+
];
6280

6381
$command->run(new ArrayInput($args), $output);
6482
}

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
1010
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1111
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
12+
use Symfony\Component\HttpFoundation\Response;
1213

1314
/**
1415
* Class ModuleResolver, resolve module path based on enabled modules of target Magento instance.
@@ -402,11 +403,19 @@ protected function getAdminToken()
402403
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
403404

404405
$response = curl_exec($ch);
406+
$responseCode = curl_getinfo($ch)['http_code'];
405407

406-
if (!$response) {
407-
$message = "Could not retrieve API token from Magento Instance.";
408+
if ($responseCode !== 200) {
409+
if ($responseCode == 0) {
410+
$details = "Could not find Magento Instance at given MAGENTO_BASE_URL";
411+
} else {
412+
$details = $responseCode . " " . Response::$statusTexts[$responseCode];
413+
}
414+
415+
$message = "Could not retrieve API token from Magento Instance ({$details})";
408416
$context = [
409-
"Admin Integration Token Url" => $url,
417+
"tokenUrl" => $url,
418+
"responseCode" => $responseCode,
410419
"MAGENTO_ADMIN_USERNAME" => getenv("MAGENTO_ADMIN_USERNAME"),
411420
"MAGENTO_ADMIN_PASSWORD" => getenv("MAGENTO_ADMIN_PASSWORD"),
412421
];

src/Magento/FunctionalTestingFramework/_bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
$projectRootPath = substr(FW_BP, 0, strpos(FW_BP, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR));
1313

1414
if (empty($projectRootPath)) {
15-
// Currently we do not support global execution, so leave this script before pathing is set improperly
15+
// If ProjectRootPath is empty, we are not under vendor and are executing standalone.
16+
require_once (realpath(FW_BP . "/dev/tests/functional/_bootstrap.php"));
1617
return;
1718
}
1819

0 commit comments

Comments
 (0)