示例#1
0
 /**
  * @param object $entity
  *
  * @return null|object
  */
 protected function validateAndUpdateContext($entity)
 {
     // validate entity
     $validationErrors = $this->strategyHelper->validateEntity($entity);
     if ($validationErrors) {
         $this->context->incrementErrorEntriesCount();
         $errorPrefix = ValidationUtils::guessValidationMessagePrefix($entity);
         $this->strategyHelper->addValidationErrors($validationErrors, $this->context, $errorPrefix);
         return null;
     }
     // increment context counter
     if ($entity->getId()) {
         $this->context->incrementUpdateCount();
     } else {
         $this->context->incrementAddCount();
     }
     return $entity;
 }
 /**
  * @param string|null $path
  * @param string $error
  * @param string $expectedMessage
  * @dataProvider validateDataProvider
  */
 public function testValidateEntity($path, $error, $expectedMessage)
 {
     $entity = new \stdClass();
     $violation = $this->getMockBuilder('Symfony\\Component\\Validator\\ConstraintViolationInterface')->getMock();
     $violation->expects($this->once())->method('getPropertyPath')->will($this->returnValue($path));
     $violation->expects($this->once())->method('getMessage')->will($this->returnValue($error));
     $violations = array($violation);
     $this->validator->expects($this->once())->method('validate')->with($entity)->will($this->returnValue($violations));
     $this->assertEquals(array($expectedMessage), $this->helper->validateEntity($entity));
 }