/** * @test */ public function buildMethodArgumentsValidatorConjunctionsReturnsEmptyArrayIfMethodHasNoArguments() { $mockController = $this->getAccessibleMock('TYPO3\\FLOW3\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE); $mockReflectionService = $this->getMock('TYPO3\\FLOW3\\Reflection\\ReflectionService', array(), array(), '', FALSE); $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue(array())); $this->validatorResolver = $this->getAccessibleMock('TYPO3\\FLOW3\\Validation\\ValidatorResolver', array('createValidator'), array(), '', FALSE); $this->validatorResolver->_set('reflectionService', $mockReflectionService); $result = $this->validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockController), 'fooAction'); $this->assertSame(array(), $result); }
/** * Check if $value is valid. If it is not valid, needs to add an error * to Result. * * @param mixed $value A collection to be validated * @return void */ protected function isValid($value) { foreach ($value as $index => $collectionElement) { if (isset($this->options['elementValidator'])) { $collectionElementValidator = $this->validatorResolver->createValidator($this->options['elementValidator']); } elseif (isset($this->options['elementType'])) { if (isset($this->options['validationGroups'])) { $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType'], $this->options['validationGroups']); } else { $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType']); } } else { return; } if ($collectionElementValidator instanceof ObjectValidatorInterface) { $collectionElementValidator->setValidatedInstancesContainer($this->validatedInstancesContainer); } $this->result->forProperty($index)->merge($collectionElementValidator->validate($collectionElement)); } }
public function transform($data, $target) { $data = $this->cleanUpBlanks($data); $value = $this->propertyMapper->convert($data, $target, \Admin\Core\PropertyMappingConfiguration::getConfiguration()); $this->validationResults = $this->propertyMapper->getMessages(); $validator = $this->validatorResolver->getBaseValidatorConjunction($target); $validationMessages = $validator->validate($value); $this->validationResults->merge($validationMessages); $errors = $this->validationResults->getFlattenedErrors(); if (empty($errors)) { return $value; } else { return $errors; } }
/** * Validates the given object and throws an exception if validation fails. * * @param object $object * @return void * @throws \TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException * @api */ protected function validateObject($object) { $classSchema = $this->reflectionService->getClassSchema($object); $validator = $this->validatorResolver->getBaseValidatorConjunction($classSchema->getClassName()); if ($validator === NULL) { return; } $validationResult = $validator->validate($object); if ($validationResult->hasErrors()) { $errorMessages = ''; $allErrors = $validationResult->getFlattenedErrors(); foreach ($allErrors as $path => $errors) { $errorMessages .= $path . ':' . PHP_EOL; foreach ($errors as $error) { $errorMessages .= (string) $error . PHP_EOL; } } throw new \TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException('An instance of "' . get_class($object) . '" failed to pass validation with ' . count($errors) . ' error(s): ' . PHP_EOL . $errorMessages, 1322585162); } }
/** * Validates the given object and throws an exception if validation fails. * * @param object $object * @param \SplObjectStorage $validatedInstancesContainer * @return void * @throws \TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException */ protected function validateObject($object, \SplObjectStorage $validatedInstancesContainer) { $className = $this->entityManager->getClassMetadata(get_class($object))->getName(); $validator = $this->validatorResolver->getBaseValidatorConjunction($className, array('Persistence', 'Default')); if ($validator === NULL) { return; } $validator->setValidatedInstancesContainer($validatedInstancesContainer); $validationResult = $validator->validate($object); if ($validationResult->hasErrors()) { $errorMessages = ''; $allErrors = $validationResult->getFlattenedErrors(); foreach ($allErrors as $path => $errors) { $errorMessages .= $path . ':' . PHP_EOL; foreach ($errors as $error) { $errorMessages .= (string) $error . PHP_EOL; } } throw new \TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException('An instance of "' . get_class($object) . '" failed to pass validation with ' . count($errors) . ' error(s): ' . PHP_EOL . $errorMessages, 1322585164); } }