## Summary - remove tenant-based Graph options access from runtime service paths and enforce provider-only resolution - add `MicrosoftGraphOptionsResolver` and `ProviderConfigurationRequiredException` for centralized, actionable provider-config errors - turn `Tenant::graphOptions()` into a fail-fast kill switch to prevent legacy runtime usage - add and update tests (including guardrail) to enforce no reintroduction in `app/` - update Spec 088 artifacts (`spec`, `plan`, `research`, `tasks`, checklist) ## Validation - `vendor/bin/sail bin pint --dirty` - `vendor/bin/sail artisan test --compact --filter=NoLegacyTenantGraphOptions` - `vendor/bin/sail artisan test --compact tests/Feature/Filament` - `CI=1 vendor/bin/sail artisan test --compact` ## Notes - Branch includes the guardrail test for legacy callsite detection in `app/`. - Full suite currently green: 1227 passed, 5 skipped. Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Reviewed-on: #105
98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Models\BackupItem;
|
|
use App\Models\Policy;
|
|
use App\Models\Tenant;
|
|
use App\Services\Intune\BackupService;
|
|
use App\Services\Intune\FoundationSnapshotService;
|
|
use App\Services\Intune\PolicySnapshotService;
|
|
use Mockery\MockInterface;
|
|
|
|
beforeEach(function () {
|
|
$this->tenant = Tenant::factory()->create(['status' => 'active']);
|
|
|
|
ensureDefaultProviderConnection($this->tenant);
|
|
|
|
$this->policy = Policy::factory()->create([
|
|
'tenant_id' => $this->tenant->id,
|
|
'policy_type' => 'deviceConfiguration',
|
|
'platform' => 'windows',
|
|
'display_name' => 'Test Policy',
|
|
]);
|
|
|
|
config()->set('tenantpilot.foundation_types', [
|
|
[
|
|
'type' => 'assignmentFilter',
|
|
'label' => 'Assignment Filter',
|
|
'category' => 'Foundations',
|
|
'platform' => 'all',
|
|
'endpoint' => 'deviceManagement/assignmentFilters',
|
|
'backup' => 'full',
|
|
'restore' => 'enabled',
|
|
'risk' => 'low',
|
|
],
|
|
]);
|
|
|
|
$this->mock(PolicySnapshotService::class, function (MockInterface $mock) {
|
|
$mock->shouldReceive('fetch')
|
|
->andReturn([
|
|
'payload' => [
|
|
'@odata.type' => '#microsoft.graph.deviceConfiguration',
|
|
'id' => 'policy-1',
|
|
'displayName' => 'Test Policy',
|
|
],
|
|
'metadata' => [],
|
|
'warnings' => [],
|
|
]);
|
|
});
|
|
|
|
$this->mock(FoundationSnapshotService::class, function (MockInterface $mock) {
|
|
$mock->shouldReceive('fetchAll')
|
|
->once()
|
|
->andReturn([
|
|
'items' => [
|
|
[
|
|
'source_id' => 'filter-1',
|
|
'display_name' => 'Filter One',
|
|
'payload' => [
|
|
'id' => 'filter-1',
|
|
'displayName' => 'Filter One',
|
|
],
|
|
'metadata' => [
|
|
'displayName' => 'Filter One',
|
|
'kind' => 'assignmentFilter',
|
|
'graph' => [
|
|
'resource' => 'deviceManagement/assignmentFilters',
|
|
'apiVersion' => 'beta',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
'failures' => [],
|
|
]);
|
|
});
|
|
});
|
|
|
|
it('creates foundation backup items when requested', function () {
|
|
$service = app(BackupService::class);
|
|
|
|
$backupSet = $service->createBackupSet(
|
|
tenant: $this->tenant,
|
|
policyIds: [$this->policy->id],
|
|
name: 'Foundation Backup',
|
|
includeFoundations: true,
|
|
);
|
|
|
|
expect($backupSet->items)->toHaveCount(2);
|
|
|
|
$foundationItem = BackupItem::query()
|
|
->where('backup_set_id', $backupSet->id)
|
|
->where('policy_type', 'assignmentFilter')
|
|
->first();
|
|
|
|
expect($foundationItem)->not->toBeNull();
|
|
expect($foundationItem->policy_id)->toBeNull();
|
|
expect($foundationItem->policy_identifier)->toBe('filter-1');
|
|
expect($foundationItem->metadata['displayName'])->toBe('Filter One');
|
|
});
|