- 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>
52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\FormBuilder\Bindings;
|
|
|
|
use App\FormBuilder\Bindings\BindingApplicationResult;
|
|
use PHPUnit\Framework\TestCase;
|
|
use RuntimeException;
|
|
|
|
final class BindingApplicationResultTest extends TestCase
|
|
{
|
|
public function test_succeeded_constructor_populates_state_correctly(): void
|
|
{
|
|
$result = BindingApplicationResult::succeeded(
|
|
bindingId: 'bnd-1',
|
|
targetEntity: 'person',
|
|
targetAttribute: 'email',
|
|
oldValue: null,
|
|
newValue: 'jan@example.nl',
|
|
);
|
|
|
|
$this->assertTrue($result->success);
|
|
$this->assertSame('bnd-1', $result->bindingId);
|
|
$this->assertSame('person', $result->targetEntity);
|
|
$this->assertSame('email', $result->targetAttribute);
|
|
$this->assertNull($result->oldValue);
|
|
$this->assertSame('jan@example.nl', $result->newValue);
|
|
$this->assertNull($result->exceptionClass);
|
|
$this->assertNull($result->exceptionMessage);
|
|
}
|
|
|
|
public function test_failed_constructor_captures_exception_metadata(): void
|
|
{
|
|
$exception = new RuntimeException('boom');
|
|
|
|
$result = BindingApplicationResult::failed(
|
|
bindingId: 'bnd-2',
|
|
targetEntity: 'company',
|
|
targetAttribute: 'name',
|
|
e: $exception,
|
|
);
|
|
|
|
$this->assertFalse($result->success);
|
|
$this->assertSame('bnd-2', $result->bindingId);
|
|
$this->assertNull($result->oldValue);
|
|
$this->assertNull($result->newValue);
|
|
$this->assertSame(RuntimeException::class, $result->exceptionClass);
|
|
$this->assertSame('boom', $result->exceptionMessage);
|
|
}
|
|
}
|