TenantAtlas/apps/platform/database/factories/TenantConfigurationResourceEvidenceFactory.php
Ahmed Darrazi 736e61c73e
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 1m37s
feat: add generic content-backed coverage capture
2026-06-25 21:55:27 +02:00

61 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Models\OperationRun;
use App\Models\TenantConfigurationResource;
use App\Models\TenantConfigurationResourceEvidence;
use App\Support\OperationRunOutcome;
use App\Support\OperationRunStatus;
use App\Support\OperationRunType;
use App\Support\TenantConfiguration\CaptureOutcome;
use App\Support\TenantConfiguration\CoverageLevel;
use App\Support\TenantConfiguration\EvidenceState;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<TenantConfigurationResourceEvidence>
*/
class TenantConfigurationResourceEvidenceFactory extends Factory
{
protected $model = TenantConfigurationResourceEvidence::class;
public function definition(): array
{
return [
'resource_id' => TenantConfigurationResource::factory(),
'workspace_id' => fn (array $attributes): int => $this->resource($attributes)->workspace_id,
'managed_environment_id' => fn (array $attributes): int => $this->resource($attributes)->managed_environment_id,
'provider_connection_id' => fn (array $attributes): int => $this->resource($attributes)->provider_connection_id,
'resource_type_id' => fn (array $attributes): int => $this->resource($attributes)->resource_type_id,
'operation_run_id' => fn (array $attributes): int => (int) OperationRun::factory()->create([
'workspace_id' => $this->resource($attributes)->workspace_id,
'managed_environment_id' => $this->resource($attributes)->managed_environment_id,
'type' => OperationRunType::TenantConfigurationCapture->value,
'status' => OperationRunStatus::Completed->value,
'outcome' => OperationRunOutcome::Succeeded->value,
])->getKey(),
'source_contract_key' => 'assignmentFilter',
'source_endpoint' => '/deviceManagement/assignmentFilters',
'source_version' => 'v1.0',
'source_schema_hash' => null,
'source_metadata' => ['factory' => 'tenant_configuration_resource_evidence'],
'raw_payload' => ['id' => fake()->uuid()],
'normalized_payload' => ['id' => fake()->uuid()],
'payload_hash' => hash('sha256', fake()->uuid()),
'permission_context' => ['scopes_granted' => []],
'evidence_state' => EvidenceState::ContentBacked->value,
'coverage_level' => CoverageLevel::ContentBacked->value,
'capture_outcome' => CaptureOutcome::Captured->value,
'captured_at' => now(),
];
}
private function resource(array $attributes): TenantConfigurationResource
{
return TenantConfigurationResource::query()->findOrFail((int) $attributes['resource_id']);
}
}