コード例 #1
0
ファイル: Page.php プロジェクト: obsidianstorms/silexblog
 /**
  * @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);
 }
コード例 #2
0
 /**
  * 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);
 }