1818class 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