/**
  * @param object        $entity        entity
  * @param ObjectManager $entityManager entityManager
  * @param UnitOfWork    $uow           uow
  */
 private function computeViolations($entity, ObjectManager $entityManager, UnitOfWork $uow)
 {
     if (!($handlers = $this->handlerManager->fetch($entity))) {
         return null;
     }
     $list = $this->violationManager->getViolationListNotFixed($entity);
     $list->setFixed(true);
     foreach ($handlers as $handler) {
         $handler->validate($entity, $list);
     }
     $uow->computeChangeSets();
     foreach ($list as $violation) {
         $changeSet = $uow->getEntityChangeSet($violation);
         if (!empty($changeSet) || !$entityManager->contains($violation)) {
             $this->violations[spl_object_hash($violation)] = $violation;
         }
     }
 }
Ejemplo n.º 2
0
 public function testFetch()
 {
     $this->mockClass('Rezzza\\ModelViolationLoggerBundle\\Handler\\ViolationHandlerInterface', '\\Mock');
     $createHandler = function ($v) {
         $handler = new \mock\ViolationHandlerInterface();
         $handler->getMockController()->getModel = $v;
         return $handler;
     };
     $handler1 = $createHandler('\\stdClass');
     $handler2 = $createHandler('\\stdClass');
     $handler3 = $createHandler('\\stdClass');
     $handler4 = $createHandler('\\stdClass');
     $handler5 = $createHandler('\\ReflectionClass');
     $manager = new ManagerModel();
     $manager->add($handler1, 3);
     $manager->add($handler2, 2);
     $manager->add($handler3, 4);
     $manager->add($handler4, 1);
     $manager->add($handler5, 6);
     $handlers = $manager->fetch(new \stdClass());
     $this->integer(count($handlers))->isEqualTo(4)->object($handlers[0])->isIdenticalTo($handler4)->object($handlers[1])->isIdenticalTo($handler2)->object($handlers[2])->isIdenticalTo($handler1)->object($handlers[3])->isIdenticalTo($handler3);
 }