From 191090e8959b53693207f4d29d61b0d2bd70d2b6 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 14 Apr 2026 11:05:55 +0000 Subject: [PATCH] update and fix initial tests --- app/tests/TestCase/ApplicationTest.php | 6 ++-- .../TestCase/Command/RegistrySetupTest.php | 32 +++---------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/app/tests/TestCase/ApplicationTest.php b/app/tests/TestCase/ApplicationTest.php index 63bc3d1bb..2bb013320 100644 --- a/app/tests/TestCase/ApplicationTest.php +++ b/app/tests/TestCase/ApplicationTest.php @@ -78,11 +78,11 @@ public function testMiddleware() $middleware = $app->middleware($middleware); $this->assertInstanceOf(ErrorHandlerMiddleware::class, $middleware->current()); + $middleware->seek(1); - $this->assertInstanceOf(HostHeaderMiddleware::class, $middleware->current()); - $middleware->seek(2); $this->assertInstanceOf(AssetMiddleware::class, $middleware->current()); - $middleware->seek(3); + + $middleware->seek(2); $this->assertInstanceOf(RoutingMiddleware::class, $middleware->current()); } } diff --git a/app/tests/TestCase/Command/RegistrySetupTest.php b/app/tests/TestCase/Command/RegistrySetupTest.php index 111131f7c..fbb2b3fb4 100644 --- a/app/tests/TestCase/Command/RegistrySetupTest.php +++ b/app/tests/TestCase/Command/RegistrySetupTest.php @@ -7,7 +7,6 @@ use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; use Cake\Datasource\ConnectionManager; use Cake\TestSuite\TestCase; -use RuntimeException; final class RegistrySetupTest extends TestCase { @@ -16,28 +15,13 @@ final class RegistrySetupTest extends TestCase public function testRegistrySetupRunsSuccessfully(): void { $appDir = dirname(__DIR__, 3); - $registryDir = dirname($appDir); - $registryDir = getenv('COMANAGE_REGISTRY_DIR') ?: $registryDir; $adminGiven = getenv('COMANAGE_REGISTRY_ADMIN_GIVEN_NAME') ?: 'Admin'; $adminFamily = getenv('COMANAGE_REGISTRY_ADMIN_FAMILY_NAME') ?: 'User'; $adminUser = getenv('COMANAGE_REGISTRY_ADMIN_USERNAME') ?: 'admin'; - $salt = getenv('COMANAGE_REGISTRY_SECURITY_SALT') ?: 'phpunit-security-salt'; - $saltFile = $registryDir . '/local/config/security.salt'; - - @mkdir(dirname($saltFile), 0775, true); - @unlink($saltFile); - file_put_contents($saltFile, $salt); - - $this->assertFileExists($saltFile, 'security.salt should exist prior to running setup'); - $this->assertSame($salt, file_get_contents($saltFile)); - - // 1) Run database command - $this->exec('database'); - $this->assertExitCode(0, 'bin/cake database should exit successfully'); - - // 2) Run setup command + // The test bootstrap already sets the Security salt and prepares the test DB schema. + // Here we only validate that the setup command can run successfully. $this->exec(sprintf( 'setup --admin-given-name %s --admin-family-name %s --admin-username %s', $adminGiven, @@ -46,24 +30,18 @@ public function testRegistrySetupRunsSuccessfully(): void )); $this->assertExitCode(0, 'bin/cake setup should exit successfully'); - // 3) Basic sanity checks - $this->assertFileExists($saltFile, 'security.salt should exist after setup'); - $this->assertSame($salt, file_get_contents($saltFile), 'security.salt should remain the expected value'); - $connection = ConnectionManager::get('test'); // Verify we can talk to the DB and it has tables. $tables = $connection->getSchemaCollection()->listTables(); - $this->assertNotEmpty($tables, 'Expected at least one table after running setup/database'); + $this->assertNotEmpty($tables, 'Expected at least one table in the test database'); - // 4) Assert schema.json tables exist + // Assert schema.json tables exist in the DB. $schemaFile = $appDir . '/config/schema/schema.json'; $this->assertFileExists($schemaFile, 'Expected schema.json to exist at config/schema/schema.json'); $json = file_get_contents($schemaFile); - if ($json === false) { - throw new RuntimeException('Failed to read schema file: ' . $schemaFile); - } + $this->assertNotFalse($json, 'Failed to read schema file: ' . $schemaFile); $data = json_decode($json, true); $this->assertIsArray($data, 'schema.json did not decode into an array');