Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"doctrine/orm": "^3.5",
"friendsofphp/php-cs-fixer": "^3.85",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.0",
"symfony/browser-kit": "^5.4 | ^6.4 | ^7.3",
"symfony/cache": "^5.4 | ^6.4 | ^7.3",
"symfony/config": "^5.4 | ^6.4 | ^7.3",
Expand Down
79 changes: 28 additions & 51 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ protected function getClient(): SymfonyConnector
*/
protected function getKernelClass(): string
{
/** @var class-string<Kernel> $kernelClass */
$kernelClass = $this->config['kernel_class'];
$this->requireAdditionalAutoloader();

if (class_exists($kernelClass)) {
return $kernelClass;
}

/** @var string $rootDir */
$rootDir = codecept_root_dir();
$path = $rootDir . $this->config['app_path'];
Expand All @@ -346,40 +354,21 @@ protected function getKernelClass(): string
);
}

$this->requireAdditionalAutoloader();

$finder = new Finder();
$results = iterator_to_array($finder->name('*Kernel.php')->depth('0')->in($path));

if ($results === []) {
throw new ModuleRequireException(
self::class,
"File with Kernel class was not found at {$path}.\n" .
'Specify directory where file with Kernel class for your application is located with `app_path` parameter.'
);
}

$kernelClass = $this->config['kernel_class'];
$filesRealPath = [];
$finder = new Finder();
$finder->name('*Kernel.php')->depth('0')->in($path);

foreach ($results as $file) {
foreach ($finder as $file) {
include_once $file->getRealPath();
$filesRealPath[] = $file->getRealPath();
}

if (class_exists($kernelClass)) {
$ref = new ReflectionClass($kernelClass);
$fileName = $ref->getFileName();
if ($fileName !== false && in_array($fileName, $filesRealPath, true)) {
/** @var class-string<Kernel> $kernelClass */
return $kernelClass;
}
if (class_exists($kernelClass, false)) {
return $kernelClass;
}

throw new ModuleRequireException(
self::class,
"Kernel class was not found.\n" .
'Specify directory where file with Kernel class for your application is located with `kernel_class` parameter.'
"Kernel class was not found at {$path}.\n" .
'Specify directory where file with Kernel class for your application is located with `app_path` parameter.'
);
}

Expand Down Expand Up @@ -455,31 +444,19 @@ protected function debugResponse(mixed $url): void
return;
}

if ($profile->hasCollector(DataCollectorName::SECURITY->value)) {
$securityCollector = $profile->getCollector(DataCollectorName::SECURITY->value);
if ($securityCollector instanceof SecurityDataCollector) {
$this->debugSecurityData($securityCollector);
}
}

if ($profile->hasCollector(DataCollectorName::MAILER->value)) {
$mailerCollector = $profile->getCollector(DataCollectorName::MAILER->value);
if ($mailerCollector instanceof MessageDataCollector) {
$this->debugMailerData($mailerCollector);
}
}

if ($profile->hasCollector(DataCollectorName::NOTIFIER->value)) {
$notifierCollector = $profile->getCollector(DataCollectorName::NOTIFIER->value);
if ($notifierCollector instanceof NotificationDataCollector) {
$this->debugNotifierData($notifierCollector);
}
}

if ($profile->hasCollector(DataCollectorName::TIME->value)) {
$timeCollector = $profile->getCollector(DataCollectorName::TIME->value);
if ($timeCollector instanceof TimeDataCollector) {
$this->debugTimeData($timeCollector);
$collectors = [
DataCollectorName::SECURITY->value => [$this->debugSecurityData(...), SecurityDataCollector::class],
DataCollectorName::MAILER->value => [$this->debugMailerData(...), MessageDataCollector::class],
DataCollectorName::NOTIFIER->value => [$this->debugNotifierData(...), NotificationDataCollector::class],
DataCollectorName::TIME->value => [$this->debugTimeData(...), TimeDataCollector::class],
];

foreach ($collectors as $name => [$callback, $expectedClass]) {
if ($profile->hasCollector($name)) {
$collector = $profile->getCollector($name);
if ($collector instanceof $expectedClass) {
$callback($collector);
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Codeception/Module/Symfony/BrowserAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ public function submitSymfonyForm(string $name, array $fields): void

$params = [];
foreach ($fields as $key => $value) {
$fixedKey = sprintf('%s%s', $name, $key);
$params[$fixedKey] = $value;
$params[$name . $key] = $value;
}

$button = sprintf('%s_submit', $name);
Expand Down
13 changes: 6 additions & 7 deletions src/Codeception/Module/Symfony/MailerAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ public function getMailerEvent(int $index = 0, ?string $transport = null): ?Mess

protected function getMessageMailerEvents(): MessageEvents
{
$mailer = $this->getService('mailer.message_logger_listener');
if ($mailer instanceof MessageLoggerListener) {
return $mailer->getEvents();
}
$mailer = $this->getService('mailer.logger_message_listener');
if ($mailer instanceof MessageLoggerListener) {
return $mailer->getEvents();
$services = ['mailer.message_logger_listener', 'mailer.logger_message_listener'];
foreach ($services as $serviceId) {
$mailer = $this->getService($serviceId);
if ($mailer instanceof MessageLoggerListener) {
return $mailer->getEvents();
}
}
Assert::fail("Emails can't be tested without Symfony Mailer service.");
}
Expand Down
13 changes: 6 additions & 7 deletions src/Codeception/Module/Symfony/NotifierAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,12 @@ protected function getNotificationEvents(): NotificationEvents
Assert::fail('Notifier assertions require Symfony 6.2 or higher.');
}

$notifier = $this->getService('notifier.notification_logger_listener');
if ($notifier instanceof NotificationLoggerListener) {
return $notifier->getEvents();
}
$notifier = $this->getService('notifier.logger_notification_listener');
if ($notifier instanceof NotificationLoggerListener) {
return $notifier->getEvents();
$services = ['notifier.notification_logger_listener', 'notifier.logger_notification_listener'];
foreach ($services as $serviceId) {
$notifier = $this->getService($serviceId);
if ($notifier instanceof NotificationLoggerListener) {
return $notifier->getEvents();
}
}
Assert::fail("Notifications can't be tested without Symfony Notifier service.");
}
Expand Down