feat(form-builder): MergeStrategy enum methods + binding value objects (WS-6)
- FormFieldBindingMergeStrategy::nullWinnerBehaviour() and isValidForScalarTargets() encode the per-strategy null-winner matrix (RFC Q7) and the collection-only restriction (RFC V1). - ResolvedBinding/BindingApplicationResult/BindingPassResult readonly DTOs for the binding pipeline. Construction-time validation for trust level. Apply-status derived from result aggregate. Note: the existing enum is named FormFieldBindingMergeStrategy (not MergeStrategy as the prompt sketched). Methods added to it directly. Refs: RFC-WS-6.md §3 (Q4, Q7), §4 (V1) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\FormBuilder\Bindings;
|
||||
|
||||
use App\Enums\FormBuilder\ApplyStatus;
|
||||
use App\FormBuilder\Bindings\BindingApplicationResult;
|
||||
use App\FormBuilder\Bindings\BindingPassResult;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
final class BindingPassResultTest extends TestCase
|
||||
{
|
||||
public function test_empty_applications_yield_completed(): void
|
||||
{
|
||||
$result = $this->make([]);
|
||||
$this->assertSame(ApplyStatus::COMPLETED, $result->applyStatus());
|
||||
$this->assertSame(0, $result->successCount());
|
||||
$this->assertSame(0, $result->failureCount());
|
||||
}
|
||||
|
||||
public function test_all_succeeded_yields_completed(): void
|
||||
{
|
||||
$result = $this->make([$this->success('a'), $this->success('b')]);
|
||||
$this->assertSame(ApplyStatus::COMPLETED, $result->applyStatus());
|
||||
$this->assertSame(2, $result->successCount());
|
||||
$this->assertSame(0, $result->failureCount());
|
||||
$this->assertSame([], $result->failures());
|
||||
}
|
||||
|
||||
public function test_all_failed_yields_failed(): void
|
||||
{
|
||||
$result = $this->make([$this->failure('a'), $this->failure('b')]);
|
||||
$this->assertSame(ApplyStatus::FAILED, $result->applyStatus());
|
||||
$this->assertSame(0, $result->successCount());
|
||||
$this->assertSame(2, $result->failureCount());
|
||||
$this->assertCount(2, $result->failures());
|
||||
}
|
||||
|
||||
public function test_mixed_yields_partial(): void
|
||||
{
|
||||
$result = $this->make([
|
||||
$this->success('a'),
|
||||
$this->failure('b'),
|
||||
$this->success('c'),
|
||||
]);
|
||||
$this->assertSame(ApplyStatus::PARTIAL, $result->applyStatus());
|
||||
$this->assertSame(2, $result->successCount());
|
||||
$this->assertSame(1, $result->failureCount());
|
||||
$this->assertCount(1, $result->failures());
|
||||
$this->assertSame('b', $result->failures()[0]->bindingId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<BindingApplicationResult> $applications
|
||||
*/
|
||||
private function make(array $applications): BindingPassResult
|
||||
{
|
||||
return new BindingPassResult(
|
||||
formSubmissionId: 'fs-1',
|
||||
provisionedSubjectType: 'person',
|
||||
provisionedSubjectId: 'p-1',
|
||||
applications: $applications,
|
||||
);
|
||||
}
|
||||
|
||||
private function success(string $bindingId): BindingApplicationResult
|
||||
{
|
||||
return BindingApplicationResult::succeeded(
|
||||
bindingId: $bindingId,
|
||||
targetEntity: 'person',
|
||||
targetAttribute: 'email',
|
||||
oldValue: null,
|
||||
newValue: 'x@y.z',
|
||||
);
|
||||
}
|
||||
|
||||
private function failure(string $bindingId): BindingApplicationResult
|
||||
{
|
||||
return BindingApplicationResult::failed(
|
||||
bindingId: $bindingId,
|
||||
targetEntity: 'person',
|
||||
targetAttribute: 'email',
|
||||
e: new RuntimeException('boom'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user