| 123456789101112131415161718192021222324252627282930313233 |
- <?php
- declare(strict_types=1);
- namespace App\Tests;
- use PDO;
- use PHPUnit\Framework\TestCase as PhpUnitTestCase;
- /**
- * Base TestCase with helpers for building an in-memory SQLite DB loaded with
- * the same migrations the app runs. Every test gets a fresh isolated database.
- */
- abstract class TestCase extends PhpUnitTestCase
- {
- protected function makeDb(): PDO
- {
- $pdo = new PDO('sqlite::memory:', null, null, [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false,
- ]);
- $pdo->exec('PRAGMA foreign_keys = ON');
- $sql = file_get_contents(__DIR__ . '/../migrations/001_init.sql');
- if ($sql === false) {
- $this->fail('Could not read migrations/001_init.sql');
- }
- $pdo->exec($sql);
- return $pdo;
- }
- }
|