18
18
class TestContextExtension extends BaseExtension
19
19
{
20
20
const TEST_PHASE_AFTER = "_after " ;
21
- const CODECEPT_AFTER_VERSION = "2.3.9 " ;
22
21
const TEST_FAILED_FILE = 'failed ' ;
23
22
24
23
/**
@@ -64,15 +63,8 @@ public function testStart()
64
63
*/
65
64
public function testFail (\Codeception \Event \FailEvent $ e )
66
65
{
67
- $ cest = $ e ->getTest ();
68
66
//log suppressed exception in case of _after hook failure
69
67
$ 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
- }
76
68
}
77
69
78
70
/**
@@ -98,13 +90,6 @@ function () use ($cest) {
98
90
if ($ error ->failedTest ()->getTestMethod () == $ cest ->getName ()) {
99
91
//log suppressed exception in case of _after hook failure
100
92
$ 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
- }
108
93
continue ;
109
94
}
110
95
}
@@ -113,31 +98,6 @@ function () use ($cest) {
113
98
$ this ->getDriver ()->_runAfter ($ e ->getTest ());
114
99
}
115
100
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
-
141
101
/**
142
102
* Extracts hook method from trace, looking specifically for the cest class given.
143
103
* @param array $trace
@@ -170,10 +130,6 @@ public function logPreviousException(\Exception $exception)
170
130
}
171
131
};
172
132
$ firstException = $ change ->call ($ exception );
173
- $ bind = function () use ($ firstException ) {
174
- $ exception = $ firstException ;
175
- };
176
- $ bind ->call ($ exception );
177
133
if ($ firstException !== null ) {
178
134
AllureHelper::addAttachmentToCurrentStep ($ firstException , 'Exception ' );
179
135
}
0 commit comments