1212use Codeception \Event \TestEvent ;
1313use Codeception \Events ;
1414use Codeception \Exception \ConfigurationException ;
15- use Codeception \Step ;
1615use Qameta \Allure \Allure ;
1716use Qameta \Allure \Allure as QametaAllure ;
1817use Qameta \Allure \Codeception \Internal \DefaultThreadDetector ;
2625use Qameta \Allure \Setup \DefaultStatusDetector ;
2726use Qameta \Allure \Setup \LinkTemplate ;
2827use Qameta \Allure \Setup \LinkTemplateInterface ;
29- use Throwable ;
3028
3129use function class_exists ;
3230use function is_a ;
@@ -46,6 +44,7 @@ final class AllureCodeception extends Extension
4644 private const DEFAULT_RESULTS_DIRECTORY = 'allure-results ' ;
4745
4846 protected static array $ events = [
47+ Events::MODULE_INIT => 'moduleInit ' ,
4948 Events::SUITE_BEFORE => 'suiteBefore ' ,
5049 Events::SUITE_AFTER => 'suiteAfter ' ,
5150 Events::TEST_START => 'testStart ' ,
@@ -69,11 +68,11 @@ final class AllureCodeception extends Extension
6968 * @throws ConfigurationException
7069 * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
7170 */
72- public function _initialize (): void
71+ public function moduleInit (): void
7372 {
74- // phpcs:enable PSR2.Methods.MethodDeclaration.Underscore
75- parent ::_initialize ();
7673 QametaAllure::reset ();
74+ $ this ->testLifecycle = null ;
75+ $ this ->threadDetector = null ;
7776 QametaAllure::getLifecycleConfigurator ()
7877 ->setStatusDetector (new StatusDetector (new DefaultStatusDetector ()))
7978 ->setOutputDirectory ($ this ->getOutputDirectory ());
@@ -148,7 +147,11 @@ class_exists($linkConfig) && is_a($linkConfig, LinkTemplateInterface::class, tru
148147 public function suiteBefore (SuiteEvent $ suiteEvent ): void
149148 {
150149 /** @psalm-suppress InternalMethod */
151- $ suiteName = $ suiteEvent ->getSuite ()->getName ();
150+ $ suiteName = $ suiteEvent ->getSuite ()?->getName();
151+ if (!isset ($ suiteName )) {
152+ return ;
153+ }
154+
152155 $ this
153156 ->getTestLifecycle ()
154157 ->switchToSuite (new SuiteInfo ($ suiteName ));
@@ -185,33 +188,28 @@ private function getThreadDetector(): ThreadDetectorInterface
185188 */
186189 public function testError (FailEvent $ failEvent ): void
187190 {
188- /** @var Throwable $error */
189- $ error = $ failEvent ->getFail ();
190191 $ this
191192 ->getTestLifecycle ()
192193 ->switchToTest ($ failEvent ->getTest ())
193- ->updateTestFailure ($ error );
194+ ->updateTestFailure ($ failEvent -> getFail () );
194195 }
195196
196197 /**
197198 * @psalm-suppress MissingDependency
198199 */
199200 public function testFail (FailEvent $ failEvent ): void
200201 {
201- /** @var Throwable $error */
202- $ error = $ failEvent ->getFail ();
203202 $ this
204203 ->getTestLifecycle ()
205204 ->switchToTest ($ failEvent ->getTest ())
206- ->updateTestFailure ($ error , Status::failed ());
205+ ->updateTestFailure ($ failEvent -> getFail () , Status::failed ());
207206 }
208207
209208 /**
210209 * @psalm-suppress MissingDependency
211210 */
212211 public function testIncomplete (FailEvent $ failEvent ): void
213212 {
214- /** @var Throwable $error */
215213 $ error = $ failEvent ->getFail ();
216214 $ this
217215 ->getTestLifecycle ()
@@ -228,7 +226,6 @@ public function testIncomplete(FailEvent $failEvent): void
228226 */
229227 public function testSkipped (FailEvent $ failEvent ): void
230228 {
231- /** @var Throwable $error */
232229 $ error = $ failEvent ->getFail ();
233230 $ this
234231 ->getTestLifecycle ()
@@ -269,12 +266,10 @@ public function testEnd(TestEvent $testEvent): void
269266 */
270267 public function stepBefore (StepEvent $ stepEvent ): void
271268 {
272- /** @psalm-var Step $step */
273- $ step = $ stepEvent ->getStep ();
274269 $ this
275270 ->getTestLifecycle ()
276271 ->switchToTest ($ stepEvent ->getTest ())
277- ->startStep ($ step )
272+ ->startStep ($ stepEvent -> getStep () )
278273 ->updateStep ();
279274 }
280275
@@ -283,12 +278,10 @@ public function stepBefore(StepEvent $stepEvent): void
283278 */
284279 public function stepAfter (StepEvent $ stepEvent ): void
285280 {
286- /** @psalm-var Step $step */
287- $ step = $ stepEvent ->getStep ();
288281 $ this
289282 ->getTestLifecycle ()
290283 ->switchToTest ($ stepEvent ->getTest ())
291- ->switchToStep ($ step )
284+ ->switchToStep ($ stepEvent -> getStep () )
292285 ->updateStepResult ()
293286 ->stopStep ();
294287 }
0 commit comments