Skip to content

Commit a6bc047

Browse files
authored
Merge branch 'develop' into MQE-1153
2 parents 59862c9 + df6aaf9 commit a6bc047

File tree

13 files changed

+584
-284
lines changed

13 files changed

+584
-284
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Magento Functional Testing Framework Changelog
22
================================================
33

4+
2.3.1
5+
-----
6+
### Enhancements
7+
* Maintainability
8+
* `mftf build:project` now copies over the `command.php` file into the parent Magento installation, if detected.
9+
410
2.3.0
511
-----
612
### Enhancements

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/magento2-functional-testing-framework",
33
"description": "Magento2 Functional Testing Framework",
44
"type": "library",
5-
"version": "2.3.0",
5+
"version": "2.3.1",
66
"license": "AGPL-3.0",
77
"keywords": ["magento", "automation", "functional", "testing"],
88
"config": {
@@ -11,7 +11,7 @@
1111
"require": {
1212
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0|~7.2.0",
1313
"allure-framework/allure-codeception": "~1.2.6",
14-
"codeception/codeception": "~2.3.4 || ~2.4.0",
14+
"codeception/codeception": "~2.3.4",
1515
"consolidation/robo": "^1.0.0",
1616
"epfremme/swagger-php": "^2.0",
1717
"flow/jsonpath": ">0.2",

composer.lock

Lines changed: 308 additions & 276 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
9+
use \Codeception\Util\Locator;
10+
use Yandex\Allure\Adapter\Annotation\Features;
11+
use Yandex\Allure\Adapter\Annotation\Stories;
12+
use Yandex\Allure\Adapter\Annotation\Title;
13+
use Yandex\Allure\Adapter\Annotation\Description;
14+
use Yandex\Allure\Adapter\Annotation\Parameter;
15+
use Yandex\Allure\Adapter\Annotation\Severity;
16+
use Yandex\Allure\Adapter\Model\SeverityLevel;
17+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
18+
19+
/**
20+
* @Title("ChildExtendedTestSkippedParent")
21+
* @group Child
22+
*/
23+
class ExtendingSkippedTestCest
24+
{
25+
/**
26+
* @param AcceptanceTester $I
27+
* @throws \Exception
28+
*/
29+
public function _before(AcceptanceTester $I)
30+
{
31+
$I->amOnPage("/beforeUrl");
32+
}
33+
34+
/**
35+
* @param AcceptanceTester $I
36+
* @throws \Exception
37+
*/
38+
public function _after(AcceptanceTester $I)
39+
{
40+
$I->amOnPage("/afterUrl");
41+
}
42+
43+
/**
44+
* @param AcceptanceTester $I
45+
* @throws \Exception
46+
*/
47+
public function _failed(AcceptanceTester $I)
48+
{
49+
$I->saveScreenshot();
50+
}
51+
52+
/**
53+
* @Severity(level = SeverityLevel::CRITICAL)
54+
* @Features({"TestModule"})
55+
* @Stories({"Child"})
56+
* @Parameter(name = "AcceptanceTester", value="$I")
57+
* @param AcceptanceTester $I
58+
* @return void
59+
* @throws \Exception
60+
*/
61+
public function ExtendingSkippedTest(AcceptanceTester $I)
62+
{
63+
$I->comment("text");
64+
$I->comment("child");
65+
}
66+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
9+
use \Codeception\Util\Locator;
10+
use Yandex\Allure\Adapter\Annotation\Features;
11+
use Yandex\Allure\Adapter\Annotation\Stories;
12+
use Yandex\Allure\Adapter\Annotation\Title;
13+
use Yandex\Allure\Adapter\Annotation\Description;
14+
use Yandex\Allure\Adapter\Annotation\Parameter;
15+
use Yandex\Allure\Adapter\Annotation\Severity;
16+
use Yandex\Allure\Adapter\Model\SeverityLevel;
17+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
18+
19+
/**
20+
* @Title("skippedTestWithHooks")
21+
* @Description("")
22+
*/
23+
class SkippedTestWithHooksCest
24+
{
25+
/**
26+
* @Stories({"skippedWithHooks"})
27+
* @Severity(level = SeverityLevel::MINOR)
28+
* @Features({"TestModule"})
29+
* @Parameter(name = "AcceptanceTester", value="$I")
30+
* @param AcceptanceTester $I
31+
* @return void
32+
* @throws \Exception
33+
*/
34+
public function SkippedTestWithHooks(AcceptanceTester $I, \Codeception\Scenario $scenario)
35+
{
36+
$scenario->skip("This test is skipped due to the following issues:\nSkippedValue");
37+
}
38+
}

dev/tests/verification/TestModule/Test/ExtendedFunctionalTest.xml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
<remove keyForRemoval="beforeAmOnPageKey"/>
117117
</before>
118118
</test>
119-
120119
<test name="ChildExtendedTestNoParent" extends="ThisTestDoesNotExist">
121120
<annotations>
122121
<severity value="CRITICAL"/>
@@ -129,4 +128,34 @@
129128
<remove keyForRemoval="beforeAmOnPageKey"/>
130129
</before>
131130
</test>
131+
<test name="SkippedParent">
132+
<annotations>
133+
<severity value="CRITICAL"/>
134+
<title value="PARENTSKIPPED"/>
135+
<group value="Parent"/>
136+
<features value="Parent"/>
137+
<stories value="Parent"/>
138+
<skip>
139+
<issueId value="NONE"/>
140+
</skip>
141+
</annotations>
142+
<before>
143+
<amOnPage url="/beforeUrl" stepKey="beforeAmOnPageKey"/>
144+
</before>
145+
<after>
146+
<amOnPage url="/afterUrl" stepKey="afterAmOnPageKey"/>
147+
</after>
148+
<comment userInput="text" stepKey="keepMe"/>
149+
<comment userInput="text" stepKey="replaceMe"/>
150+
</test>
151+
<test name="ExtendingSkippedTest" extends="SkippedParent">
152+
<annotations>
153+
<severity value="CRITICAL"/>
154+
<title value="ChildExtendedTestSkippedParent"/>
155+
<group value="Child"/>
156+
<features value="Child"/>
157+
<stories value="Child"/>
158+
</annotations>
159+
<comment userInput="child" stepKey="replaceMe"/>
160+
</test>
132161
</tests>

dev/tests/verification/TestModule/Test/SkippedTest.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
</skip>
2020
</annotations>
2121
</test>
22+
<test name="SkippedTestWithHooks">
23+
<annotations>
24+
<stories value="skippedWithHooks"/>
25+
<title value="skippedTestWithHooks"/>
26+
<description value=""/>
27+
<severity value="AVERAGE"/>
28+
<skip>
29+
<issueId value="SkippedValue"/>
30+
</skip>
31+
</annotations>
32+
<before>
33+
<comment userInput="skippedComment" stepKey="beforeComment"/>
34+
</before>
35+
<after>
36+
<comment userInput="skippedComment" stepKey="afterComment"/>
37+
</after>
38+
</test>
2239
<test name="SkippedTestTwoIssues">
2340
<annotations>
2441
<stories value="skippedMultiple"/>

dev/tests/verification/Tests/ExtendedGenerationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,15 @@ public function testExtendedTestGenerationNoParent()
9696
{
9797
$this->generateAndCompareTest('ChildExtendedTestNoParent');
9898
}
99+
100+
/**
101+
* Tests extending a skipped test generation.
102+
*
103+
* @throws \Exception
104+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
105+
*/
106+
public function testExtendingSkippedGeneration()
107+
{
108+
$this->generateAndCompareTest('ExtendingSkippedTest');
109+
}
99110
}

dev/tests/verification/Tests/SkippedGenerationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ public function testSkippedGeneration()
2020
$this->generateAndCompareTest('SkippedTest');
2121
}
2222

23+
/**
24+
* Tests skipped test generation does not generate hooks.
25+
*
26+
* @throws \Exception
27+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
28+
*/
29+
public function testSkippedWithHooksGeneration()
30+
{
31+
$this->generateAndCompareTest('SkippedTestWithHooks');
32+
}
33+
2334
/**
2435
* Tests skipped test with multiple issues generation.
2536
*

etc/config/command.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
if (isset($_POST['command'])) {
8+
$command = urldecode($_POST['command']);
9+
if (array_key_exists("arguments", $_POST)) {
10+
$arguments = urldecode($_POST['arguments']);
11+
} else {
12+
$arguments = null;
13+
}
14+
$php = PHP_BINARY ?: (PHP_BINDIR ? PHP_BINDIR . '/php' : 'php');
15+
$valid = validateCommand($command);
16+
if ($valid) {
17+
exec(
18+
escapeCommand($php . ' -f ../../../../bin/magento ' . $command) . " $arguments" ." 2>&1",
19+
$output,
20+
$exitCode
21+
);
22+
if ($exitCode == 0) {
23+
http_response_code(202);
24+
} else {
25+
http_response_code(500);
26+
}
27+
echo implode("\n", $output);
28+
} else {
29+
http_response_code(403);
30+
echo "Given command not found valid in Magento CLI Command list.";
31+
}
32+
} else {
33+
http_response_code(412);
34+
echo("Command parameter is not set.");
35+
}
36+
37+
/**
38+
* Returns escaped command.
39+
*
40+
* @param string $command
41+
* @return string
42+
*/
43+
function escapeCommand($command)
44+
{
45+
$escapeExceptions = [
46+
'> /dev/null &' => '--dev-null-amp--'
47+
];
48+
49+
$command = escapeshellcmd(
50+
str_replace(array_keys($escapeExceptions), array_values($escapeExceptions), $command)
51+
);
52+
53+
return str_replace(array_values($escapeExceptions), array_keys($escapeExceptions), $command);
54+
}
55+
56+
/**
57+
* Checks magento list of CLI commands for given $command. Does not check command parameters, just base command.
58+
* @param string $command
59+
* @return bool
60+
*/
61+
function validateCommand($command)
62+
{
63+
$php = PHP_BINARY ?: (PHP_BINDIR ? PHP_BINDIR . '/php' : 'php');
64+
exec($php . ' -f ../../../../bin/magento list', $commandList);
65+
// Trim list of commands after first whitespace
66+
$commandList = array_map("trimAfterWhitespace", $commandList);
67+
return in_array(trimAfterWhitespace($command), $commandList);
68+
}
69+
70+
/**
71+
* Returns given string trimmed of everything after the first found whitespace.
72+
* @param string $string
73+
* @return string
74+
*/
75+
function trimAfterWhitespace($string)
76+
{
77+
return strtok($string, ' ');
78+
}

src/Magento/FunctionalTestingFramework/Console/BuildProjectCommand.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ private function generateConfigFiles(OutputInterface $output)
154154
self::CREDENTIALS_FILE_PATH
155155
);
156156

