create(); $schema = FormSchema::factory()->create([ 'organisation_id' => $org->id, 'submission_mode' => FormSubmissionMode::SINGLE, 'snapshot_mode' => FormSchemaSnapshotMode::ON_SUBMIT, ]); $field = FormField::factory()->create([ 'form_schema_id' => $schema->id, 'field_type' => FormFieldType::TEXT->value, 'slug' => 'voornaam', ]); FormFieldValidationRule::factory()->forField($field) ->ofType(FormFieldValidationRuleType::MinLength, ['value' => 2])->create(); FormFieldValidationRule::factory()->forField($field) ->ofType(FormFieldValidationRuleType::MaxLength, ['value' => 40])->create(); $service = app(FormSubmissionService::class); $snapshot = $this->invokeBuildSnapshot($service, $schema); $fieldEntry = collect($snapshot['fields'])->firstWhere('slug', 'voornaam'); $this->assertNotNull($fieldEntry); $this->assertSame([ 'min_length' => 2, 'max_length' => 40, ], $fieldEntry['validation_rules']); } public function test_snapshot_validation_rules_null_when_no_rules(): void { $org = Organisation::factory()->create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); FormField::factory()->create([ 'form_schema_id' => $schema->id, 'slug' => 'noot', ]); $service = app(FormSubmissionService::class); $snapshot = $this->invokeBuildSnapshot($service, $schema); $entry = collect($snapshot['fields'])->firstWhere('slug', 'noot'); $this->assertNull($entry['validation_rules']); } /** @return array */ private function invokeBuildSnapshot(FormSubmissionService $service, FormSchema $schema): array { $ref = new \ReflectionMethod($service, 'buildSnapshot'); $ref->setAccessible(true); return $ref->invoke($service, $schema); } }