27 lines
868 B
PHP
27 lines
868 B
PHP
<?php
|
|
|
|
namespace Tests;
|
|
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
|
use RuntimeException;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
public function createApplication(): Application
|
|
{
|
|
$app = parent::createApplication();
|
|
$connection = (string) $app['config']->get('database.default');
|
|
$database = (string) $app['config']->get("database.connections.{$connection}.database");
|
|
$usesInMemorySqlite = $connection === 'sqlite' && $database === ':memory:';
|
|
|
|
if (! $usesInMemorySqlite && ! str_ends_with(strtolower($database), '_test')) {
|
|
throw new RuntimeException(
|
|
"Unsafe test database [{$database}]. Tests may only use an in-memory SQLite database or a database ending in _test.",
|
|
);
|
|
}
|
|
|
|
return $app;
|
|
}
|
|
}
|