Files
netslim-core/tests/Kernel/ModuleSchemaTest.php

48 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Kernel;
use Netig\Netslim\Kernel\Runtime\Module\ModuleRegistry;
use Netig\Netslim\Kernel\Runtime\Module\ProvidesSchemaInterface;
use PHPUnit\Framework\TestCase;
use Tests\Support\TestRuntimeFactory;
final class ModuleSchemaTest extends TestCase
{
protected function setUp(): void
{
TestRuntimeFactory::resetRuntime();
}
protected function tearDown(): void
{
ModuleRegistry::reset();
}
public function testFeatureModulesDeclareOwnedMigrationDirectoriesAndTables(): void
{
$schemaModules = array_values(array_filter(
ModuleRegistry::modules(),
static fn (object $module): bool => $module instanceof ProvidesSchemaInterface,
));
self::assertCount(6, $schemaModules);
foreach ($schemaModules as $module) {
foreach ($module->migrationDirectories() as $directory) {
self::assertDirectoryExists($directory, $module::class . ' should expose an existing migration directory.');
self::assertNotSame([], glob(rtrim($directory, '/') . '/*.php') ?: [], $module::class . ' should expose at least one migration file.');
}
self::assertNotSame([], $module->requiredTables(), $module::class . ' should expose owned tables for readiness checks.');
}
}
public function testLegacyGlobalMigrationsDirectoryIsNoLongerUsed(): void
{
self::assertSame([], glob(dirname(__DIR__, 2) . '/database/migrations/*.php') ?: []);
}
}