/**
  * @param \Flowpack\ElasticSearch\Domain\Model\AbstractType $type
  * @param string $id
  * @param \Flowpack\ElasticSearch\Transfer\Response $response
  * @throws \Flowpack\ElasticSearch\Domain\Exception\DocumentPropertiesMismatchException
  * @return \Flowpack\ElasticSearch\Domain\Model\Document
  */
 public function createFromResponse(Model\AbstractType $type, $id = null, \Flowpack\ElasticSearch\Transfer\Response $response)
 {
     $content = $response->getTreatedContent();
     $verificationResults = new ErrorResult();
     if (isset($content['_index']) && $type->getIndex()->getName() !== $content['_index']) {
         $error = new Error('The received index name "%s" does not match the expected one "%s".', 1340264838, array($content['_index'], $type->getIndex()->getName()));
         $verificationResults->addError($error);
     }
     if (isset($content['_type']) && $type->getName() !== $content['_type']) {
         $error = new Error('The received type name "%s" does not match the expected one "%s".', 1340265103, array($content['_type'], $type->getName()));
         $verificationResults->addError($error);
     }
     if (isset($content['_id']) && $id !== null && $id !== $content['_id']) {
         $error = new Error('The received id "%s" does not match the expected one "%s".', 1340269758, array($content['_id'], $id));
         $verificationResults->addError($error);
     }
     if ($verificationResults->hasErrors()) {
         $exception = new \Flowpack\ElasticSearch\Domain\Exception\DocumentPropertiesMismatchException('The document\'s properties do not match the expected ones.', 1340265248);
         $exception->setErrorResult($verificationResults);
         throw $exception;
     }
     $version = $content['_version'];
     $data = $content['_source'];
     return new Model\Document($type, $data, $id, $version);
 }
 /**
  * @test
  */
 public function returnsAndRendersThenChildIfResultsHaveErrors()
 {
     $result = new Result();
     $result->addError(new Error('I am an error', 1386163707));
     /** @var $requestMock \PHPUnit_Framework_MockObject_MockObject */
     $requestMock = $this->request;
     $requestMock->expects($this->once())->method('getInternalArgument')->with('__submittedArgumentValidationResults')->will($this->returnValue($result));
     $this->viewHelper->expects($this->once())->method('renderThenChild')->will($this->returnValue('ThenChild'));
     $this->assertEquals('ThenChild', $this->viewHelper->render());
 }
 /**
  * Creates a new validation error object and adds it to $this->errors
  *
  * @param string $message The error message
  * @param integer $code The error code (a unix timestamp)
  * @param array $arguments Arguments to be replaced in message
  * @return void
  * @api
  */
 protected function addError($message, $code, array $arguments = [])
 {
     $this->result->addError(new ValidationError($message, $code, $arguments));
 }
 /**
  * Validate a null value with the given schema
  *
  * @param mixed $value
  * @param array $schema
  * @return ErrorResult
  */
 protected function validateNullType($value, array $schema)
 {
     $result = new ErrorResult();
     if ($value !== null) {
         $result->addError($this->createError('type=NULL', 'type=' . gettype($value)));
     }
     return $result;
 }
 /**
  * Creates a new validation error object and adds it to $this->errors
  *
  * @param string $message The error message
  * @param integer $code The error code (a unix timestamp)
  * @param array $arguments Arguments to be replaced in message
  * @return void
  * @api
  */
 protected function addError($message, $code, array $arguments = array())
 {
     $this->result->addError(new \TYPO3\Flow\Validation\Error($message, $code, $arguments));
 }