157+
// copy command.php into magento instance
158+
if (MAGENTO_BP === FW_BP) {
159+
$output->writeln('MFTF standalone detected, command.php copy not applied.');
160+
} else {
161+
$fileSystem->copy(
162+
realpath(FW_BP . '/etc/config/command.php'),
163+
TESTS_BP . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR .'command.php'
164+
);
165+
$output->writeln('command.php copied to ' .
166+
TESTS_BP . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR .'command.php');
167+
}
168+
157169
// Remove and Create Log File
158170
$logPath = LoggingUtil::getInstance()->getLoggingPath();
159171
$fileSystem->remove($logPath);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ public function getAnnotations()
168168
*/
169169
public function getHooks()
170170
{
171-
// if this test is skipped we do not want any before/after actions to generate as the tests will not run
172-
if ($this->isSkipped()) {
173-
return [];
174-
}
175171
return $this->hooks;
176172
}
177173

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ private function assembleTestPhp($testObject)
207207

208208
$className = $testObject->getCodeceptionName();
209209
try {
210-
$hookPhp = $this->generateHooksPhp($testObject->getHooks());
210+
if (!$testObject->isSkipped()) {
211+
$hookPhp = $this->generateHooksPhp($testObject->getHooks());
212+
} else {
213+
$hookPhp = null;
214+
}
211215
$testsPhp = $this->generateTestPhp($testObject);
212216
} catch (TestReferenceException $e) {
213217
throw new TestReferenceException($e->getMessage() . "\n" . $testObject->getFilename());

0 commit comments

Comments
 (0)