Files
ppeasy_vg12/tests/Feature/EnvironmentTemplateTest.php
T
2026-10-09 08:21:06 +02:00

50 lines
1.4 KiB
PHP

<?php
/**
* @return array<string, array{string}>
*/
dataset('templates', function () {
return [
'.env.example' => [__DIR__.'/../../.env.example'],
'installer' => [__DIR__.'/../../app/Http/Controllers/Web/InstallController.php'],
];
});
test('template names a configured mailer', function (string $path) {
$mailer = valueOf('MAIL_MAILER', $path);
$this->assertArrayHasKey(
$mailer,
config('mail.mailers'),
"MAIL_MAILER=$mailer is not defined in config/mail.php."
);
})->with('templates');
test('template ships with demo mode off', function (string $path) {
$this->assertSame('false', valueOf('DEMO_MODE', $path));
})->with('templates');
test('template names a configured database connection', function (string $path) {
$connection = valueOf('DB_CONNECTION', $path);
$this->assertArrayHasKey(
$connection,
config('database.connections'),
"DB_CONNECTION=$connection is not defined in config/database.php."
);
})->with('templates');
/**
* Read a single environment value out of a template.
*/
function valueOf(string $key, string $path): string
{
test()->assertFileExists($path);
$matched = preg_match('/^\s*'.preg_quote($key, '/').'=(.*)$/m', file_get_contents($path), $matches);
test()->assertSame(1, $matched, "$key is not present in ".basename($path).'.');
return trim($matches[1], " \t\"'");
}