TenantAtlas/apps/platform/tests/Unit/SettingsFoundation/SettingsResolverCacheTest.php
ahmido ce0615a9c1 Spec 182: relocate Laravel platform to apps/platform (#213)
## Summary
- move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling
- update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location
- add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation`
- integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404`

## Remaining Rollout Checks
- validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout
- confirm web, queue, and scheduler processes all start from the expected working directory in staging/production
- verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #213
2026-04-08 08:40:47 +00:00

78 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Workspace;
use App\Models\WorkspaceSetting;
use App\Services\Settings\SettingsResolver;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
uses(RefreshDatabase::class);
it('caches repeated workspace setting resolution within a request', function (): void {
$workspace = Workspace::factory()->create();
WorkspaceSetting::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'domain' => 'backup',
'key' => 'retention_keep_last_default',
'value' => 41,
'updated_by_user_id' => null,
]);
$resolver = app(SettingsResolver::class);
DB::flushQueryLog();
DB::enableQueryLog();
expect($resolver->resolveValue($workspace, 'backup', 'retention_keep_last_default'))->toBe(41);
expect($resolver->resolveValue($workspace, 'backup', 'retention_keep_last_default'))->toBe(41);
$workspaceSettingsQueries = collect(DB::getQueryLog())
->pluck('query')
->filter(fn (string $query): bool => str_contains($query, 'workspace_settings'))
->count();
expect($workspaceSettingsQueries)->toBe(1);
});
it('resolves tenant override from cache without repeated database reads', function (): void {
$workspace = Workspace::factory()->create();
$tenant = \App\Models\Tenant::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
]);
WorkspaceSetting::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'domain' => 'backup',
'key' => 'retention_keep_last_default',
'value' => 22,
'updated_by_user_id' => null,
]);
\App\Models\TenantSetting::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'tenant_id' => (int) $tenant->getKey(),
'domain' => 'backup',
'key' => 'retention_keep_last_default',
'value' => 12,
'updated_by_user_id' => null,
]);
$resolver = app(SettingsResolver::class);
DB::flushQueryLog();
DB::enableQueryLog();
expect($resolver->resolveValue($workspace, 'backup', 'retention_keep_last_default', $tenant))->toBe(12);
expect($resolver->resolveValue($workspace, 'backup', 'retention_keep_last_default', $tenant))->toBe(12);
$settingsQueries = collect(DB::getQueryLog())
->pluck('query')
->filter(fn (string $query): bool => str_contains($query, 'tenant_settings') || str_contains($query, 'workspace_settings'))
->count();
expect($settingsQueries)->toBe(2);
});