Skip to content

Commit b525101

Browse files
authored
Merge branch 'develop' into 3.0.0-RC2
2 parents 1225f25 + 254551d commit b525101

File tree

2 files changed

+86
-39
lines changed

2 files changed

+86
-39
lines changed

docs/test.md

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Test
22

33
Test cases in the Magento Functional Testing Framework (MFTF) are defined in XML as [`<tests>`].
4-
`<tests>` is a [Codeception test container][Codeception] that contains multiple individual tests with test metadata and before and after actions.
4+
`<tests>` is a [Codeception test container][Codeception] that contains individual test [`<test>`] with its metadata ([`<annotations>`]), before ([`<before>`]) and after ([`<after>`]) section.
55

6-
MFTF `<tests>` is considered a sequence of actions with associated parameters.
6+
MFTF `<test>` is considered a sequence of actions with associated parameters.
77
Any failed [assertion] within a test constitutes a failed test.
88

99
<div class="bs-callout bs-callout-info" markdown="1">
@@ -18,7 +18,7 @@ The following diagram shows the structure of an MFTF test case:
1818

1919
## Format
2020

21-
The format of `<tests>` is:
21+
The format of a test XML file is:
2222

2323
```xml
2424
<?xml version="1.0" encoding="UTF-8"?>
@@ -44,26 +44,23 @@ The format of `<tests>` is:
4444

4545
The following conventions apply to MFTF tests:
4646

47-
* All names within the framework are in the CamelCase format.
48-
* `<test>` name must be alphanumeric.
49-
* Each action and action group has its own identifier `<stepKey>` for reference purposes.
50-
* A test may have any number of [assertions][assertion] at any point within the `<test>`.
51-
* If `<test>` is included in `<suite>`, it **cannot be generated in isolation** to the rest of the contents of the suite (see [suites] for details).
5247
* One `<test>` tag is allowed per test XML file.
48+
* All names within the framework are in the **PascalCase** format and must be alphanumeric.
49+
* Each action and action group call should have its own identifier `<stepKey>`.
50+
* A test may have any number of [assertions][assertion] at any point within the `<test>`.
51+
* If `<test>` is included in [`<suite>`][suites], it **cannot be generated in isolation** from `<before>` and `<after>` section of the suite (see [suites] for details).
5352

5453
## Elements reference
5554

56-
There are several XML elements that are used in `<tests>` in the MFTF.
55+
There are several XML elements that are used within `<test>` in the MFTF.
5756

5857
### tests {#tests-tag}
5958

60-
`<tests>` is a container for multiple tests. It is a group of test methods that define test flows within a test case.
61-
62-
`<tests>` must contain at least one [`<test>`].
59+
`<tests>` is a container for test and must contain exactly one [`<test>`].
6360

6461
### test {#test-tag}
6562

66-
`<test>` is a set of steps, including [actions] and [assertions][assertion]. It is a sequence of test steps that define test flow within a test method.
63+
`<test>` is a set of steps, including [actions], [assertions][assertion] and Action Group calls. It is a sequence of test steps that define test flow within a test method.
6764

6865
Attribute|Type|Use|Description
6966
---|---|---|---
@@ -85,21 +82,20 @@ Allure annotations provide metadata for reporting.
8582

8683
### before {#before-tag}
8784

88-
`<before>` wraps the steps to perform before the [`<test>`].
85+
`<before>` wraps the steps that are preconditions for the [`<test>`]. For example: Change configuration, create Customer Account, Create Category and Product.
8986

9087
`<before>` may contain these child elements:
9188

92-
* Any [`<action>`][actions]
93-
* [`<actionGroup>`]
89+
* Any [Action][actions]
90+
* [`<actionGroup>`]s
9491

9592
### after {#after-tag}
9693

97-
`<after>` wraps the steps to perform after the [`<test>`].
98-
The steps are run in both successful **and** failed test runs.
94+
`<after>` wraps the steps to perform after the [`<test>`]. The steps are run in both successful **and** failed test runs. The goal of this section is to perform cleanup (revert the environment to the pre-test state).
9995

10096
`<after>` may contain:
10197

102-
* Any [`<action>`][actions]
98+
* Any [Action][actions]
10399
* [`<actionGroup>`]
104100

105101
### actionGroup {#actiongroup-tag}

src/Magento/FunctionalTestingFramework/Console/GenerateDevUrnCommand.php

+71-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7-
declare(strict_types = 1);
7+
declare(strict_types=1);
88

99
namespace Magento\FunctionalTestingFramework\Console;
1010

@@ -19,6 +19,14 @@
1919

2020
class GenerateDevUrnCommand extends Command
2121
{
22+
/**
23+
* Argument for the path to IDE config file
24+
*/
25+
const IDE_FILE_PATH_ARGUMENT = 'path';
26+
27+
const PROJECT_PATH_IDENTIFIER = '$PROJECT_DIR$';
28+
const MFTF_SRC_PATH = 'src/Magento/FunctionalTestingFramework/';
29+
2230
/**
2331
* Configures the current command.
2432
*
@@ -27,8 +35,12 @@ class GenerateDevUrnCommand extends Command
2735
protected function configure()
2836
{
2937
$this->setName('generate:urn-catalog')
30-
->setDescription('This command generates an URN catalog to enable PHPStorm to recognize and highlight URNs.')
31-
->addArgument('path', InputArgument::REQUIRED, 'path to PHPStorm misc.xml file (typically located in [ProjectRoot]/.idea/misc.xml)')
38+
->setDescription('Generates the catalog of URNs to *.xsd mappings for the IDE to highlight xml.')
39+
->addArgument(
40+
self::IDE_FILE_PATH_ARGUMENT,
41+
InputArgument::REQUIRED,
42+
'Path to file to output the catalog. For PhpStorm use .idea/misc.xml'
43+
)
3244
->addOption(
3345
"force",
3446
'f',
@@ -47,7 +59,7 @@ protected function configure()
4759
*/
4860
protected function execute(InputInterface $input, OutputInterface $output)
4961
{
50-
$miscXmlFilePath = $input->getArgument('path') . DIRECTORY_SEPARATOR . "misc.xml";
62+
$miscXmlFilePath = $input->getArgument(self::IDE_FILE_PATH_ARGUMENT);
5163
$miscXmlFile = realpath($miscXmlFilePath);
5264
$force = $input->getOption('force');
5365

@@ -71,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7183

7284
//Locate ProjectResources node, create one if none are found.
7385
$nodeForWork = null;
74-
foreach($dom->getElementsByTagName('component') as $child) {
86+
foreach ($dom->getElementsByTagName('component') as $child) {
7587
if ($child->getAttribute('name') === 'ProjectResources') {
7688
$nodeForWork = $child;
7789
}
@@ -109,35 +121,74 @@ protected function execute(InputInterface $input, OutputInterface $output)
109121

110122
/**
111123
* Generates urn => location array for all MFTF schema.
124+
*
112125
* @return array
113-
* @throws TestFrameworkException
114126
*/
115127
private function generateResourcesArray()
116128
{
117129
$resourcesArray = [
118130
'urn:magento:mftf:DataGenerator/etc/dataOperation.xsd' =>
119-
realpath(FilePathFormatter::format(FW_BP)
120-
. 'src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd'),
131+
$this->getResourcePath('DataGenerator/etc/dataOperation.xsd'),
121132
'urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd' =>
122-
realpath(FilePathFormatter::format(FW_BP)
123-
. 'src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd'),
133+
$this->getResourcePath('DataGenerator/etc/dataProfileSchema.xsd'),
124134
'urn:magento:mftf:Page/etc/PageObject.xsd' =>
125-
realpath(FilePathFormatter::format(FW_BP)
126-
. 'src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd'),
135+
$this->getResourcePath('Page/etc/PageObject.xsd'),
127136
'urn:magento:mftf:Page/etc/SectionObject.xsd' =>
128-
realpath(FilePathFormatter::format(FW_BP)
129-
. 'src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd'),
137+
$this->getResourcePath('Page/etc/SectionObject.xsd'),
130138
'urn:magento:mftf:Test/etc/actionGroupSchema.xsd' =>
131-
realpath(FilePathFormatter::format(FW_BP)
132-
. 'src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd'),
139+
$this->getResourcePath('Test/etc/actionGroupSchema.xsd'),
133140
'urn:magento:mftf:Test/etc/testSchema.xsd' =>
134-
realpath(FilePathFormatter::format(FW_BP)
135-
. 'src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd'),
141+
$this->getResourcePath('Test/etc/testSchema.xsd'),
136142
'urn:magento:mftf:Suite/etc/suiteSchema.xsd' =>
137-
realpath(FilePathFormatter::format(FW_BP)
138-
. 'src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd')
143+
$this->getResourcePath('Suite/etc/suiteSchema.xsd')
139144
];
140145
return $resourcesArray;
141146
}
142147

148+
/**
149+
* Returns path (full or PhpStorm project-based) to XSD file
150+
*
151+
* @param $relativePath
152+
* @return string
153+
* @throws TestFrameworkException
154+
*/
155+
private function getResourcePath($relativePath)
156+
{
157+
$urnPath = realpath(FilePathFormatter::format(FW_BP) . self::MFTF_SRC_PATH . $relativePath);
158+
$projectRoot = $this->getProjectRootPath();
159+
160+
if ($projectRoot !== null) {
161+
return str_replace($projectRoot, self::PROJECT_PATH_IDENTIFIER, $urnPath);
162+
}
163+
164+
return $urnPath;
165+
}
166+
167+
/**
168+
* Returns Project root directory absolute path
169+
* @TODO Find out how to detect other types of installation
170+
*
171+
* @return string|null
172+
*/
173+
private function getProjectRootPath()
174+
{
175+
$frameworkRoot = realpath(__DIR__);
176+
177+
if ($this->isInstalledByComposer($frameworkRoot)) {
178+
return strstr($frameworkRoot, '/vendor/', true);
179+
}
180+
181+
return null;
182+
}
183+
184+
/**
185+
* Determines whether MFTF was installed using Composer
186+
*
187+
* @param string $frameworkRoot
188+
* @return bool
189+
*/
190+
private function isInstalledByComposer($frameworkRoot)
191+
{
192+
return false !== strpos($frameworkRoot, '/vendor/');
193+
}
143194
}

0 commit comments

Comments
 (0)