Beispiel #1
0
 /**
  * @param Application $app
  * @param $post_id int
  * @param $comment_id int
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  */
 public function removeComment(Application $app, $post_id, $comment_id)
 {
     $apiObject = new CommentApi(new CommentData($app));
     try {
         $result = $apiObject->delete($comment_id);
     } catch (\InvalidArgumentException $e) {
         $message = $e->getMessage();
     } catch (\UnexpectedValueException $e) {
         $message = $e->getMessage();
     }
     if (isset($message)) {
         $app['session']->getFlashBag()->add('message', $message);
     }
     if (!isset($result) || !$result) {
         $app['session']->getFlashBag()->add('message', 'Failed to remove comment.');
         return $this->viewReadPost($app, $post_id);
     }
     $app['session']->getFlashBag()->add('message', 'Deleted comment.');
     return $this->viewReadPost($app, $post_id);
 }
 /**
  * Test delete() method returns true if query suceeds
  */
 public function testDeleteReturnsTrueIfQuerySucceeds()
 {
     $mockId = 1;
     $mockApp = m::mock(\Silex\Application::class)->makePartial();
     $mockDataObject = m::mock(CommentData::class, [$mockApp]);
     $mockDataObject->shouldReceive('delete')->with($mockId)->andReturn(true);
     $object = new CommentApi($mockDataObject);
     $returned = $object->delete($mockId);
     $this->assertTrue($returned);
 }