Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created January 14, 2014 06:50
Show Gist options
  • Save coreymcmahon/8414199 to your computer and use it in GitHub Desktop.
Save coreymcmahon/8414199 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 Mockery as m;
class PostControllerTest extends PHPUnit_Framework_Testcase {
private $postRepository;
private $postController;
public function setUp()
{
parent::setup();
$this->postRepository = m::mock('Acme\Storage\PostRepository');
// inject the mocked version of the repository
$this->postController = new Acme\Controllers\PostController($this->postRepository);
}
public function tearDown()
{
m::close();
parent::tearDown();
}
public function testIndex()
{
$this->postRepository->shoudlReceive('paginate')->once()->andReturn(array());
$response = $this->postController->index();
$this->assertEqual(array(), $response);
}
// etc...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment