/** * @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; }
/** * @dataProvider prefixDataProvider * @param string|null $prefix */ public function testAddValidationErrors($prefix) { $validationErrors = array('Error1', 'Error2'); $expectedPrefix = $prefix; $context = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface')->getMock(); if (null === $prefix) { $context->expects($this->once())->method('getReadOffset')->will($this->returnValue(10)); $this->translator->expects($this->once())->method('trans')->with('oro.importexport.import.error %number%', array('%number%' => 10))->will($this->returnValue('TranslatedError 10')); $expectedPrefix = 'TranslatedError 10'; } $context->expects($this->exactly(2))->method('addError')->with($this->stringStartsWith($expectedPrefix . ' Error')); $this->helper->addValidationErrors($validationErrors, $context, $prefix); }
/** * @param string $entityName * * @return EntityRepository */ public function getEntityRepository($entityName) { return $this->strategyHelper->getEntityManager($entityName)->getRepository($entityName); }