enabled())->toBeFalse() ->and($runtime->requested('capital-register'))->toBeFalse() ->and($runtime->feature('capital-register', $db))->toBeFalse(); }); test('standalone feature opt in requires a boolean rather than a truthy setting', function (mixed $value) { $db = Mockery::mock(Connection::class); $runtime = new StandaloneRuntime(['enabled' => $value, 'features' => ['capital-register' => true]], new StandaloneArtifact); expect($runtime->feature('capital-register', $db))->toBeFalse(); })->with([false, 1, 'true', 'false', null]); test('standalone requested features remain explicit before readiness validation', function () { $runtime = new StandaloneRuntime(['enabled' => true, 'features' => ['requisition-accounts' => true]], new StandaloneArtifact); expect($runtime->requested('requisition-accounts'))->toBeTrue() ->and($runtime->requested('private-audit'))->toBeFalse(); expect(fn () => $runtime->artifact())->toThrow(LogicException::class, 'COMPRAS_RUNTIME_CONFIGURATION'); }); test('standalone database binding accepts an ordinary own installation without QA names', function () { $db = Mockery::mock(Connection::class); $db->shouldReceive('getDriverName')->once()->andReturn('pgsql'); $db->shouldReceive('selectOne')->once()->andReturn((object) [ 'database_name' => 'purchasing_company', 'role_name' => 'purchasing_app', 'database_oid' => '45000', 'server_address' => '192.0.2.10', 'server_port' => 5432, 'elevated' => 0, ]); expect(StandaloneRuntime::databaseBinding($db))->toBe(hash('sha256', json_encode([ 'product' => 'compras', 'database' => 'purchasing_company', 'oid' => '45000', 'role' => 'purchasing_app', 'address' => '192.0.2.10', 'port' => 5432, ], JSON_THROW_ON_ERROR))); }); test('standalone binding rejects elevated or unavailable database identities', function (string $failure) { $db = Mockery::mock(Connection::class); $db->shouldReceive('getDriverName')->once()->andReturn('pgsql'); $identity = (object) ['database_name' => 'own', 'role_name' => 'app', 'database_oid' => '1', 'server_address' => '127.0.0.1', 'server_port' => 5432, 'elevated' => 0]; if ($failure === 'elevated') { $identity->elevated = 1; } elseif ($failure === 'address') { $identity->server_address = null; } elseif ($failure === 'port') { $identity->server_port = null; } $db->shouldReceive('selectOne')->once()->andReturn($failure === 'missing' ? null : $identity); expect(fn () => StandaloneRuntime::databaseBinding($db))->toThrow(LogicException::class, 'COMPRAS_RUNTIME_DATABASE_IDENTITY'); })->with(['elevated', 'address', 'port', 'missing']); test('standalone binding rejects other drivers without querying them', function () { $db = Mockery::mock(Connection::class); $db->shouldReceive('getDriverName')->once()->andReturn('sqlite'); expect(fn () => StandaloneRuntime::databaseBinding($db))->toThrow(LogicException::class, 'COMPRAS_RUNTIME_DATABASE_DRIVER'); });