/** * Guess field types only for this form type * for not extended fields * can't use regular guessers, as they will work for all forms * * @param string $className * @param string $fieldName * * @return array */ protected function guessFieldType($className, $fieldName) { $type = null; $fieldOptions = ['label' => '']; // chance to guess by names if (isset($this->mapping['all'][$fieldName])) { $map = $this->mapping['all'][$fieldName]; $type = $map['type']; $fieldOptions = $map['options']; } // if more specific map rule exists if (isset($this->mapping[$className][$fieldName])) { $map = $this->mapping[$className][$fieldName]; $type = $map['type']; $fieldOptions = $map['options']; } if (is_null($type)) { $guess = $this->guesser->guessType($className, $fieldName); if ($guess) { $type = $guess->getType(); $fieldOptions = $guess->getOptions(); } } return [$type, $fieldOptions]; }
/** * @param bool $hasConfig * @param bool $isEnabled * @param bool $isManyToOneExists * @param string $expectedType * @param array $expectedOptions * * @dataProvider guessTypeProvider */ public function testGuessType($hasConfig, $isEnabled, $isManyToOneExists, $expectedType, $expectedOptions) { $className = 'Test\\Entity'; $relatedEntityName = 'Test\\EntityRelated'; $property = 'subject'; $this->setupExtendHasConfig($className, $property, $hasConfig, ['is_deleted' => false, 'state' => ExtendScope::STATE_ACTIVE, 'target_entity' => $relatedEntityName]); $this->setupFormIsEnabled($className, $property, RelationType::TO_ONE, $isEnabled); if ($hasConfig && $isEnabled) { $this->fieldProviderMock->expects($this->once())->method('getFields')->with($className, true)->willReturn([['name' => 'subject', 'related_entity_name' => $relatedEntityName]]); } if ($isManyToOneExists) { $this->setupEntityConfig($className, $property); $this->guesser->addExtendTypeMapping(RelationType::TO_ONE, 'entity'); } $guess = $this->guesser->guessType($className, $property); $this->assertEquals($expectedType, $guess->getType(), 'Failed asserting type guessed correctly'); $this->assertEquals($expectedOptions, $guess->getOptions(), 'Failed asserting options guessed correctly'); }