32 lines
966 B
PHP
32 lines
966 B
PHP
<?php
|
|
|
|
namespace Tests\Support;
|
|
|
|
use Illuminate\Database\Connectors\ConnectionFactory;
|
|
use RuntimeException;
|
|
|
|
final class InMemoryConnectionFactory extends ConnectionFactory
|
|
{
|
|
public static function assertSafe(array $config): void
|
|
{
|
|
// Reject URLs and alternate endpoints rather than trusting a database name.
|
|
if (($config['driver'] ?? null) !== 'sqlite'
|
|
|| ($config['database'] ?? null) !== ':memory:'
|
|
|| ! empty($config['url'])
|
|
|| array_key_exists('read', $config)
|
|
|| array_key_exists('write', $config)
|
|
|| array_key_exists('direct', $config)) {
|
|
throw new RuntimeException(
|
|
'Unsafe test connection. Tests may only use SQLite :memory: without URLs or alternate endpoints.'
|
|
);
|
|
}
|
|
}
|
|
|
|
public function make(array $config, $name = null)
|
|
{
|
|
self::assertSafe($config);
|
|
|
|
return parent::make($config, $name);
|
|
}
|
|
}
|