Refactor core test runtime and simplify project documentation
This commit is contained in:
34
tests/Support/TestDatabaseFactory.php
Normal file
34
tests/Support/TestDatabaseFactory.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* Fabrique légère pour les bases SQLite de test.
|
||||
*/
|
||||
final class TestDatabaseFactory
|
||||
{
|
||||
public static function createInMemory(): PDO
|
||||
{
|
||||
return new PDO('sqlite::memory:', options: [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function createFileBacked(string $name): PDO
|
||||
{
|
||||
$path = TestRuntimeFactory::path('database/' . $name . '.sqlite');
|
||||
if (is_file($path)) {
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
return new PDO('sqlite:' . $path, options: [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user