Refactor core test runtime and simplify project documentation
This commit is contained in:
@@ -18,7 +18,6 @@ use Netig\Netslim\Identity\UI\Http\UserController;
|
||||
use Netig\Netslim\Kernel\Http\Infrastructure\Twig\AppExtension;
|
||||
use Netig\Netslim\Kernel\Runtime\Http\MiddlewareRegistrar;
|
||||
use Netig\Netslim\Kernel\Runtime\Module\ModuleRegistry;
|
||||
use Netig\Netslim\Kernel\Runtime\RuntimePaths;
|
||||
use Netig\Netslim\Media\Application\MediaServiceInterface;
|
||||
use Netig\Netslim\Media\UI\Http\MediaController;
|
||||
use Netig\Netslim\Notifications\Application\NotificationServiceInterface;
|
||||
@@ -30,6 +29,7 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Slim\Factory\AppFactory;
|
||||
use Slim\Views\Twig;
|
||||
use Tests\Support\TestRuntimeFactory;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
|
||||
final class ContainerWiringIntegrationTest extends TestCase
|
||||
@@ -56,8 +56,7 @@ final class ContainerWiringIntegrationTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
ModuleRegistry::reset();
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
foreach (self::ENV_DEFAULTS as $key => $value) {
|
||||
$this->envBackup[$key] = $_ENV[$key] ?? null;
|
||||
$_ENV[$key] = $value;
|
||||
@@ -66,8 +65,6 @@ final class ContainerWiringIntegrationTest extends TestCase
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
RuntimePaths::resetApplicationRoot();
|
||||
RuntimePaths::resetProjectRoot();
|
||||
ModuleRegistry::reset();
|
||||
foreach (self::ENV_DEFAULTS as $key => $_) {
|
||||
$previous = $this->envBackup[$key] ?? null;
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace Tests\Kernel;
|
||||
|
||||
use Netig\Netslim\Kernel\Persistence\Infrastructure\DatabaseNotProvisionedException;
|
||||
use Netig\Netslim\Kernel\Persistence\Infrastructure\DatabaseReadiness;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Support\TestDatabaseFactory;
|
||||
|
||||
final class DatabaseReadinessTest extends TestCase
|
||||
{
|
||||
public function testAssertProvisionedFailsWhenModuleTablesAreMissing(): void
|
||||
{
|
||||
$db = new PDO('sqlite::memory:');
|
||||
$db = TestDatabaseFactory::createInMemory();
|
||||
$db->exec('CREATE TABLE migrations (id INTEGER PRIMARY KEY AUTOINCREMENT, version TEXT, run_at TEXT)');
|
||||
|
||||
$this->expectException(DatabaseNotProvisionedException::class);
|
||||
@@ -24,7 +24,7 @@ final class DatabaseReadinessTest extends TestCase
|
||||
|
||||
public function testAssertProvisionedAcceptsCompleteCoreSchema(): void
|
||||
{
|
||||
$db = new PDO('sqlite::memory:');
|
||||
$db = TestDatabaseFactory::createInMemory();
|
||||
|
||||
$db->exec('CREATE TABLE migrations (id INTEGER PRIMARY KEY AUTOINCREMENT, version TEXT, run_at TEXT)');
|
||||
$db->exec('CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT, email TEXT, password_hash TEXT, role TEXT, session_version INTEGER, created_at TEXT)');
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace Tests\Kernel;
|
||||
|
||||
use Netig\Netslim\Kernel\Persistence\Infrastructure\Migrator;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Support\TestDatabaseFactory;
|
||||
|
||||
/**
|
||||
* Tests unitaires pour Migrator.
|
||||
@@ -18,14 +18,11 @@ use PHPUnit\Framework\TestCase;
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class MigratorTest extends TestCase
|
||||
{
|
||||
private PDO $db;
|
||||
private \PDO $db;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->db = new PDO('sqlite::memory:', options: [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
$this->db = TestDatabaseFactory::createInMemory();
|
||||
}
|
||||
|
||||
public function testRunCreatesMigrationsTable(): void
|
||||
|
||||
@@ -8,26 +8,23 @@ use Netig\Netslim\Kernel\Runtime\Module\ModuleInterface;
|
||||
use Netig\Netslim\Kernel\Runtime\Module\ModuleRegistry;
|
||||
use Netig\Netslim\Kernel\Runtime\RuntimePaths;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Support\TestRuntimeFactory;
|
||||
|
||||
final class ModuleRegistryTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
RuntimePaths::resetApplicationRoot();
|
||||
RuntimePaths::resetProjectRoot();
|
||||
ModuleRegistry::reset();
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
RuntimePaths::resetApplicationRoot();
|
||||
RuntimePaths::resetProjectRoot();
|
||||
ModuleRegistry::reset();
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
}
|
||||
|
||||
public function testModulesAreDeclaredInExpectedOrderForFixtureApplication(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
|
||||
$moduleClasses = array_map(
|
||||
static fn (ModuleInterface $module): string => $module::class,
|
||||
@@ -47,7 +44,7 @@ final class ModuleRegistryTest extends TestCase
|
||||
|
||||
public function testModuleClassNamesExposeTheActiveApplicationComposition(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
|
||||
self::assertSame([
|
||||
'Netig\Netslim\Kernel\Runtime\KernelModule',
|
||||
@@ -62,14 +59,14 @@ final class ModuleRegistryTest extends TestCase
|
||||
|
||||
public function testApplicationManifestIsResolvedFromTheActiveApplicationRoot(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
|
||||
self::assertFileExists(RuntimePaths::getApplicationConfigPath('modules.php'));
|
||||
}
|
||||
|
||||
public function testEveryModuleExposesResolvableMetadata(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
|
||||
foreach (ModuleRegistry::modules() as $module) {
|
||||
self::assertNotSame([], $module->definitions(), $module::class . ' should expose DI definitions.');
|
||||
|
||||
@@ -6,21 +6,18 @@ namespace Tests\Kernel;
|
||||
|
||||
use Netig\Netslim\Kernel\Runtime\Module\ModuleRegistry;
|
||||
use Netig\Netslim\Kernel\Runtime\Module\ProvidesSchemaInterface;
|
||||
use Netig\Netslim\Kernel\Runtime\RuntimePaths;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Support\TestRuntimeFactory;
|
||||
|
||||
final class ModuleSchemaTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
ModuleRegistry::reset();
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
RuntimePaths::resetApplicationRoot();
|
||||
RuntimePaths::resetProjectRoot();
|
||||
ModuleRegistry::reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,15 @@ declare(strict_types=1);
|
||||
namespace Tests\Kernel;
|
||||
|
||||
use Netig\Netslim\Kernel\Persistence\Infrastructure\Provisioner;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Support\TestDatabaseFactory;
|
||||
use Tests\Support\TestRuntimeFactory;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class ProvisionerTest extends TestCase
|
||||
{
|
||||
private PDO $db;
|
||||
private \PDO $db;
|
||||
|
||||
private string $lockPath;
|
||||
|
||||
@@ -20,13 +21,11 @@ final class ProvisionerTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->db = new PDO('sqlite::memory:', options: [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
$this->db = TestDatabaseFactory::createInMemory();
|
||||
$this->db->sqliteCreateFunction('strip_tags', 'strip_tags', 1);
|
||||
|
||||
$this->lockPath = dirname(__DIR__, 2) . '/database/.provision.lock';
|
||||
$this->lockPath = TestRuntimeFactory::path('database/.provision.lock');
|
||||
@unlink($this->lockPath);
|
||||
|
||||
$this->envBackup = [
|
||||
|
||||
@@ -6,23 +6,20 @@ namespace Tests\Kernel;
|
||||
|
||||
use Netig\Netslim\Kernel\Runtime\Module\ModuleRegistry;
|
||||
use Netig\Netslim\Kernel\Runtime\Routing\Routes;
|
||||
use Netig\Netslim\Kernel\Runtime\RuntimePaths;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Slim\Factory\AppFactory;
|
||||
use Tests\Support\TestRuntimeFactory;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class RoutesTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
ModuleRegistry::reset();
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
RuntimePaths::resetApplicationRoot();
|
||||
RuntimePaths::resetProjectRoot();
|
||||
ModuleRegistry::reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,40 +6,40 @@ namespace Tests\Kernel;
|
||||
|
||||
use Netig\Netslim\Kernel\Runtime\RuntimePaths;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Support\TestRuntimeFactory;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class RuntimePathsTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
RuntimePaths::resetApplicationRoot();
|
||||
RuntimePaths::resetProjectRoot();
|
||||
TestRuntimeFactory::resetRuntime();
|
||||
}
|
||||
|
||||
public function testGetProjectRootReturnsRepositoryRoot(): void
|
||||
public function testGetProjectRootReturnsIsolatedTestProjectRoot(): void
|
||||
{
|
||||
self::assertSame(dirname(__DIR__, 2), RuntimePaths::getProjectRoot());
|
||||
self::assertSame(TestRuntimeFactory::projectRoot(), RuntimePaths::getProjectRoot());
|
||||
}
|
||||
|
||||
public function testGetConfigPathReturnsRootConfigDirectoryAndFilePath(): void
|
||||
{
|
||||
self::assertSame(dirname(__DIR__, 2) . '/config', RuntimePaths::getConfigPath());
|
||||
self::assertSame(dirname(__DIR__, 2) . '/config/modules.php', RuntimePaths::getConfigPath('modules.php'));
|
||||
self::assertSame(TestRuntimeFactory::path('config'), RuntimePaths::getConfigPath());
|
||||
self::assertSame(TestRuntimeFactory::path('config/modules.php'), RuntimePaths::getConfigPath('modules.php'));
|
||||
}
|
||||
|
||||
public function testApplicationRootDefaultsToProjectRoot(): void
|
||||
{
|
||||
self::assertSame(dirname(__DIR__, 2), RuntimePaths::getApplicationRoot());
|
||||
self::assertSame(dirname(__DIR__, 2) . '/config', RuntimePaths::getApplicationConfigPath());
|
||||
self::assertSame(TestRuntimeFactory::applicationRoot(), RuntimePaths::getApplicationRoot());
|
||||
self::assertSame(TestRuntimeFactory::path('config'), RuntimePaths::getApplicationConfigPath());
|
||||
}
|
||||
|
||||
public function testApplicationRootCanPointToFixtureApplication(): void
|
||||
public function testApplicationRootCanPointToTheIsolatedFixtureApplication(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
RuntimePaths::setApplicationRoot(TestRuntimeFactory::applicationRoot());
|
||||
|
||||
self::assertSame(dirname(__DIR__, 2) . '/tests/Fixtures/Application', RuntimePaths::getApplicationRoot());
|
||||
self::assertSame(dirname(__DIR__, 2) . '/tests/Fixtures/Application/config/modules.php', RuntimePaths::getApplicationConfigPath('modules.php'));
|
||||
self::assertSame(dirname(__DIR__, 2) . '/tests/Fixtures/Application/templates/Kernel', RuntimePaths::getApplicationPath('templates/Kernel'));
|
||||
self::assertSame(TestRuntimeFactory::applicationRoot(), RuntimePaths::getApplicationRoot());
|
||||
self::assertSame(TestRuntimeFactory::path('config/modules.php'), RuntimePaths::getApplicationConfigPath('modules.php'));
|
||||
self::assertSame(TestRuntimeFactory::path('templates/Kernel'), RuntimePaths::getApplicationPath('templates/Kernel'));
|
||||
}
|
||||
|
||||
public function testGetTwigCacheReturnsFalseInDev(): void
|
||||
@@ -57,7 +57,7 @@ final class RuntimePathsTest extends TestCase
|
||||
|
||||
public function testGetDatabasePathCreatesDatabaseFileWhenMissing(): void
|
||||
{
|
||||
$dbFile = dirname(__DIR__, 2) . '/database/app.sqlite';
|
||||
$dbFile = TestRuntimeFactory::path('database/app.sqlite');
|
||||
$dbDir = dirname($dbFile);
|
||||
$backup = $dbFile . '.bak-test';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user