示例#1
0
 /**
  * @param Application $app
  * @param $post_id int
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  */
 public function removePost(Application $app, $post_id)
 {
     $apiObject = new PostApi(new PostData($app));
     $apiCommentObject = new CommentApi(new CommentData($app));
     try {
         $result = $apiObject->delete($post_id);
         $resultComment = $apiCommentObject->deleteAllForPost($post_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 completely remove post.');
         return $this->index($app);
     }
     $app['session']->getFlashBag()->add('message', 'Deleted post.');
     return $this->index($app);
 }
 /**
  * Test deleteAllForPosts() method returns true if query succeeds
  */
 public function testDeleteAllForPostReturnsTrueIfQuerySucceeds()
 {
     $mockId = 1;
     $mockApp = m::mock(\Silex\Application::class)->makePartial();
     $mockDataObject = m::mock(CommentData::class, [$mockApp]);
     $mockDataObject->shouldReceive('deleteAllForPost')->with($mockId)->andReturn(true);
     $object = new CommentApi($mockDataObject);
     $returned = $object->deleteAllForPost($mockId);
     $this->assertTrue($returned);
 }