コード例 #1
0
 public function addAction()
 {
     $tipo = $this->_getParam('tipo', 'Monetario');
     $tarefa_id = (int) $this->_getParam('tarefa', 0);
     if (!$tarefa_id) {
         $dql = "SELECT t FROM Application\\Entity\\Tarefa t";
         $query = $this->_em->createQuery($dql);
         $tarefas = $query->getResult();
     } else {
         $tarefas[] = $this->_em->find('Application\\Entity\\Tarefa', $tarefa_id);
     }
     $formName = 'Form_Requisito_' . $tipo;
     $form = new $formName($tarefas);
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $tarefa = $this->_em->find('Application\\Entity\\Tarefa', $tarefa_id);
             $config = $form->getValues();
             $config['em'] = $this->_em;
             $builderRequisito = new Service\Builder\Requisito();
             $requisito = $builderRequisito->create($tarefa, $form->getValue('tipo'), $config);
             $this->_em->persist($requisito);
             $this->_em->flush();
             $this->_helper->FlashMessenger(array('success' => 'Requisito incluído com sucesso'));
             return $this->_helper->redirector('edit', 'tarefas', 'admin', array('id' => $tarefa_id));
         } else {
             $form->populate($formData);
         }
     }
 }
コード例 #2
0
 public function testCreateTarefa()
 {
     $tarefa = \Mockery::mock('\\Application\\Entity\\Tarefa', array('getId' => 1, 'getNome' => 'Descrição da Tarefa1'));
     $tarefaRequisito = \Mockery::mock('\\Application\\Entity\\Tarefa', array('getId' => 2, 'getNome' => 'Descrição da Tarefa2'));
     $em = \Mockery::mock('\\Doctrine\\ORM\\EntityManager', array('find' => $tarefaRequisito));
     $builderRequisito = new Builder\Requisito();
     $requisito = $builderRequisito->create($tarefa, 'Tarefa', array('tarefa_req' => 2, 'em' => $em));
     $this->assertInstanceOf('Application\\Entity\\RequisitoTarefa', $requisito);
     $this->assertEquals($tarefaRequisito, $requisito->getTarefaRequisito());
     $this->assertEquals($tarefa, $requisito->getTarefa());
 }