Example #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);
 }
Example #2
0
 /**
  * Test delete() returns post id if query succeeds
  */
 public function testDeleteReturnsPostIdIfQuerySucceeds()
 {
     $mockPostId = 1;
     $mockData = ['title' => 'somevalue', 'body' => 'somevalue'];
     $mockSessionData = ['author_id' => 1];
     $mockPostData = ['title' => 'somevalue'];
     $mockContentData = ['body' => 'somevalue'];
     $mockSessionObject = m::mock(\stdClass::class);
     $mockSessionObject->shouldReceive('get')->with('author')->andReturn($mockSessionData);
     $mockApp = m::mock(\Silex\Application::class)->makePartial();
     $mockDataObject = m::mock(PostData::class, [$mockApp]);
     $mockDataObject->shouldReceive('getSession')->andReturn($mockSessionObject);
     $mockDataObject->shouldReceive('update')->with($mockPostId, $mockPostData)->andReturn($mockPostId);
     $mockDataObject->shouldReceive('updateContent')->with($mockPostId, $mockContentData)->andReturn(true);
     $object = new PostApi($mockDataObject);
     $returned = $object->update($mockPostId, $mockData);
     $this->assertSame($mockPostId, $returned);
 }