{
"tool_response": {
"type": "text",
"file": {
"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]",
"numLines": 375,
"startLine": 1,
"totalLines": 375
}
}
}