Skip to content

Commit db8712b

Browse files
committed
MQE-1884: MFTF - <after> failures override other failures
bumped up codeception version to 2.4.5 to be inline with magento version. Removed method runAfterBlock, 2.4.5 runs _after hook implicitly.
1 parent 960320a commit db8712b

File tree

3 files changed

+63
-67
lines changed

3 files changed

+63
-67
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"php": "7.0.2||7.0.4||~7.0.6||~7.1.0||~7.2.0||~7.3.0",
1313
"ext-curl": "*",
1414
"allure-framework/allure-codeception": "~1.3.0",
15-
"codeception/codeception": "~2.3.4 || ~2.4.0 ",
15+
"codeception/codeception": "~2.4.5",
1616
"composer/composer": "^1.6",
1717
"consolidation/robo": "^1.0.0",
1818
"csharpru/vault-php": "~3.5.3",

composer.lock

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

src/Magento/FunctionalTestingFramework/Extension/TestContextExtension.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
class TestContextExtension extends BaseExtension
1919
{
2020
const TEST_PHASE_AFTER = "_after";
21-
const CODECEPT_AFTER_VERSION = "2.3.9";
2221
const TEST_FAILED_FILE = 'failed';
2322

2423
/**
@@ -64,15 +63,8 @@ public function testStart()
6463
*/
6564
public function testFail(\Codeception\Event\FailEvent $e)
6665
{
67-
$cest = $e->getTest();
6866
//log suppressed exception in case of _after hook failure
6967
$this->logPreviousException($e->getFail());
70-
$context = $this->extractContext($e->getFail()->getTrace(), $cest->getTestMethod());
71-
// Do not attempt to run _after if failure was in the _after block
72-
// Try to run _after but catch exceptions to prevent them from overwriting original failure.
73-
if ($context != TestContextExtension::TEST_PHASE_AFTER) {
74-
$this->runAfterBlock($e, $cest);
75-
}
7668
}
7769

7870
/**
@@ -98,13 +90,6 @@ function () use ($cest) {
9890
if ($error->failedTest()->getTestMethod() == $cest->getName()) {
9991
//log suppressed exception in case of _after hook failure
10092
$this->logPreviousException($error->thrownException());
101-
$stack = $error->thrownException()->getTrace();
102-
$context = $this->extractContext($stack, $cest->getTestMethod());
103-
// Do not attempt to run _after if failure was in the _after block
104-
// Try to run _after but catch exceptions to prevent them from overwriting original failure.
105-
if ($context != TestContextExtension::TEST_PHASE_AFTER) {
106-
$this->runAfterBlock($e, $cest);
107-
}
10893
continue;
10994
}
11095
}
@@ -113,31 +98,6 @@ function () use ($cest) {
11398
$this->getDriver()->_runAfter($e->getTest());
11499
}
115100

116-
/**
117-
* Runs cest's after block, if necessary.
118-
* @param \Symfony\Component\EventDispatcher\Event $e
119-
* @param \Codeception\TestInterface $cest
120-
* @return void
121-
*/
122-
private function runAfterBlock($e, $cest)
123-
{
124-
try {
125-
$actorClass = $e->getTest()->getMetadata()->getCurrent('actor');
126-
$I = new $actorClass($cest->getScenario());
127-
if (version_compare(\Codeception\Codecept::VERSION, TestContextExtension::CODECEPT_AFTER_VERSION, "<=")) {
128-
call_user_func(\Closure::bind(
129-
function () use ($cest, $I) {
130-
$cest->executeHook($I, 'after');
131-
},
132-
null,
133-
$cest
134-
));
135-
}
136-
} catch (\Exception $e) {
137-
// Do not rethrow Exception
138-
}
139-
}
140-
141101
/**
142102
* Extracts hook method from trace, looking specifically for the cest class given.
143103
* @param array $trace
@@ -170,10 +130,6 @@ public function logPreviousException(\Exception $exception)
170130
}
171131
};
172132
$firstException = $change->call($exception);
173-
$bind = function () use ($firstException) {
174-
$exception = $firstException;
175-
};
176-
$bind->call($exception);
177133
if ($firstException !== null) {
178134
AllureHelper::addAttachmentToCurrentStep($firstException, 'Exception');
179135
}

0 commit comments

Comments
 (0)