@@ -334,6 +334,14 @@ protected function getClient(): SymfonyConnector
334334 */
335335 protected function getKernelClass (): string
336336 {
337+ /** @var class-string<Kernel> $kernelClass */
338+ $ kernelClass = $ this ->config ['kernel_class ' ];
339+ $ this ->requireAdditionalAutoloader ();
340+
341+ if (class_exists ($ kernelClass )) {
342+ return $ kernelClass ;
343+ }
344+
337345 /** @var string $rootDir */
338346 $ rootDir = codecept_root_dir ();
339347 $ path = $ rootDir . $ this ->config ['app_path ' ];
@@ -346,40 +354,21 @@ protected function getKernelClass(): string
346354 );
347355 }
348356
349- $ this ->requireAdditionalAutoloader ();
350-
351- $ finder = new Finder ();
352- $ results = iterator_to_array ($ finder ->name ('*Kernel.php ' )->depth ('0 ' )->in ($ path ));
353-
354- if ($ results === []) {
355- throw new ModuleRequireException (
356- self ::class,
357- "File with Kernel class was not found at {$ path }. \n" .
358- 'Specify directory where file with Kernel class for your application is located with `app_path` parameter. '
359- );
360- }
361-
362- $ kernelClass = $ this ->config ['kernel_class ' ];
363- $ filesRealPath = [];
357+ $ finder = new Finder ();
358+ $ finder ->name ('*Kernel.php ' )->depth ('0 ' )->in ($ path );
364359
365- foreach ($ results as $ file ) {
360+ foreach ($ finder as $ file ) {
366361 include_once $ file ->getRealPath ();
367- $ filesRealPath [] = $ file ->getRealPath ();
368362 }
369363
370- if (class_exists ($ kernelClass )) {
371- $ ref = new ReflectionClass ($ kernelClass );
372- $ fileName = $ ref ->getFileName ();
373- if ($ fileName !== false && in_array ($ fileName , $ filesRealPath , true )) {
374- /** @var class-string<Kernel> $kernelClass */
375- return $ kernelClass ;
376- }
364+ if (class_exists ($ kernelClass , false )) {
365+ return $ kernelClass ;
377366 }
378367
379368 throw new ModuleRequireException (
380369 self ::class,
381- "Kernel class was not found. \n" .
382- 'Specify directory where file with Kernel class for your application is located with `kernel_class ` parameter. '
370+ "Kernel class was not found at { $ path } . \n" .
371+ 'Specify directory where file with Kernel class for your application is located with `app_path ` parameter. '
383372 );
384373 }
385374
@@ -455,31 +444,19 @@ protected function debugResponse(mixed $url): void
455444 return ;
456445 }
457446
458- if ($ profile ->hasCollector (DataCollectorName::SECURITY ->value )) {
459- $ securityCollector = $ profile ->getCollector (DataCollectorName::SECURITY ->value );
460- if ($ securityCollector instanceof SecurityDataCollector) {
461- $ this ->debugSecurityData ($ securityCollector );
462- }
463- }
464-
465- if ($ profile ->hasCollector (DataCollectorName::MAILER ->value )) {
466- $ mailerCollector = $ profile ->getCollector (DataCollectorName::MAILER ->value );
467- if ($ mailerCollector instanceof MessageDataCollector) {
468- $ this ->debugMailerData ($ mailerCollector );
469- }
470- }
471-
472- if ($ profile ->hasCollector (DataCollectorName::NOTIFIER ->value )) {
473- $ notifierCollector = $ profile ->getCollector (DataCollectorName::NOTIFIER ->value );
474- if ($ notifierCollector instanceof NotificationDataCollector) {
475- $ this ->debugNotifierData ($ notifierCollector );
476- }
477- }
478-
479- if ($ profile ->hasCollector (DataCollectorName::TIME ->value )) {
480- $ timeCollector = $ profile ->getCollector (DataCollectorName::TIME ->value );
481- if ($ timeCollector instanceof TimeDataCollector) {
482- $ this ->debugTimeData ($ timeCollector );
447+ $ collectors = [
448+ DataCollectorName::SECURITY ->value => [$ this ->debugSecurityData (...), SecurityDataCollector::class],
449+ DataCollectorName::MAILER ->value => [$ this ->debugMailerData (...), MessageDataCollector::class],
450+ DataCollectorName::NOTIFIER ->value => [$ this ->debugNotifierData (...), NotificationDataCollector::class],
451+ DataCollectorName::TIME ->value => [$ this ->debugTimeData (...), TimeDataCollector::class],
452+ ];
453+
454+ foreach ($ collectors as $ name => [$ callback , $ expectedClass ]) {
455+ if ($ profile ->hasCollector ($ name )) {
456+ $ collector = $ profile ->getCollector ($ name );
457+ if ($ collector instanceof $ expectedClass ) {
458+ $ callback ($ collector );
459+ }
483460 }
484461 }
485462 }
0 commit comments