public function testProcessValid()
 {
     $entity = new SomeEntity();
     $form = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $data = ['a' => '1', 'b' => '2'];
     $method = 'PATCH';
     $this->processor->expects($this->once())->method('preProcess')->with($entity);
     $form->expects($this->once())->method('setData')->with($entity);
     $form->expects($this->once())->method('submit')->with($data);
     $form->expects($this->once())->method('isValid')->willReturn(true);
     $this->processor->expects($this->once())->method('beforeProcess')->with($entity);
     $this->processor->expects($this->once())->method('afterProcess')->with($entity);
     $this->processor->expects($this->never())->method('invalidateProcess')->with($entity);
     $this->initManager();
     $this->assertEquals(['fields' => ['a' => '1', 'b' => '2']], $this->handler->process($entity, $form, $data, $method));
 }
Esempio n. 2
0
 /**
  * Process form
  *
  * @param $entity
  * @param FormInterface $form
  * @param array $data
  * @param string $method
  *
  * @return array changset
  */
 public function process($entity, FormInterface $form, $data, $method)
 {
     $this->processor->preProcess($entity);
     $form->setData($entity);
     if (in_array($method, ['POST', 'PUT', 'PATCH'], true)) {
         $form->submit($data);
         if ($form->isValid()) {
             $this->processor->beforeProcess($entity);
             $this->onSuccess($entity);
             $changeSet = $this->initChangeSet($entity, $data);
             $changeSet = $this->updateChangeSet($changeSet, $this->processor->afterProcess($entity));
             return $changeSet;
         } else {
             $this->processor->invalidateProcess($entity);
         }
     }
     return [];
 }
 /**
  * @param $entity
  * @param string $method
  * @param int $count
  */
 protected function prepareProcess($entity, $method, $count = 0)
 {
     $handler = $this->getHandlerMock();
     $this->processor->addHandler($handler);
     if ($count === 0) {
         $handler->expects($this->once())->method('getClass')->willReturn('some/class');
     } else {
         $handler->expects($this->once())->method('getClass')->willReturn(ClassUtils::getClass($entity));
     }
     $handler->expects($this->exactly($count))->method($method);
 }