public function indexAction() { /** @var \Zend\Http\Request $request */ $request = $this->getRequest(); $id = $this->params()->fromRoute('id', null); try { $bookEntity = $this->service->getById($id); if ($request->isPost()) { $this->form->setData($request->getPost()->toArray()); if ($this->form->isValid()) { $this->flashMessenger()->addSuccessMessage('Books deleted successfully'); $this->service->delete($bookEntity); return $this->redirect()->toRoute('library/books'); } else { $this->flashMessenger()->addErrorMessage('Please fill form correctly'); } } else { $this->form->get('id')->setValue($bookEntity->getId()); } return ['form' => $this->form, 'book' => $bookEntity]; } catch (\Exception $e) { $this->flashMessenger()->addSuccessMessage($e->getMessage()); return $this->redirect()->toRoute('library/books'); } }
public function indexAction() { $id = $this->params()->fromRoute('id', null); try { $bookEntity = $this->service->getById($id); $this->service->delete($bookEntity); return new JsonModel(['data' => "Books with id {$id} has been deleted"]); } catch (EntityNotFoundException $e) { throw new Exception\NotFoundException(); } catch (\PDOException $e) { throw new Exception\PDOServiceUnavailableException(); } }
public function testDelete() { $bookEntity = $this->bookEntityProvider->getBookEntityWithRandomData(); $this->bookRepositoryMock->expects($this->once())->method('delete')->with($bookEntity); $this->testedObj->delete($bookEntity); }