示例#1
0
 public function testFromArrayAndToArray()
 {
     $array = ['id' => 'testId', 'label' => 'test label', 'is_default' => true, 'priority' => 100];
     $enumValue = new EnumValue();
     $enumValue->setLabel('test label')->setId('testId')->setIsDefault(true)->setPriority(100);
     static::assertEquals($enumValue, EnumValue::createFromArray($array));
     static::assertEquals($array, $enumValue->toArray());
 }
 /**
  * @param FieldConfigModel $entity
  * @return array
  */
 protected function validateEntityFields(FieldConfigModel $entity)
 {
     $errors = [];
     $fieldProperties = $this->fieldTypeProvider->getFieldProperties($entity->getType());
     foreach ($fieldProperties as $scope => $properties) {
         $scopeData = $entity->toArray($scope);
         foreach ($properties as $code => $config) {
             if (!isset($scopeData[$code])) {
                 continue;
             }
             if ($scope === 'enum') {
                 foreach ($scopeData[$code] as $key => $enumFields) {
                     $result = $this->strategyHelper->validateEntity(EnumValue::createFromArray($enumFields));
                     if ($result) {
                         $errors[] = sprintf('%s.%s.%s: %s', $scope, $code, $key, implode(' ', $result));
                     }
                 }
             } elseif (isset($config['constraints'])) {
                 $result = $this->strategyHelper->validateEntity($scopeData[$code], $this->constraintFactory->parse($config['constraints']));
                 if ($result) {
                     $errors[] = sprintf('%s.%s: %s', $scope, $code, implode(' ', $result));
                 }
             }
         }
     }
     return $errors;
 }