Created
November 13, 2012 13:16
-
-
Save aranw/4065718 to your computer and use it in GitHub Desktop.
Bug with phpunit Laravel 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PostTest extends TestCase { | |
/** | |
* Tear down the testing environment | |
* | |
* @return void | |
**/ | |
public function tearDown() | |
{ | |
Mockery::close(); | |
} | |
/** | |
* Test Post Repository | |
* | |
* @return void | |
**/ | |
public function testGetLatestPosts() | |
{ | |
$mockRepository = Mockery::mock('PostRepository'); | |
$mockRepository->shouldReceive('getLatestPosts')->once()->andReturn('foo'); | |
$this->app->instance('PostRepository', $mockRepository); | |
$response = $this->call('GET', '/blog'); | |
$view = $response->getOriginalContent(); | |
$this->assertTrue($response->isOk()); | |
$this->assertEquals('foo', $view['posts']); | |
} | |
/** | |
* Test Single Post | |
* | |
* @return void | |
**/ | |
public function testPostBySlug() | |
{ | |
$mockRepository = Mockery::mock('PostRepository'); | |
$mockRepository->shouldReceive('getPostBySlug')->with("mockery")->once()->andReturn('foobar'); | |
$this->app->instance('PostRepository', $mockRepository); | |
$response = $this->call('GET', '/blog/mockery'); | |
$view = $response->getOriginalContent(); | |
$this->assertTrue($response->isOk()); | |
$this->assertEquals('foobar', $view['post']); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('/blog/{slug}', 'PostController@showPost'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TestCase extends Illuminate\Foundation\Testing\TestCase { | |
/** | |
* Creates the application. | |
* | |
* @return Symfony\Component\HttpKernel\HttpKernelInterface | |
*/ | |
public function createApplication() | |
{ | |
$unitTesting = true; | |
$testEnvironment = 'testing'; | |
return require __DIR__.'/../../start.php'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment