Skip to content

Commit e741a1d

Browse files
authored
Merge branch 'develop' into ReleaseCandidateTest
2 parents 9082403 + 48b4b2e commit e741a1d

File tree

10 files changed

+244
-23
lines changed

10 files changed

+244
-23
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ dev/tests/mftf.log
1919
dev/tests/docs/*
2020
dev/tests/_output
2121
dev/tests/functional.suite.yml
22-
mftf-annotations-static-check.txt
22+

docs/backward-incompatible-changes.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# MFTF 3.0.0 backward incompatible changes
2+
3+
This page highlights backward incompatible changes between releases that have a major impact and require detailed explanation and special instructions to ensure third-party tests continue working with Magento core tests.
4+
5+
## Minimum supported PHP version changes
6+
7+
We changed the minimum PHP version requirement from 7.0 to 7.3. Because of the PHP version requirement change, this MFTF version only supports Magento 2.4 or later.
8+
9+
## Folder structure changes
10+
11+
We removed support to read test modules from the deprecated path `dev/tests/acceptance/tests/functional/Magento/FunctionalTest`. If there are test modules in this path, they should be moved to `dev/tests/acceptance/tests/functional/Magento`.
12+
13+
## XSD schema changes
14+
15+
- Files under test modules `ActionGroup`, `Page`, `Section`, `Test` and `Suite` only support a single entity per file.
16+
- The `file` attribute from `<module>` has been removed from the suite schema. `<module file=""/>` is no longer supported in suites.
17+
- Metadata filename format changed to ***`*Meta.xml`***.
18+
- Only nested assertion syntax will be supported. See the [assertions page](./docs/test/assertions.md) for details. Here is an example of the nested assertion syntax:
19+
```xml
20+
<assertEquals stepKey="assertAddressOrderPage">
21+
<actualResult type="const">$billingAddressOrderPage</actualResult>
22+
<expectedResult type="const">$shippingAddressOrderPage</expectedResult>
23+
</assertEquals>
24+
```
25+
26+
### Upgrading tests to the new schema
27+
28+
The following table lists the upgrade scripts that are available to upgrade tests to the new schema.
29+
30+
| Script name | Description |
31+
|-----------------------|-----------------------------------------------------------------------------------------------------------|
32+
|`splitMultipleEntitiesFiles`| Splits files that have multiple entities into multiple files with one entity per file. |
33+
|`upgradeAssertionSchema`| Updates assert actions that uses the old assertion syntax into the new nested syntax.|
34+
|`renameMetadataFiles`| Renames Metadata filenames to `*Meta.xml`.|
35+
|`removeModuleFileInSuiteFiles`| Removes occurrences of `<module file=""/>` from all `<suite>`s.|
36+
|`removeUnusedArguments`| Removes unused arguments from action groups.|
37+
|`upgradeTestSchema`| Replaces relative schema paths to URN in test files.|
38+
39+
To run the upgrade tests:
40+
41+
1. Run `bin/mftf reset --hard` to remove old generated configurations.
42+
1. Run `bin/mftf build:project` to generate new configurations.
43+
1. Run `bin/mftf upgrade:tests`. [See command page for details](./docs/commands/mftf.md#upgradetests).
44+
1. Lastly, try to generate all tests. Tests should all be generated as a result of the upgrades. If not, the most likely issue will be a changed XML schema. Check error messaging and search your codebase for the attributes listed.
45+
46+
## MFTF commands
47+
48+
`--debug` option `NONE` removed for strict schema validation. Ensure there are no schema validation errors in test modules before running MFTF commands.
49+
50+
## MFTF actions
51+
52+
### `executeInSelenium` and `performOn` removed
53+
54+
**Action**: Deprecated actions `executeInSelenium` and `performOn` are removed in favor of new action `helper`.
55+
56+
**Reason**: `executeInSelenium` and `performOn` allowed custom PHP code to be written inline inside of XML files which was difficult to maintain, troubleshoot, and modify.
57+
58+
**Details**:
59+
60+
The `helper` allows test writers to solve advanced requirements beyond what MFTF offers out of the box. See [custom-helpers](./docs/custom-helpers.md) for more information on usage.
61+
62+
Here is an example of using `helper` in place of `executeSelenium` to achieve same workflow.
63+
64+
Old usage:
65+
66+
```xml
67+
<executeInSelenium function="function ($webdriver) use ($I) {
68+
$heading = $webdriver->findElement(\Facebook\WebDriver\WebDriverBy::xpath('//div[contains(@class, \'inline-wysiwyg\')]//h2'));
69+
$actions = new \Facebook\WebDriver\Interactions\WebDriverActions($webdriver);
70+
$actions->moveToElement($heading, {{TinyMCEPartialHeadingSelection.startX}}, {{TinyMCEPartialHeadingSelection.startY}})
71+
->clickAndHold()
72+
->moveToElement($heading, {{TinyMCEPartialHeadingSelection.endX}}, {{TinyMCEPartialHeadingSelection.endY}})
73+
->release()
74+
->perform();
75+
}" stepKey="selectHeadingTextInTinyMCE"/>
76+
```
77+
78+
New usage:
79+
80+
```xml
81+
<helper class="\Magento\PageBuilder\Test\Mftf\Helper\SelectText" method="selectText" stepKey="selectHeadingTextInTinyMCE">
82+
<argument name="context">//div[contains(@class, 'inline-wysiwyg')]//h2</argument>
83+
<argument name="startX">{{TinyMCEPartialHeadingSelection.startX}}</argument>
84+
<argument name="startY">{{TinyMCEPartialHeadingSelection.startY}}</argument>
85+
<argument name="endX">{{TinyMCEPartialHeadingSelection.endX}}</argument>
86+
<argument name="endY">{{TinyMCEPartialHeadingSelection.endY}}</argument>
87+
</helper>
88+
```
89+
90+
### `pauseExecution` removed
91+
92+
**Action**: `pauseExecution` is removed in favor of `pause`.
93+
94+
**Reason**: `[WebDriver]pauseExecution` is removed in Codeception 3 in favor of `I->pause()`.
95+
96+
**Details**:
97+
98+
See the [actions page for details](./docs/test/actions.md#pause). Here is a usage example:
99+
100+
```xml
101+
<pause stepKey="pauseExecutionKey"/>
102+
```
103+
104+
### Removed assert actions
105+
106+
**Action**: Assert actions `assertInternalType`, `assertNotInternalType` and `assertArraySubset` are removed.
107+
108+
**Reason**: PHPUnit 9 has dropped support for these assertions.
109+
110+
### Updated assert actions
111+
112+
**Action**: The `delta` attribute has been removed from `assertEquals` and `assertNotEquals`. Instead, new assert actions have been introduced:
113+
114+
- `assertEqualsWithDelta`
115+
- `assertNotEqualsWithDelta`
116+
- `assertEqualsCanonicalizing`
117+
- `assertNotEqualsCanonicalizing`
118+
- `assertEqualsIgnoringCase`
119+
- `assertNotEqualsIgnoringCase`
120+
121+
**Reason**: PHPUnit 9 has dropped support for optional parameters for `assertEquals` and `assertNotEquals` and has introduced these new assertions.
122+
123+
**Details**:
124+
125+
Usage of `assertEquals` or `assertNotEquals` with a specified `delta`, should be replaced with appropriate assertion from the above list.
126+
127+
### `assertContains` supports only iterable haystacks
128+
129+
**Action**: `assertContains` and `assertNotContains` now only supports iterable haystacks. These assert actions have been added to work with string haystacks:
130+
131+
- `assertStringContainsString`
132+
- `assertStringNotContainsString`
133+
- `assertStringContainsStringIgnoringCase`
134+
- `assertStringNotContainsStringIgnoringCase`
135+
136+
**Reason**: With PHPUnit 9, `assertContains` and `assertNotContains` only allows iterable haystacks. New assertions have been introduced to support string haystacks.
137+
138+
**Details**:
139+
140+
Usages of `assertContains` and `assertNotContains` with string haystacks should be replaced with appropriate assertion from the above list.
141+
142+
Usage example for string haystacks:
143+
144+
```xml
145+
<assertStringContainsString stepKey="assertDiscountOnPrice2">
146+
<actualResult type="const">$grabSimpleProdPrice2</actualResult>
147+
<expectedResult type="string">$110.70</expectedResult>
148+
</assertStringContainsString>
149+
```
150+
151+
### `formatMoney` removed
152+
153+
**Action**: `formatMoney` has been removed in favor of `formatCurrency`.
154+
155+
**Reason**: PHP 7.4 has deprecated use of `formatMoney`.
156+
157+
**Details**: Format input to specified currency according to the locale specified.
158+
159+
Usage example:
160+
161+
```xml
162+
<formatCurrency userInput="1234.56789000" locale="de_DE" currency="USD" stepKey="usdInDE"/>
163+
```

docs/commands/mftf.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,15 @@ The example parameters are taken from the `etc/config/.env.example` file.
430430

431431
### `static-checks`
432432

433-
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
433+
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
434434
Behavior for determining what tests to run is as follows:
435435

436436
* If test names are specified, only those tests are run.
437437
* If no test names are specified, tests are run according to `staticRuleset.json`.
438438
* If no `staticRuleset.json` is found, all tests are run.
439439

440+
Static checks errors are written to *.txt files under TEST_BP/tests/_output/static-results/
441+
440442
#### Usage
441443

442444
```bash

src/Magento/FunctionalTestingFramework/StaticCheck/ActionGroupArgumentsCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function execute(InputInterface $input)
6565

6666
$this->output = $this->scriptUtil->printErrorsToFile(
6767
$this->errors,
68-
self::ERROR_LOG_FILENAME,
68+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
6969
self::ERROR_LOG_MESSAGE
7070
);
7171
}

src/Magento/FunctionalTestingFramework/StaticCheck/AnnotationsCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function execute(InputInterface $input)
8585
$scriptUtil = new ScriptUtil();
8686
$this->output = $scriptUtil->printErrorsToFile(
8787
$this->errors,
88-
self::ERROR_LOG_FILENAME,
88+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
8989
self::ERROR_LOG_MESSAGE
9090
);
9191
}

src/Magento/FunctionalTestingFramework/StaticCheck/DeprecatedEntityUsageCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function execute(InputInterface $input)
128128
// Hold on to the output and print any errors to a file
129129
$this->output = $this->scriptUtil->printErrorsToFile(
130130
$this->errors,
131-
self::ERROR_LOG_FILENAME,
131+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
132132
self::ERROR_LOG_MESSAGE
133133
);
134134
}

src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
namespace Magento\FunctionalTestingFramework\StaticCheck;
99

10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
12+
1013
/**
1114
* Class StaticChecksList has a list of static checks to run on test xml
1215
* @codingStandardsIgnoreFile
1316
*/
1417
class StaticChecksList implements StaticCheckListInterface
1518
{
1619
const DEPRECATED_ENTITY_USAGE_CHECK_NAME = 'deprecatedEntityUsage';
20+
const STATIC_RESULTS = 'tests' . DIRECTORY_SEPARATOR .'_output' . DIRECTORY_SEPARATOR . 'static-results';
1721

1822
/**
1923
* Property contains all static check scripts.
@@ -22,10 +26,18 @@ class StaticChecksList implements StaticCheckListInterface
2226
*/
2327
private $checks;
2428

29+
/**
30+
* Directory path for static checks error files
31+
*
32+
* @var string
33+
*/
34+
private static $errorFilesPath = null;
35+
2536
/**
2637
* Constructor
2738
*
2839
* @param array $checks
40+
* @throws TestFrameworkException
2941
*/
3042
public function __construct(array $checks = [])
3143
{
@@ -35,6 +47,11 @@ public function __construct(array $checks = [])
3547
self::DEPRECATED_ENTITY_USAGE_CHECK_NAME => new DeprecatedEntityUsageCheck(),
3648
'annotations' => new AnnotationsCheck()
3749
] + $checks;
50+
51+
// Static checks error files directory
52+
if (null === self::$errorFilesPath) {
53+
self::$errorFilesPath = FilePathFormatter::format(TESTS_BP) . self::STATIC_RESULTS;
54+
}
3855
}
3956

4057
/**
@@ -44,4 +61,12 @@ public function getStaticChecks()
4461
{
4562
return $this->checks;
4663
}
64+
65+
/**
66+
* Return the directory path for the static check error files
67+
*/
68+
public static function getErrorFilesPath()
69+
{
70+
return self::$errorFilesPath;
71+
}
4772
}

src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function execute(InputInterface $input)
121121
// hold on to the output and print any errors to a file
122122
$this->output = $this->scriptUtil->printErrorsToFile(
123123
$this->errors,
124-
self::ERROR_LOG_FILENAME,
124+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
125125
self::ERROR_LOG_MESSAGE
126126
);
127127
}

src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,53 @@
77
namespace Magento\FunctionalTestingFramework\Util\Logger;
88

99
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
10-
use Monolog\Handler\StreamHandler;
10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
use Monolog\Handler\HandlerInterface;
1112
use Monolog\Logger;
1213

1314
class MftfLogger extends Logger
1415
{
16+
/**
17+
* MFTF execution phase
18+
*
19+
* @var string
20+
*/
21+
private $phase;
22+
23+
/**
24+
* MftfLogger constructor.
25+
*
26+
* @param string $name
27+
* @param HandlerInterface[] $handlers
28+
* @param callable[] $processors
29+
* @throws TestFrameworkException
30+
*/
31+
public function __construct($name, array $handlers = [], array $processors = [])
32+
{
33+
parent::__construct($name, $handlers, $processors);
34+
$this->phase = MftfApplicationConfig::getConfig()->getPhase();
35+
}
36+
1537
/**
1638
* Prints a deprecation warning, as well as adds a log at the WARNING level.
39+
* Suppresses logging during execution phase.
1740
*
1841
* @param string $message The log message.
1942
* @param array $context The log context.
2043
* @param boolean $verbose
2144
* @return void
22-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
2345
*/
2446
public function deprecation($message, array $context = [], $verbose = false)
2547
{
2648
$message = "DEPRECATION: " . $message;
27-
// Suppress print during unit testing
28-
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
49+
// print during test generation
50+
if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) {
2951
print ($message . json_encode($context) . "\n");
3052
}
31-
parent::warning($message, $context);
53+
// suppress logging during test execution
54+
if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) {
55+
parent::warning($message, $context);
56+
}
3257
}
3358

3459
/**
@@ -38,34 +63,36 @@ public function deprecation($message, array $context = [], $verbose = false)
3863
* @param array $context The log context.
3964
* @param boolean $verbose
4065
* @return void
41-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
4266
*/
4367
public function criticalFailure($message, array $context = [], $verbose = false)
4468
{
4569
$message = "FAILURE: " . $message;
4670
// Suppress print during unit testing
47-
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
71+
if ($this->phase !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
4872
print ($message . implode("\n", $context) . "\n");
4973
}
5074
parent::critical($message, $context);
5175
}
5276

5377
/**
5478
* Adds a log record at the NOTICE level.
79+
* Suppresses logging during execution phase.
5580
*
5681
* @param string $message
5782
* @param array $context
5883
* @param boolean $verbose
5984
* @return void
60-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
6185
*/
6286
public function notification($message, array $context = [], $verbose = false)
6387
{
6488
$message = "NOTICE: " . $message;
65-
// Suppress print during unit testing
66-
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
67-
print ($message . implode("\n", $context) . "\n");
89+
// print during test generation
90+
if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) {
91+
print ($message . json_encode($context) . "\n");
92+
}
93+
// suppress logging during test execution
94+
if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) {
95+
parent::notice($message, $context);
6896
}
69-
parent::notice($message, $context);
7097
}
7198
}

0 commit comments

Comments
 (0)