Skip to content

Commit

Permalink
update and fix initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Apr 14, 2026
1 parent 64c09e1 commit 191090e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
6 changes: 3 additions & 3 deletions app/tests/TestCase/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
32 changes: 5 additions & 27 deletions app/tests/TestCase/Command/RegistrySetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
use RuntimeException;

final class RegistrySetupTest extends TestCase
{
Expand All @@ -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,
Expand All @@ -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');
Expand Down

0 comments on commit 191090e

Please sign in to comment.