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:
101
api/tests/Unit/FormBuilder/Bindings/ResolvedBindingTest.php
Normal file
101
api/tests/Unit/FormBuilder/Bindings/ResolvedBindingTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\FormBuilder\Bindings;
|
||||
|
||||
use App\Enums\FormBuilder\BindingTargetType;
|
||||
use App\Enums\FormBuilder\FormFieldBindingMergeStrategy;
|
||||
use App\FormBuilder\Bindings\ResolvedBinding;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ResolvedBindingTest extends TestCase
|
||||
{
|
||||
public function test_construction_with_valid_data(): void
|
||||
{
|
||||
$binding = $this->makeWith(['trustLevel' => 80]);
|
||||
$this->assertSame(80, $binding->trustLevel);
|
||||
$this->assertSame('person', $binding->targetEntity);
|
||||
}
|
||||
|
||||
public function test_trust_level_lower_bound(): void
|
||||
{
|
||||
$binding = $this->makeWith(['trustLevel' => 0]);
|
||||
$this->assertSame(0, $binding->trustLevel);
|
||||
}
|
||||
|
||||
public function test_trust_level_upper_bound(): void
|
||||
{
|
||||
$binding = $this->makeWith(['trustLevel' => 100]);
|
||||
$this->assertSame(100, $binding->trustLevel);
|
||||
}
|
||||
|
||||
public function test_trust_level_below_zero_throws(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->makeWith(['trustLevel' => -1]);
|
||||
}
|
||||
|
||||
public function test_trust_level_above_hundred_throws(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->makeWith(['trustLevel' => 101]);
|
||||
}
|
||||
|
||||
public function test_empty_target_entity_throws(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->makeWith(['targetEntity' => '']);
|
||||
}
|
||||
|
||||
public function test_empty_target_attribute_throws(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->makeWith(['targetAttribute' => '']);
|
||||
}
|
||||
|
||||
public function test_null_value_preserved_with_explicit_flag(): void
|
||||
{
|
||||
$binding = $this->makeWith([
|
||||
'value' => null,
|
||||
'valueIsExplicit' => true,
|
||||
]);
|
||||
$this->assertNull($binding->value);
|
||||
$this->assertTrue($binding->valueIsExplicit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $overrides
|
||||
*/
|
||||
private function makeWith(array $overrides): ResolvedBinding
|
||||
{
|
||||
$defaults = [
|
||||
'sourceFormFieldId' => '01jq1k1k1k1k1k1k1k1k1k1k1k',
|
||||
'bindingId' => '01jq1k1k1k1k1k1k1k1k1k1k1l',
|
||||
'targetEntity' => 'person',
|
||||
'targetAttribute' => 'email',
|
||||
'targetType' => BindingTargetType::SCALAR,
|
||||
'mergeStrategy' => FormFieldBindingMergeStrategy::Overwrite,
|
||||
'trustLevel' => 50,
|
||||
'isIdentityKey' => false,
|
||||
'value' => 'jan@example.nl',
|
||||
'valueIsExplicit' => true,
|
||||
];
|
||||
|
||||
$args = array_merge($defaults, $overrides);
|
||||
|
||||
return new ResolvedBinding(
|
||||
sourceFormFieldId: $args['sourceFormFieldId'],
|
||||
bindingId: $args['bindingId'],
|
||||
targetEntity: $args['targetEntity'],
|
||||
targetAttribute: $args['targetAttribute'],
|
||||
targetType: $args['targetType'],
|
||||
mergeStrategy: $args['mergeStrategy'],
|
||||
trustLevel: $args['trustLevel'],
|
||||
isIdentityKey: $args['isIdentityKey'],
|
||||
value: $args['value'],
|
||||
valueIsExplicit: $args['valueIsExplicit'],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user