Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Last active August 31, 2017 00:51
Show Gist options
  • Save coreymcmahon/8414236 to your computer and use it in GitHub Desktop.
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/
<?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