Last active
August 31, 2017 00:51
-
-
Save coreymcmahon/8414236 to your computer and use it in GitHub Desktop.
Building Testable Applications using the Repository Pattern - http://www.slashnode.com/the-repository-pattern/
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 | |
use Acme\Storage\PostRepositoryInterface; | |
use Mockery as m; | |
class PostControllerTest extends TestCase { | |
private $postRepository; | |
public function setUp() | |
{ | |
parent::setup(); | |
// create a mock of the post repository interface and inject it into the | |
// IoC container | |
$this->postRepository = m::mock('Acme\Storage\PostRepositoryInterface'); | |
$this->app->instance('Acme\Storage\PostRepositoryInterface', $this->postRepository); | |
} | |
public function tearDown() | |
{ | |
m::close(); | |
parent::tearDown(); | |
} | |
public function testIndex() | |
{ | |
$this->postRepository->shouldReceive('paginate')->once()->andReturn(array()); | |
$response = $this->call('GET', '/posts'); | |
$this->assertResponseOk($response); | |
$this->assertViewHas('posts'); | |
} | |
// etc... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment