{
"tool_response": {
"type": "update",
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/tests\/Integration\/Taxonomy\/TaxonomyIntegrationTest.php",
"content": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Integration\\Taxonomy;\n\n\/\/ @responsibility: Integration-Tests für Taxonomie-Mapping Pipeline\n\nuse Domain\\Entity\\ChunkTaxonomyMapping;\nuse Domain\\Entity\\EntityTaxonomyMapping;\nuse Domain\\ValueObject\\Confidence;\nuse Domain\\ValueObject\\MappingSource;\nuse PHPUnit\\Framework\\TestCase;\n\n\/**\n * Integration tests for Taxonomy Mapping Pipeline.\n *\n * Tests cover:\n * - ChunkTaxonomyMapping entity creation and serialization\n * - EntityTaxonomyMapping entity creation and validation\n * - Value objects (Confidence, MappingSource)\n * - Data integrity across mapping lifecycle\n *\/\nclass TaxonomyIntegrationTest extends TestCase\n{\n \/\/ =========================================================================\n \/\/ ChunkTaxonomyMapping Tests\n \/\/ =========================================================================\n\n public function testChunkTaxonomyMappingCreation(): void\n {\n $mapping = new ChunkTaxonomyMapping();\n $mapping->setChunkId(42);\n $mapping->setTaxonomyTermId(7);\n $mapping->setConfidence(Confidence::fromFloat(0.85));\n $mapping->setSource(MappingSource::AUTO);\n\n $this->assertNull($mapping->getId());\n $this->assertSame(42, $mapping->getChunkId());\n $this->assertSame(7, $mapping->getTaxonomyTermId());\n $this->assertSame(0.85, $mapping->getConfidence()->value());\n $this->assertSame('auto', $mapping->getSource()->value);\n $this->assertInstanceOf(\\DateTimeImmutable::class, $mapping->getCreatedAt());\n }\n\n public function testChunkTaxonomyMappingToArray(): void\n {\n $mapping = new ChunkTaxonomyMapping();\n $mapping->setId(1);\n $mapping->setChunkId(100);\n $mapping->setTaxonomyTermId(5);\n $mapping->setConfidence(Confidence::fromFloat(0.9));\n $mapping->setSource(MappingSource::MANUAL);\n\n $array = $mapping->toArray();\n\n $this->assertSame(1, $array['id']);\n $this->assertSame(100, $array['chunk_id']);\n $this->assertSame(5, $array['taxonomy_term_id']);\n $this->assertSame(0.9, $array['confidence']);\n $this->assertSame('manual', $array['source']);\n $this->assertArrayHasKey('created_at', $array);\n }\n\n public function testChunkTaxonomyMappingFromArray(): void\n {\n $data = [\n 'id' => 99,\n 'chunk_id' => 200,\n 'taxonomy_term_id' => 15,\n 'confidence' => 0.75,\n 'source' => 'auto',\n 'created_at' => '2025-01-01 12:00:00',\n ];\n\n $mapping = ChunkTaxonomyMapping::fromArray($data);\n\n $this->assertSame(99, $mapping->getId());\n $this->assertSame(200, $mapping->getChunkId());\n $this->assertSame(15, $mapping->getTaxonomyTermId());\n $this->assertSame(0.75, $mapping->getConfidence()->value());\n $this->assertSame('auto', $mapping->getSource()->value);\n }\n\n public function testChunkTaxonomyMappingRoundTrip(): void\n {\n $original = new ChunkTaxonomyMapping();\n $original->setId(42);\n $original->setChunkId(500);\n $original->setTaxonomyTermId(25);\n $original->setConfidence(Confidence::high());\n $original->setSource(MappingSource::MANUAL);\n\n $array = $original->toArray();\n $restored = ChunkTaxonomyMapping::fromArray($array);\n\n $this->assertSame($original->getId(), $restored->getId());\n $this->assertSame($original->getChunkId(), $restored->getChunkId());\n $this->assertSame($original->getTaxonomyTermId(), $restored->getTaxonomyTermId());\n $this->assertSame($original->getConfidence()->value(), $restored->getConfidence()->value());\n $this->assertSame($original->getSource()->value, $restored->getSource()->value);\n }\n\n public function testChunkTaxonomyMappingDefaultValues(): void\n {\n $mapping = new ChunkTaxonomyMapping();\n $mapping->setChunkId(1);\n $mapping->setTaxonomyTermId(1);\n\n \/\/ Default values from constructor\n $this->assertSame(0.7, $mapping->getConfidence()->value()); \/\/ medium()\n $this->assertSame('auto', $mapping->getSource()->value);\n }\n\n \/\/ =========================================================================\n \/\/ EntityTaxonomyMapping Tests\n \/\/ =========================================================================\n\n public function testEntityTaxonomyMappingCreation(): void\n {\n $mapping = new EntityTaxonomyMapping();\n $mapping->setEntityId(10);\n $mapping->setTaxonomyTermId(3);\n $mapping->setRelevance(Confidence::fromFloat(0.8));\n\n $this->assertNull($mapping->getId());\n $this->assertSame(10, $mapping->getEntityId());\n $this->assertSame(3, $mapping->getTaxonomyTermId());\n $this->assertSame(0.8, $mapping->getRelevance()->value());\n $this->assertFalse($mapping->isValidated());\n }\n\n public function testEntityTaxonomyMappingValidation(): void\n {\n $mapping = new EntityTaxonomyMapping();\n $mapping->setEntityId(5);\n $mapping->setTaxonomyTermId(2);\n\n $this->assertFalse($mapping->isValidated());\n\n $mapping->validate();\n $this->assertTrue($mapping->isValidated());\n $this->assertNotNull($mapping->getUpdatedAt());\n\n $mapping->invalidate();\n $this->assertFalse($mapping->isValidated());\n }\n\n public function testEntityTaxonomyMappingToArray(): void\n {\n $mapping = new EntityTaxonomyMapping();\n $mapping->setId(50);\n $mapping->setEntityId(100);\n $mapping->setTaxonomyTermId(20);\n $mapping->setRelevance(Confidence::medium());\n $mapping->validate();\n\n $array = $mapping->toArray();\n\n $this->assertSame(50, $array['id']);\n $this->assertSame(100, $array['entity_id']);\n $this->assertSame(20, $array['taxonomy_term_id']);\n $this->assertSame(0.7, $array['relevance']); \/\/ medium() = 0.7\n $this->assertSame(1, $array['validated']);\n }\n\n public function testEntityTaxonomyMappingFromArray(): void\n {\n $data = [\n 'id' => 77,\n 'entity_id' => 300,\n 'taxonomy_term_id' => 30,\n 'relevance' => 0.65,\n 'validated' => true,\n 'created_at' => '2025-06-15 10:30:00',\n 'updated_at' => '2025-06-15 11:00:00',\n ];\n\n $mapping = EntityTaxonomyMapping::fromArray($data);\n\n $this->assertSame(77, $mapping->getId());\n $this->assertSame(300, $mapping->getEntityId());\n $this->assertSame(30, $mapping->getTaxonomyTermId());\n $this->assertSame(0.65, $mapping->getRelevance()->value());\n $this->assertTrue($mapping->isValidated());\n $this->assertNotNull($mapping->getUpdatedAt());\n }\n\n public function testEntityTaxonomyMappingDefaultRelevance(): void\n {\n $mapping = new EntityTaxonomyMapping();\n $mapping->setEntityId(1);\n $mapping->setTaxonomyTermId(1);\n\n \/\/ Default relevance is medium (0.7)\n $this->assertSame(0.7, $mapping->getRelevance()->value());\n }\n\n \/\/ =========================================================================\n \/\/ Confidence Value Object Tests\n \/\/ =========================================================================\n\n public function testConfidenceFromFloat(): void\n {\n $confidence = Confidence::fromFloat(0.75);\n $this->assertSame(0.75, $confidence->value());\n }\n\n public function testConfidenceFactoryMethods(): void\n {\n $this->assertSame(0.9, Confidence::high()->value());\n $this->assertSame(0.7, Confidence::medium()->value());\n $this->assertSame(0.5, Confidence::low()->value());\n }\n\n public function testConfidenceBoundaries(): void\n {\n $zero = Confidence::fromFloat(0.0);\n $one = Confidence::fromFloat(1.0);\n\n $this->assertSame(0.0, $zero->value());\n $this->assertSame(1.0, $one->value());\n }\n\n public function testConfidenceInvalidValueTooLow(): void\n {\n $this->expectException(\\InvalidArgumentException::class);\n Confidence::fromFloat(-0.1);\n }\n\n public function testConfidenceInvalidValueTooHigh(): void\n {\n $this->expectException(\\InvalidArgumentException::class);\n Confidence::fromFloat(1.1);\n }\n\n public function testConfidenceIsHighMediumLow(): void\n {\n $high = Confidence::fromFloat(0.85);\n $medium = Confidence::fromFloat(0.6);\n $low = Confidence::fromFloat(0.3);\n\n $this->assertTrue($high->isHigh());\n $this->assertFalse($high->isMedium());\n $this->assertFalse($high->isLow());\n\n $this->assertFalse($medium->isHigh());\n $this->assertTrue($medium->isMedium());\n $this->assertFalse($medium->isLow());\n\n $this->assertFalse($low->isHigh());\n $this->assertFalse($low->isMedium());\n $this->assertTrue($low->isLow());\n }\n\n public function testConfidenceAsPercentage(): void\n {\n $confidence = Confidence::fromFloat(0.75);\n $this->assertSame(75, $confidence->asPercentage());\n }\n\n \/\/ =========================================================================\n \/\/ MappingSource Value Object Tests\n \/\/ =========================================================================\n\n public function testMappingSourceValues(): void\n {\n $this->assertSame('auto', MappingSource::AUTO->value);\n $this->assertSame('manual', MappingSource::MANUAL->value);\n }\n\n public function testMappingSourceFrom(): void\n {\n $auto = MappingSource::from('auto');\n $manual = MappingSource::from('manual');\n\n $this->assertSame(MappingSource::AUTO, $auto);\n $this->assertSame(MappingSource::MANUAL, $manual);\n }\n\n public function testMappingSourceTryFrom(): void\n {\n $valid = MappingSource::tryFrom('auto');\n $invalid = MappingSource::tryFrom('invalid_source');\n\n $this->as... [TRUNCATED-9c9122431a91caa5]",
"structuredPatch": [
{
"oldStart": 69,
"oldLines": 7,
"newStart": 69,
"newLines": 7,
"lines": [
" 'chunk_id' => 200,",
" 'taxonomy_term_id' => 15,",
" 'confidence' => 0.75,",
"- 'source' => 'pipeline',",
"+ 'source' => 'auto',",
" 'created_at' => '2025-01-01 12:00:00',",
" ];",
" "
]
},
{
"oldStart": 79,
"oldLines": 7,
"newStart": 79,
"newLines": 7,
"lines": [
" $this->assertSame(200, $mapping->getChunkId());",
" $this->assertSame(15, $mapping->getTaxonomyTermId());",
" $this->assertSame(0.75, $mapping->getConfidence()->value());",
"- $this->assertSame('pipeline', $mapping->getSource()->value);",
"+ $this->assertSame('auto', $mapping->getSource()->value);",
" }",
" ",
" public function testChunkTaxonomyMappingRoundTrip(): void"
]
},
{
"oldStart": 89,
"oldLines": 7,
"newStart": 89,
"newLines": 7,
"lines": [
" $original->setChunkId(500);",
" $original->setTaxonomyTermId(25);",
" $original->setConfidence(Confidence::high());",
"- $original->setSource(MappingSource::IMPORT);",
"+ $original->setSource(MappingSource::MANUAL);",
" ",
" $array = $original->toArray();",
" $restored = ChunkTaxonomyMapping::fromArray($array);"
]
},
{
"oldStart": 101,
"oldLines": 6,
"newStart": 101,
"newLines": 17,
"lines": [
" $this->assertSame($original->getSource()->value, $restored->getSource()->value);",
" }",
" ",
"+ public function testChunkTaxonomyMappingDefaultValues(): void",
"+ {",
"+ $mapping = new ChunkTaxonomyMapping();",
"+ $mapping->setChunkId(1);",
"+ $mapping->setTaxonomyTermId(1);",
"+",
"+ \/\/ Default values from constructor",
"+ $this->assertSame(0.7, $mapping->getConfidence()->value()); \/\/ medium()",
"+ $this->assertSame('auto', $mapping->getSource()->value);",
"+ }",
"+",
" \/\/ =========================================================================",
" \/\/ EntityTaxonomyMapping Tests",
" \/\/ ========================================================================="
]
},
{
"oldStart": 149,
"oldLines": 7,
"newStart": 160,
"newLines": 7,
"lines": [
" $this->assertSame(50, $array['id']);",
" $this->assertSame(100, $array['entity_id']);",
" $this->assertSame(20, $array['taxonomy_term_id']);",
"- $this->assertSame(0.5, $array['relevance']);",
"+ $this->assertSame(0.7, $array['relevance']); \/\/ medium() = 0.7",
" $this->assertSame(1, $array['validated']);",
" }",
" "
]
},
{
"oldStart": 175,
"oldLines": 6,
"newStart": 186,
"newLines": 16,
"lines": [
" $this->assertNotNull($mapping->getUpdatedAt());",
" }",
" ",
"+ public function testEntityTaxonomyMappingDefaultRelevance(): void",
"+ {",
"+ $mapping = new EntityTaxonomyMapping();",
"+ $mapping->setEntityId(1);",
"+ $mapping->setTaxonomyTermId(1);",
"+",
"+ \/\/ Default relevance is medium (0.7)",
"+ $this->assertSame(0.7, $mapping->getRelevance()->value());",
"+ }",
"+",
" \/\/ =========================================================================",
" \/\/ Confidence Value Object Tests",
" \/\/ ========================================================================="
]
},
{
"oldStart": 188,
"oldLines": 8,
"newStart": 209,
"newLines": 8,
"lines": [
" public function testConfidenceFactoryMethods(): void",
" {",
" $this->assertSame(0.9, Confidence::high()->value());",
"- $this->assertSame(0.5, Confidence::medium()->value());",
"- $this->assertSame(0.3, Confidence::low()->value());",
"+ $this->assertSame(0.7, Confidence::medium()->value());",
"+ $this->assertSame(0.5, Confidence::low()->value());",
" }",
" ",
" public function testConfidenceBoundaries(): void"
]
},
{
"oldStart": 213,
"oldLines": 6,
"newStart": 234,
"newLines": 31,
"lines": [
" Confidence::fromFloat(1.1);",
" }",
" ",
"+ public function testConfidenceIsHighMediumLow(): void",
"+ {",
"+ $high = Confidence::fromFloat(0.85);",
"+ $medium = Confidence::fromFloat(0.6);",
"+ $low = Confidence::fromFloat(0.3);",
"+",
"+ $this->assertTrue($high->isHigh());",
"+ $this->assertFalse($high->isMedium());",
"+ $this->assertFalse($high->isLow());",
"+",
"+ $this->assertFalse($medium->isHigh());",
"+ $this->assertTrue($medium->isMedium());",
"+ $this->assertFalse($medium->isLow());",
"+",
"+ $this->assertFalse($low->isHigh());",
"+ $this->assertFalse($low->isMedium());",
"+ $this->assertTrue($low->isLow());",
"+ }",
"+",
"+ public function testConfidenceAsPercentage(): void",
"+ {",
"+ $confidence = Confidence::fromFloat(0.75);",
"+ $this->assertSame(75, $confidence->asPercentage());",
"+ }",
"+",
" \/\/ =========================================================================",
" \/\/ MappingSource Value Object Tests",
" \/\/ ========================================================================="
]
},
{
"oldStart": 221,
"oldLines": 8,
"newStart": 267,
"newLines": 6,
"lines": [
" {",
" $this->assertSame('auto', MappingSource::AUTO->value);",
" $this->assertSame('manual', MappingSource::MANUAL->value);",
"- $this->assertSame('pipeline', MappingSource::PIPELINE->value);",
"- $this->assertSame('import', MappingSource::IMPORT->value);",
" }",
" ",
" public function testMappingSourceFrom(): void"
]
},
{
"oldStart": 236,
"oldLines": 39,
"newStart": 280,
"newLines": 49,
"lines": [
" ",
" public function testMappingSourceTryFrom(): void",
" {",
"- $valid = MappingSource::tryFrom('pipeline');",
"+ $valid = MappingSource::tryFrom('auto');",
" $invalid = MappingSource::tryFrom('invalid_source');",
" ",
"- $this->assertSame(MappingSource::PIPELINE, $valid);",
"+ $this->assertSame(MappingSource::AUTO, $valid);",
" $this->assertNull($invalid);",
" }",
" ",
"+ public function testMappingSourceIsAutomatic(): void",
"+ {",
"+ $this->assertTrue(MappingSource::AUTO->isAutomatic());",
"+ $this->assertFalse(MappingSource::MANUAL->isAutomatic());",
"+ }",
"+",
"+ public function testMappingSourceIsManual(): void",
"+ {",
"+ $this->assertFalse(MappingSource::AUTO->isManual());",
"+ $this->assertTrue(MappingSource::MANUAL->isManual());",
"+ }",
"+",
"+ public function testMappingSourceLabel(): void",
"+ {",
"+ $this->assertSame('Automatisch', MappingSource::AUTO->label());",
"+ $this->assertSame('Manuell', MappingSource::MANUAL->label());",
"+ }",
"+",
" \/\/ =========================================================================",
" \/\/ Data Integrity Tests",
" \/\/ =========================================================================",
" ",
"- public function testChunkMappingUpdatedAtOnConfidenceChange(): void",
"+ public function testEntityMappingUpdatedAtOnValidation(): void",
" {",
"- $mapping = new ChunkTaxonomyMapping();",
"- $mapping->setChunkId(1);",
"+ $mapping = new EntityTaxonomyMapping();",
"+ $mapping->setEntityId(1);",
" $mapping->setTaxonomyTermId(1);",
"- $mapping->setConfidence(Confidence::low());",
" ",
"- $initialUpdatedAt = $mapping->getUpdatedAt();",
"+ $this->assertNull($mapping->getUpdatedAt());",
" ",
"- usleep(1000);",
"- $mapping->setConfidence(Confidence::high());",
"+ $mapping->validate();",
" ",
" $this->assertNotNull($mapping->getUpdatedAt());",
"- if ($initialUpdatedAt !== null) {",
"- $this->assertNotEquals(",
"- $initialUpdatedAt->format('U.u'),",
"- $mapping->getUpdatedAt()->format('U.u')",
"- );",
"- }",
" }",
" ",
"- public function testEntityMappingUpdatedAtOnValidation(): void",
"+ public function testEntityMappingUpdatedAtOnRelevanceChange(): void",
" {",
" $mapping = new EntityTaxonomyMapping();",
" $mapping->setEntityId(1);"
]
},
{
"oldStart": 276,
"oldLines": 7,
"newStart": 330,
"newLines": 7,
"lines": [
" ",
" $this->assertNull($mapping->getUpdatedAt());",
" ",
"- $mapping->validate();",
"+ $mapping->setRelevance(Confidence::high());",
" ",
" $this->assertNotNull($mapping->getUpdatedAt());",
" }"
]
},
{
"oldStart": 298,
"oldLines": 4,
"newStart": 352,
"newLines": 23,
"lines": [
" $this->assertNotSame($mapping1->getTaxonomyTermId(), $mapping2->getTaxonomyTermId());",
" $this->assertNotSame($mapping1->getConfidence()->value(), $mapping2->getConfidence()->value());",
" }",
"+",
"+ public function testEntityTaxonomyMappingRoundTrip(): void",
"+ {",
"+ $original = new EntityTaxonomyMapping();",
"+ $original->setId(100);",
"+ $original->setEntityId(50);",
"+ $original->setTaxonomyTermId(25);",
"+ $original->setRelevance(Confidence::high());",
"+ $original->validate();",
"+",
"+ $array = $original->toArray();",
"+ $restored = EntityTaxonomyMapping::fromArray($array);",
"+",
"+ $this->assertSame($original->getId(), $restored->getId());",
"+ $this->assertSame($original->getEntityId(), $restored->getEntityId());",
"+ $this->assertSame($original->getTaxonomyTermId(), $restored->getTaxonomyTermId());",
"+ $this->assertSame($original->getRelevance()->value(), $restored->getRelevance()->value());",
"+ $this->assertSame($original->isValidated(), $restored->isValidated());",
"+ }",
" }"
]
}
],
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Integration\\Taxonomy;\n\n\/\/ @responsibility: Integration-Tests für Taxonomie-Mapping Pipeline\n\nuse Domain\\Entity\\ChunkTaxonomyMapping;\nuse Domain\\Entity\\EntityTaxonomyMapping;\nuse Domain\\ValueObject\\Confidence;\nuse Domain\\ValueObject\\MappingSource;\nuse PHPUnit\\Framework\\TestCase;\n\n\/**\n * Integration tests for Taxonomy Mapping Pipeline.\n *\n * Tests cover:\n * - ChunkTaxonomyMapping entity creation and serialization\n * - EntityTaxonomyMapping entity creation and validation\n * - Value objects (Confidence, MappingSource)\n * - Data integrity across mapping lifecycle\n *\/\nclass TaxonomyIntegrationTest extends TestCase\n{\n \/\/ =========================================================================\n \/\/ ChunkTaxonomyMapping Tests\n \/\/ =========================================================================\n\n public function testChunkTaxonomyMappingCreation(): void\n {\n $mapping = new ChunkTaxonomyMapping();\n $mapping->setChunkId(42);\n $mapping->setTaxonomyTermId(7);\n $mapping->setConfidence(Confidence::fromFloat(0.85));\n $mapping->setSource(MappingSource::AUTO);\n\n $this->assertNull($mapping->getId());\n $this->assertSame(42, $mapping->getChunkId());\n $this->assertSame(7, $mapping->getTaxonomyTermId());\n $this->assertSame(0.85, $mapping->getConfidence()->value());\n $this->assertSame('auto', $mapping->getSource()->value);\n $this->assertInstanceOf(\\DateTimeImmutable::class, $mapping->getCreatedAt());\n }\n\n public function testChunkTaxonomyMappingToArray(): void\n {\n $mapping = new ChunkTaxonomyMapping();\n $mapping->setId(1);\n $mapping->setChunkId(100);\n $mapping->setTaxonomyTermId(5);\n $mapping->setConfidence(Confidence::fromFloat(0.9));\n $mapping->setSource(MappingSource::MANUAL);\n\n $array = $mapping->toArray();\n\n $this->assertSame(1, $array['id']);\n $this->assertSame(100, $array['chunk_id']);\n $this->assertSame(5, $array['taxonomy_term_id']);\n $this->assertSame(0.9, $array['confidence']);\n $this->assertSame('manual', $array['source']);\n $this->assertArrayHasKey('created_at', $array);\n }\n\n public function testChunkTaxonomyMappingFromArray(): void\n {\n $data = [\n 'id' => 99,\n 'chunk_id' => 200,\n 'taxonomy_term_id' => 15,\n 'confidence' => 0.75,\n 'source' => 'pipeline',\n 'created_at' => '2025-01-01 12:00:00',\n ];\n\n $mapping = ChunkTaxonomyMapping::fromArray($data);\n\n $this->assertSame(99, $mapping->getId());\n $this->assertSame(200, $mapping->getChunkId());\n $this->assertSame(15, $mapping->getTaxonomyTermId());\n $this->assertSame(0.75, $mapping->getConfidence()->value());\n $this->assertSame('pipeline', $mapping->getSource()->value);\n }\n\n public function testChunkTaxonomyMappingRoundTrip(): void\n {\n $original = new ChunkTaxonomyMapping();\n $original->setId(42);\n $original->setChunkId(500);\n $original->setTaxonomyTermId(25);\n $original->setConfidence(Confidence::high());\n $original->setSource(MappingSource::IMPORT);\n\n $array = $original->toArray();\n $restored = ChunkTaxonomyMapping::fromArray($array);\n\n $this->assertSame($original->getId(), $restored->getId());\n $this->assertSame($original->getChunkId(), $restored->getChunkId());\n $this->assertSame($original->getTaxonomyTermId(), $restored->getTaxonomyTermId());\n $this->assertSame($original->getConfidence()->value(), $restored->getConfidence()->value());\n $this->assertSame($original->getSource()->value, $restored->getSource()->value);\n }\n\n \/\/ =========================================================================\n \/\/ EntityTaxonomyMapping Tests\n \/\/ =========================================================================\n\n public function testEntityTaxonomyMappingCreation(): void\n {\n $mapping = new EntityTaxonomyMapping();\n $mapping->setEntityId(10);\n $mapping->setTaxonomyTermId(3);\n $mapping->setRelevance(Confidence::fromFloat(0.8));\n\n $this->assertNull($mapping->getId());\n $this->assertSame(10, $mapping->getEntityId());\n $this->assertSame(3, $mapping->getTaxonomyTermId());\n $this->assertSame(0.8, $mapping->getRelevance()->value());\n $this->assertFalse($mapping->isValidated());\n }\n\n public function testEntityTaxonomyMappingValidation(): void\n {\n $mapping = new EntityTaxonomyMapping();\n $mapping->setEntityId(5);\n $mapping->setTaxonomyTermId(2);\n\n $this->assertFalse($mapping->isValidated());\n\n $mapping->validate();\n $this->assertTrue($mapping->isValidated());\n $this->assertNotNull($mapping->getUpdatedAt());\n\n $mapping->invalidate();\n $this->assertFalse($mapping->isValidated());\n }\n\n public function testEntityTaxonomyMappingToArray(): void\n {\n $mapping = new EntityTaxonomyMapping();\n $mapping->setId(50);\n $mapping->setEntityId(100);\n $mapping->setTaxonomyTermId(20);\n $mapping->setRelevance(Confidence::medium());\n $mapping->validate();\n\n $array = $mapping->toArray();\n\n $this->assertSame(50, $array['id']);\n $this->assertSame(100, $array['entity_id']);\n $this->assertSame(20, $array['taxonomy_term_id']);\n $this->assertSame(0.5, $array['relevance']);\n $this->assertSame(1, $array['validated']);\n }\n\n public function testEntityTaxonomyMappingFromArray(): void\n {\n $data = [\n 'id' => 77,\n 'entity_id' => 300,\n 'taxonomy_term_id' => 30,\n 'relevance' => 0.65,\n 'validated' => true,\n 'created_at' => '2025-06-15 10:30:00',\n 'updated_at' => '2025-06-15 11:00:00',\n ];\n\n $mapping = EntityTaxonomyMapping::fromArray($data);\n\n $this->assertSame(77, $mapping->getId());\n $this->assertSame(300, $mapping->getEntityId());\n $this->assertSame(30, $mapping->getTaxonomyTermId());\n $this->assertSame(0.65, $mapping->getRelevance()->value());\n $this->assertTrue($mapping->isValidated());\n $this->assertNotNull($mapping->getUpdatedAt());\n }\n\n \/\/ =========================================================================\n \/\/ Confidence Value Object Tests\n \/\/ =========================================================================\n\n public function testConfidenceFromFloat(): void\n {\n $confidence = Confidence::fromFloat(0.75);\n $this->assertSame(0.75, $confidence->value());\n }\n\n public function testConfidenceFactoryMethods(): void\n {\n $this->assertSame(0.9, Confidence::high()->value());\n $this->assertSame(0.5, Confidence::medium()->value());\n $this->assertSame(0.3, Confidence::low()->value());\n }\n\n public function testConfidenceBoundaries(): void\n {\n $zero = Confidence::fromFloat(0.0);\n $one = Confidence::fromFloat(1.0);\n\n $this->assertSame(0.0, $zero->value());\n $this->assertSame(1.0, $one->value());\n }\n\n public function testConfidenceInvalidValueTooLow(): void\n {\n $this->expectException(\\InvalidArgumentException::class);\n Confidence::fromFloat(-0.1);\n }\n\n public function testConfidenceInvalidValueTooHigh(): void\n {\n $this->expectException(\\InvalidArgumentException::class);\n Confidence::fromFloat(1.1);\n }\n\n \/\/ =========================================================================\n \/\/ MappingSource Value Object Tests\n \/\/ =========================================================================\n\n public function testMappingSourceValues(): void\n {\n $this->assertSame('auto', MappingSource::AUTO->value);\n $this->assertSame('manual', MappingSource::MANUAL->value);\n $this->assertSame('pipeline', MappingSource::PIPELINE->value);\n $this->assertSame('import', MappingSource::IMPORT->value);\n }\n\n public function testMappingSourceFrom(): void\n {\n $auto = MappingSource::from('auto');\n $manual = MappingSource::from('manual');\n\n $this->assertSame(MappingSource::AUTO, $auto);\n $this->assertSame(MappingSource::MANUAL, $manual);\n }\n\n public function testMappingSourceTryFrom(): void\n {\n $valid = MappingSource::tryFrom('pipeline');\n $invalid = MappingSource::tryFrom('invalid_source');\n\n $this->assertSame(MappingSource::PIPELINE, $valid);\n $this->assertNull($invalid);\n }\n\n \/\/ =========================================================================\n \/\/ Data Integrity Tests\n \/\/ =========================================================================\n\n public function testChunkMappingUpdatedAtOnConfidenceChange(): void\n {\n $mapping = new ChunkTaxonomyMapping();\n $mapping->setChunkId(1);\n $mapping->setTaxonomyTermId(1);\n $mapping->setConfidence(Confidence::low());\n\n $initialUpdatedAt = $mapping->getUpdatedAt();\n\n usleep(1000);\n $mapping->setConfidence(Confidence::high());\n\n $this->assertNotNull($mapping->getUpdatedAt());\n if ($initialUpdatedAt !== null) {\n $this->assertNotEquals(\n $initialUpdatedAt->format('U.u'),\n $mapping->getUpdatedAt()->format('U.u')\n );\n }\n }\n\n public function testEntityMappingUpdatedAtOnValidation(): void\n {\n $mapping = new EntityTaxonomyMapping();\n $mapping->setEntityId(1);\n $mapping->setTaxonomyTermId(1);\n\n $this->assertNull($mapping->getUpdatedAt());\n\n $mapping->validate();\n\n $this->assertNotNull($mapping->getUpdatedAt());\n }\n\n public function testMultipleMappingsIndependence(): void\n {\n $mapping1 = new Ch... [TRUNCATED-bc6e5d98b893c0d3]"
}
}