Skip to content

Instantly share code, notes, and snippets.

@aranw
Created November 13, 2012 22:25
Show Gist options
  • Save aranw/4068849 to your computer and use it in GitHub Desktop.
Save aranw/4068849 to your computer and use it in GitHub Desktop.
Testing
public function showPost($post = null)
{
$view = View::make('blog.post');
$view->with('title', "Aran Wilkinson - "); // We need to get the post title
$view->with('post', $this->posts->getPostBySlug($post));
//
// Get the requested blog post
// If it doesn't exist give 404 error
//
return $view;
}
public function resolvePost($post_id)
{
$post = $this->posts->getPostById($post_id);
if ($post)
{
return Redirect::to('blog/'.$post->slug);
}
else
{
// Trigger 404
throw new NotFoundHttpException('Unable to find that blog post');
}
}
public function testPostById()
{
// For the PostById query we need a $post object with a slug
$post = new stdClass;
$post->id = 1;
$post->slug = 'foo';
$mockRepository = Mockery::mock('PostRepository');
$redirector = Mockery::mock('Illuminate\Routing\Redirector');
$redirector->shouldReceive('to')->once()->with('blog/foo');
App()['redirect'] = $redirector;
// Return the $post object to the function giving our $post->slug
$mockRepository->shouldReceive('getPostById')->with(1)->once()->andReturn($post);
$this->app->instance('PostRepository', $mockRepository);
$response = $this->call('GET', '/1');
$this->assertTrue($response->isOk());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment