/** * @test */ public function mergeShouldMergeTwoResults() { $notice1 = $this->getMockMessage('Notice'); $notice2 = $this->getMockMessage('Notice'); $notice3 = $this->getMockMessage('Notice'); $warning1 = $this->getMockMessage('Warning'); $warning2 = $this->getMockMessage('Warning'); $warning3 = $this->getMockMessage('Warning'); $error1 = $this->getMockMessage('Error'); $error2 = $this->getMockMessage('Error'); $error3 = $this->getMockMessage('Error'); $otherResult = new \TYPO3\FLOW3\Error\Result(); $otherResult->addNotice($notice1); $otherResult->forProperty('foo.bar')->addNotice($notice2); $this->result->forProperty('foo')->addNotice($notice3); $otherResult->addWarning($warning1); $this->result->addWarning($warning2); $this->result->addWarning($warning3); $otherResult->forProperty('foo')->addError($error1); $otherResult->forProperty('foo')->addError($error2); $otherResult->addError($error3); $this->result->merge($otherResult); $this->assertSame(array($notice1), $this->result->getNotices(), 'Notices are not merged correctly without recursion'); $this->assertSame(array($notice3), $this->result->forProperty('foo')->getNotices(), 'Original sub-notices are overridden.'); $this->assertSame(array($notice2), $this->result->forProperty('foo')->forProperty('bar')->getNotices(), 'Sub-notices are not copied.'); $this->assertSame(array($warning2, $warning3, $warning1), $this->result->getWarnings()); $this->assertSame(array($error3), $this->result->getErrors()); $this->assertSame(array($error1, $error2), $this->result->forProperty('foo')->getErrors()); }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * @return \TYPO3\FLOW3\Mvc\Controller\Argument $this */ public function setValue($rawValue) { if ($rawValue === NULL) { $this->value = NULL; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== NULL) { $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; }
/** * Checks if the specified property of the given object is valid, and adds * found errors to the $messages object. * * @param mixed $value The value to be validated * @param array $validators The validators to be called on the value * @param \TYPO3\FLOW3\Error\Result $messages the result object to which the validation errors should be added * @return void */ protected function checkProperty($value, $validators, \TYPO3\FLOW3\Error\Result $messages) { foreach ($validators as $validator) { if ($validator instanceof ObjectValidatorInterface) { $validator->setValidatedInstancesContainer($this->validatedInstancesContainer); } $result = $validator->validate($value); if ($result->hasErrors() || $result->hasNotices() || $result->hasWarnings()) { $messages->merge($validator->validate($value)); } } }