Skip to content

Commit 3e8ee44

Browse files
authored
Merge pull request #396 from magento/MQE-1672
MQE-1672: AllureAdapter does not output BROKEN test steps
2 parents 5c7bea5 + 1b60a53 commit 3e8ee44

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
1010
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
1111
use \Magento\FunctionalTestingFramework\Util\TestGenerator;
12+
use Yandex\Allure\Adapter\Model\Status;
1213
use Yandex\Allure\Adapter\Model\Step;
1314
use Yandex\Allure\Codeception\AllureCodeception;
1415
use Yandex\Allure\Adapter\Event\StepStartedEvent;
1516
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
1617
use Yandex\Allure\Adapter\Event\StepFailedEvent;
1718
use Yandex\Allure\Adapter\Event\TestCaseFailedEvent;
1819
use Yandex\Allure\Adapter\Event\TestCaseFinishedEvent;
20+
use Yandex\Allure\Adapter\Event\TestCaseBrokenEvent;
1921
use Codeception\Event\FailEvent;
2022
use Codeception\Event\SuiteEvent;
2123
use Codeception\Event\StepEvent;
@@ -187,10 +189,37 @@ public function testIncomplete(FailEvent $failEvent)
187189
$this->getLifecycle()->fire($event->withException($e)->withMessage($message));
188190
}
189191

192+
/**
193+
* Override of parent method. Adds in steps for hard PHP Errors if they arrise.
194+
*
195+
* @param FailEvent $failEvent
196+
* @return void
197+
*/
198+
public function testError(FailEvent $failEvent)
199+
{
200+
$event = new TestCaseBrokenEvent();
201+
$e = $failEvent->getFail();
202+
$message = $e->getMessage();
203+
204+
// Create new step with an error for Allure
205+
$failStep = new Step();
206+
$failStep->setName("ERROR");
207+
$failStep->setTitle($message);
208+
$failStep->setStatus(Status::BROKEN);
209+
210+
// Retrieve Allure Steps and add in the new BROKEN step
211+
$rootStep = $this->getLifecycle()->getStepStorage()->pollLast();
212+
$rootStep->addStep($failStep);
213+
$this->getLifecycle()->getStepStorage()->put($rootStep);
214+
215+
$this->getLifecycle()->fire($event->withException($e)->withMessage($message));
216+
}
217+
190218
/**
191219
* Override of parent method, polls stepStorage for testcase and formats it according to actionGroup nesting.
192220
*
193221
* @return void
222+
* @SuppressWarnings(PHPMD)
194223
*/
195224
public function testEnd()
196225
{
@@ -207,6 +236,13 @@ public function testEnd()
207236
}
208237
// if actionGroup flag, start nesting
209238
if (strpos($step->getName(), ActionGroupObject::ACTION_GROUP_CONTEXT_START) !== false) {
239+
if ($actionGroupStepContainer !== null) {
240+
//actionGroup still being nested, need to close out and finish it.
241+
$formattedSteps[] = $actionGroupStepContainer;
242+
$actionGroupStepContainer = null;
243+
$actionGroupStepKey = null;
244+
}
245+
210246
$step->setName(str_replace(ActionGroupObject::ACTION_GROUP_CONTEXT_START, '', $step->getName()));
211247
$actionGroupStepContainer = $step;
212248

0 commit comments

Comments
 (0)