99use Magento \FunctionalTestingFramework \Suite \Handlers \SuiteObjectHandler ;
1010use Magento \FunctionalTestingFramework \Test \Objects \ActionGroupObject ;
1111use \Magento \FunctionalTestingFramework \Util \TestGenerator ;
12+ use Yandex \Allure \Adapter \Model \Status ;
1213use Yandex \Allure \Adapter \Model \Step ;
1314use Yandex \Allure \Codeception \AllureCodeception ;
1415use Yandex \Allure \Adapter \Event \StepStartedEvent ;
1516use Yandex \Allure \Adapter \Event \StepFinishedEvent ;
1617use Yandex \Allure \Adapter \Event \StepFailedEvent ;
1718use Yandex \Allure \Adapter \Event \TestCaseFailedEvent ;
1819use Yandex \Allure \Adapter \Event \TestCaseFinishedEvent ;
20+ use Yandex \Allure \Adapter \Event \TestCaseBrokenEvent ;
1921use Codeception \Event \FailEvent ;
2022use Codeception \Event \SuiteEvent ;
2123use 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