refactor(form-builder): align binding registry with model column reality (WS-6)
Three renames (registry → matches actual Eloquent model column):
- person.phone_number → person.phone
- company.email → company.contact_email
- company.phone_number → company.contact_phone
Six removals (registry attribute does not exist as model column,
intentionally deferred):
- person.dietary_preferences (custom_fields JSON path; BACKLOG
FORM-BINDING-JSON-PATH)
- artist.email (Artist model absent + column absent)
- artist.stage_name (column absent)
- artist.tech_rider (column absent)
- artist.hospitality_rider (column absent)
- artist entity removed entirely (no v1 bindable attributes)
Decisions documented inline in binding_targets.php and tracked
via BACKLOG entries (Task 4 of this session).
Tests touched:
- BindingTypeRegistryTest:
test_resolve_person_dietary_preferences_returns_collection_array →
renamed test_resolve_collection_attribute_returns_collection_array,
uses Config::set to inject a synthetic 'test_entity.tags' collection
target. v1 has no production collection targets (BACKLOG
FORM-BINDING-JSON-PATH).
test_validate_append_strategy_accepts_collection_target — same pattern.
test_entities_returns_known_entities — drop 'artist' from expected list.
test_attributes_for_person_includes_email_and_dietary_preferences →
renamed _includes_email_and_phone (the renamed attribute).
- AppendStrategyRequiresCollectionTargetTest:
test_passes_with_collection_target — same Config::set synthetic-
target pattern.
- MaxOneIdentityKeyPerTargetEntityTest:
test_passes_with_one_identity_key_each_on_different_entities —
'company.email' → 'company.contact_email' to match registry rename.
Refs: WS-6 sessie 3a binding-target drift audit
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
/**
|
||||
* RFC-WS-6 §4 (V1) — single source of truth for binding-target storage
|
||||
* shape. Consulted by `BindingTypeRegistry`, `AppendStrategyRequiresCollectionTarget`
|
||||
* publish guard, and (in session 2) by `FormBindingApplicator`.
|
||||
* publish guard, and `FormBindingApplicator`.
|
||||
*
|
||||
* `type` values:
|
||||
* - 'scalar' — single column (string/int/datetime/email/...)
|
||||
@@ -19,6 +19,27 @@ declare(strict_types=1);
|
||||
* `identity_key_eligible` permits a binding to set `is_identity_key=true`
|
||||
* on this attribute. PurposeGuardProvider's RequiresIdentityKeyBinding
|
||||
* may only target attributes that are eligible.
|
||||
*
|
||||
* Every entry MUST map 1:1 to a real Eloquent model column on the
|
||||
* corresponding entity model — enforced by
|
||||
* BindingTypeRegistryConsistencyTest's model-existence + column-existence
|
||||
* assertions (sessie 3a.5).
|
||||
*
|
||||
* Intentional gaps (Crewli v1):
|
||||
*
|
||||
* - 'artist' entity has NO registry entries in v1. The artist_advance
|
||||
* purpose accepts schemas without bindings (subject is resolved via
|
||||
* portal_token, not via field-to-attribute mapping). The Artist
|
||||
* Eloquent model class does not exist; the artists table is reachable
|
||||
* only via the morph map. Tracked: BACKLOG ARTIST-ADV-BINDING-MODEL.
|
||||
*
|
||||
* - person.dietary_preferences is NOT in the registry. Person-level
|
||||
* dietary preferences live inside the persons.custom_fields JSON
|
||||
* column. JSON-path bindings are out of scope for v1 binding pipeline.
|
||||
* For v1, model dietary_preferences as a TAG_PICKER form_field with
|
||||
* tag_categories config; see ARCH-FORM-BUILDER §31.10 for the
|
||||
* TAG_PICKER → user_organisation_tags sync path.
|
||||
* Tracked: BACKLOG FORM-BINDING-JSON-PATH.
|
||||
*/
|
||||
return [
|
||||
'person' => [
|
||||
@@ -26,20 +47,13 @@ return [
|
||||
'first_name' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
'last_name' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
'date_of_birth' => ['type' => 'scalar', 'php' => 'date', 'identity_key_eligible' => false],
|
||||
'phone_number' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
'dietary_preferences' => ['type' => 'collection', 'php' => 'array', 'identity_key_eligible' => false],
|
||||
],
|
||||
'artist' => [
|
||||
'email' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => true],
|
||||
'stage_name' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
'tech_rider' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
'hospitality_rider' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
'phone' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
],
|
||||
'company' => [
|
||||
'name' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => true],
|
||||
'email' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => true],
|
||||
'contact_email' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => true],
|
||||
'contact_phone' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
'kvk_number' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => true],
|
||||
'phone_number' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => false],
|
||||
],
|
||||
'user' => [
|
||||
'email' => ['type' => 'scalar', 'php' => 'string', 'identity_key_eligible' => true],
|
||||
|
||||
@@ -22,9 +22,22 @@ final class BindingTypeRegistryTest extends TestCase
|
||||
$this->assertTrue($meta->identityKeyEligible);
|
||||
}
|
||||
|
||||
public function test_resolve_person_dietary_preferences_returns_collection_array(): void
|
||||
public function test_resolve_collection_attribute_returns_collection_array(): void
|
||||
{
|
||||
$meta = $this->registry()->resolve('person', 'dietary_preferences');
|
||||
// Sessie 3a.5: v1 registry has no collection targets after the
|
||||
// model-alignment cleanup (person.dietary_preferences was the only
|
||||
// one, and it's deferred to BACKLOG FORM-BINDING-JSON-PATH).
|
||||
// Inject a synthetic collection target via Config::set so the
|
||||
// registry's collection-handling behaviour stays under test
|
||||
// without depending on a live model column. Cache is bypassed
|
||||
// because we resolve a fresh registry instance.
|
||||
config()->set('form_builder.binding_targets.test_entity', [
|
||||
'tags' => ['type' => 'collection', 'php' => 'array', 'identity_key_eligible' => false],
|
||||
]);
|
||||
|
||||
$meta = (new \App\FormBuilder\Bindings\BindingTypeRegistry(
|
||||
config: $this->app->make(\Illuminate\Contracts\Config\Repository::class),
|
||||
))->resolve('test_entity', 'tags');
|
||||
|
||||
$this->assertSame(BindingTargetType::COLLECTION, $meta->type);
|
||||
$this->assertSame('array', $meta->php);
|
||||
@@ -57,9 +70,16 @@ final class BindingTypeRegistryTest extends TestCase
|
||||
|
||||
public function test_validate_append_strategy_accepts_collection_target(): void
|
||||
{
|
||||
$this->registry()->validateAppendStrategy(
|
||||
'person',
|
||||
'dietary_preferences',
|
||||
// Sessie 3a.5: synthetic collection target — see test above.
|
||||
config()->set('form_builder.binding_targets.test_entity', [
|
||||
'tags' => ['type' => 'collection', 'php' => 'array', 'identity_key_eligible' => false],
|
||||
]);
|
||||
|
||||
(new \App\FormBuilder\Bindings\BindingTypeRegistry(
|
||||
config: $this->app->make(\Illuminate\Contracts\Config\Repository::class),
|
||||
))->validateAppendStrategy(
|
||||
'test_entity',
|
||||
'tags',
|
||||
FormFieldBindingMergeStrategy::Append,
|
||||
);
|
||||
|
||||
@@ -79,16 +99,18 @@ final class BindingTypeRegistryTest extends TestCase
|
||||
|
||||
public function test_entities_returns_known_entities(): void
|
||||
{
|
||||
// Sessie 3a.5: 'artist' is intentionally absent from v1 registry
|
||||
// (BACKLOG ARTIST-ADV-BINDING-MODEL).
|
||||
$entities = $this->registry()->entities();
|
||||
sort($entities);
|
||||
$this->assertSame(['artist', 'company', 'person', 'user'], $entities);
|
||||
$this->assertSame(['company', 'person', 'user'], $entities);
|
||||
}
|
||||
|
||||
public function test_attributes_for_person_includes_email_and_dietary_preferences(): void
|
||||
public function test_attributes_for_person_includes_email_and_phone(): void
|
||||
{
|
||||
$attributes = $this->registry()->attributesFor('person');
|
||||
$this->assertContains('email', $attributes);
|
||||
$this->assertContains('dietary_preferences', $attributes);
|
||||
$this->assertContains('phone', $attributes);
|
||||
}
|
||||
|
||||
public function test_attributes_for_unknown_entity_returns_empty_list(): void
|
||||
|
||||
@@ -46,9 +46,17 @@ final class AppendStrategyRequiresCollectionTargetTest extends TestCase
|
||||
|
||||
public function test_passes_with_collection_target(): void
|
||||
{
|
||||
// Sessie 3a.5: v1 registry has no collection targets in any
|
||||
// production entity. Inject a synthetic collection target via
|
||||
// Config::set so the guard's collection-allowed branch stays
|
||||
// under test. Tracked: BACKLOG FORM-BINDING-JSON-PATH.
|
||||
config()->set('form_builder.binding_targets.test_entity', [
|
||||
'tags' => ['type' => 'collection', 'php' => 'array', 'identity_key_eligible' => false],
|
||||
]);
|
||||
|
||||
$schema = FormSchema::factory()->create();
|
||||
$field = FormField::factory()->create(['form_schema_id' => $schema->id]);
|
||||
FormFieldBinding::factory()->forField($field)->entityOwned('person', 'dietary_preferences')->create([
|
||||
FormFieldBinding::factory()->forField($field)->entityOwned('test_entity', 'tags')->create([
|
||||
'merge_strategy' => FormFieldBindingMergeStrategy::Append->value,
|
||||
]);
|
||||
$schema->load('fields.bindings');
|
||||
|
||||
@@ -21,7 +21,7 @@ final class MaxOneIdentityKeyPerTargetEntityTest extends TestCase
|
||||
FormField::factory()->create(['form_schema_id' => $schema->id]);
|
||||
$schema->load('fields.bindings');
|
||||
|
||||
$result = (new MaxOneIdentityKeyPerTargetEntity())->evaluate($schema);
|
||||
$result = (new MaxOneIdentityKeyPerTargetEntity)->evaluate($schema);
|
||||
$this->assertTrue($result->passed);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ final class MaxOneIdentityKeyPerTargetEntityTest extends TestCase
|
||||
->create(['is_identity_key' => true]);
|
||||
$schema->load('fields.bindings');
|
||||
|
||||
$result = (new MaxOneIdentityKeyPerTargetEntity())->evaluate($schema);
|
||||
$result = (new MaxOneIdentityKeyPerTargetEntity)->evaluate($schema);
|
||||
$this->assertTrue($result->passed);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ final class MaxOneIdentityKeyPerTargetEntityTest extends TestCase
|
||||
->create(['is_identity_key' => true]);
|
||||
$schema->load('fields.bindings');
|
||||
|
||||
$result = (new MaxOneIdentityKeyPerTargetEntity())->evaluate($schema);
|
||||
$result = (new MaxOneIdentityKeyPerTargetEntity)->evaluate($schema);
|
||||
$this->assertFalse($result->passed);
|
||||
$this->assertSame('person', $result->context['entity']);
|
||||
}
|
||||
@@ -60,11 +60,11 @@ final class MaxOneIdentityKeyPerTargetEntityTest extends TestCase
|
||||
$f2 = FormField::factory()->create(['form_schema_id' => $schema->id]);
|
||||
FormFieldBinding::factory()->forField($f1)->entityOwned('person', 'email')
|
||||
->create(['is_identity_key' => true]);
|
||||
FormFieldBinding::factory()->forField($f2)->entityOwned('company', 'email')
|
||||
FormFieldBinding::factory()->forField($f2)->entityOwned('company', 'contact_email')
|
||||
->create(['is_identity_key' => true]);
|
||||
$schema->load('fields.bindings');
|
||||
|
||||
$result = (new MaxOneIdentityKeyPerTargetEntity())->evaluate($schema);
|
||||
$result = (new MaxOneIdentityKeyPerTargetEntity)->evaluate($schema);
|
||||
$this->assertTrue($result->passed);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user