You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/MailDriverRegistryContractT...

41 lines
1.4 KiB
PHTML

<?php
$root = dirname(__DIR__);
$mailDirectory = $root . '/app/Services/Mail';
$mailService = file_get_contents($root . '/app/Services/Mail.php');
$configExample = file_get_contents($root . '/config/.config.php.example');
function expectMailDriverRegistry($condition, string $message): void
{
if (!$condition) {
fwrite(STDERR, $message . PHP_EOL);
exit(1);
}
}
$driverFiles = array_map('basename', glob($mailDirectory . '/*.php') ?: []);
sort($driverFiles);
$expectedDriverFiles = ['Base.php', 'Mailgun.php', 'NullMail.php', 'Smtp.php'];
expectMailDriverRegistry(
$driverFiles === $expectedDriverFiles,
'The mail transport directory must contain only the supported drivers.'
);
expectMailDriverRegistry(is_string($mailService), 'Unable to read the mail service.');
preg_match_all('/case\s+["\']([^"\']+)["\']\s*:/', $mailService, $driverCases);
expectMailDriverRegistry(
($driverCases[1] ?? []) === ['mailgun', 'smtp'],
'The mail service must register only Mailgun and SMTP transports.'
);
expectMailDriverRegistry(
str_contains($mailService, 'return new NullMail();'),
'Unknown or disabled mail transports must retain the null fallback.'
);
expectMailDriverRegistry(
is_string($configExample)
&& str_contains($configExample, "'smtp'; // mailgun or smtp"),
'The example configuration must document the complete supported transport list.'
);
echo "Mail driver registry checks passed.\n";