Files
breadcrumb-the-shire/tests/Architecture/ApiSchemaContractTest.php
fs 0e86925464 refactor: rename lib/ to core/ for clearer core-module separation
Rename the top-level lib/ directory to core/ so the project root
immediately communicates which code is core platform and which lives
in modules/. PHP namespaces (MintyPHP\*) are unchanged — only the
Composer PSR-4 path mapping moves from lib/ to core/.

Module-internal lib/ directories (modules/*/lib/) are untouched.

Updated across the full stack:
- composer.json PSR-4 mapping
- bootstrap entry points (web/index.php, bin/*, tests/bootstrap.php)
- tooling configs (phpstan.neon, phpunit.xml, php-cs-fixer)
- 26 architecture contract tests
- enforcement-policy, guard-catalog, quality-gates
- all documentation (CLAUDE.md, README, 25 docs/, .agents/skills/)
- bin/qa-extended.sh search paths
- .claude/settings.local.json permission paths

Workflow: .agents/runs/CORE-LIB-RENAME-001/ (Analyst → Planner →
Executor → Code Review (4 findings fixed) → Security Review →
Acceptance Test → Finalizer)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 23:20:42 +02:00

67 lines
3.3 KiB
PHP

<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
class ApiSchemaContractTest extends TestCase
{
use ProjectFileAssertionSupport;
public function testOpenApiMarksLoginAsPublic(): void
{
$content = $this->readProjectFile('docs/openapi.yaml');
$this->assertMatchesRegularExpression('/\/auth\/login:\s+post:.*?security:\s*\[\]/s', $content);
$this->assertStringContainsString('no Authorization header required', $content);
}
public function testOpenApiIncludesNewCriticalFrontendEndpoints(): void
{
$content = $this->readProjectFile('docs/openapi.yaml');
$this->assertStringContainsString('/permissions:', $content);
$this->assertStringContainsString('/me/password:', $content);
$this->assertStringContainsString('/me/avatar:', $content);
$this->assertStringContainsString('/users/avatar/{uuid}:', $content);
$this->assertStringContainsString('/tenants/avatar/{uuid}:', $content);
$this->assertStringContainsString('/settings:', $content);
$this->assertStringContainsString('/settings/public:', $content);
}
public function testOpenApiUsesUuidBasedMasterDataContracts(): void
{
$content = $this->readProjectFile('docs/openapi.yaml');
$this->assertStringContainsString('required: [description, tenant_uuid]', $content);
$this->assertStringContainsString('tenant_uuids:', $content);
$this->assertStringContainsString('primary_tenant_uuid:', $content);
$this->assertStringContainsString('role_uuids:', $content);
$this->assertStringContainsString('department_uuids:', $content);
$this->assertStringContainsString('permission_keys:', $content);
$this->assertStringContainsString('tenant_uuid:', $content);
}
public function testTenantShowOpenApiStaysInSyncWithResponseContract(): void
{
$openApiContent = $this->readProjectFile('docs/openapi.yaml');
$this->assertStringContainsString('TenantShowResponse:', $openApiContent);
$this->assertStringContainsString('primary_color_use_default:', $openApiContent);
$this->assertStringContainsString('allow_user_theme_mode:', $openApiContent);
$this->assertStringContainsString('support_email:', $openApiContent);
}
public function testApiErrorEnvelopeIsCentralizedAndRequestIdAware(): void
{
$apiResponse = $this->readProjectFile('core/Http/ApiResponse.php');
$this->assertStringContainsString("'ok' => false", $apiResponse);
$this->assertStringContainsString("'error_code' => \$normalizedErrorCode", $apiResponse);
$this->assertStringContainsString("'details' => \$normalizedDetails", $apiResponse);
$this->assertStringContainsString("header('X-Request-Id: ' . \$requestId);", $apiResponse);
$this->assertStringNotContainsString("'error' => \$normalizedErrorCode", $apiResponse);
$this->assertStringNotContainsString("\$body['errors']", $apiResponse);
$openApi = $this->readProjectFile('docs/openapi.yaml');
$this->assertStringContainsString('required: [ok, request_id, error_code, details]', $openApi);
$this->assertStringNotContainsString('Legacy alias of `error_code`', $openApi);
$this->assertStringNotContainsString('Legacy alias of `details.errors`', $openApi);
}
}