Skip to content

Instantly share code, notes, and snippets.

@robertbasic
Created March 6, 2013 08:59
Show Gist options
  • Select an option

  • Save robertbasic/5097794 to your computer and use it in GitHub Desktop.

Select an option

Save robertbasic/5097794 to your computer and use it in GitHub Desktop.
Not sure about phpunit's mock building, but with mockery you could possibly mock
the Article class - not the entire class, but just the createQueryBuilder method,
which you set that to return a mock of the query builder, on which you further
set the expectations. Something like:
<?php
use \Mockery as m;
function testQueryBuilder()
{
$qbMock = m::mock(...QueryBuilderClassGoesHere...);
$qbMock->shouldReceive("andWhere")
->with("a.publishDate IS NOT NULL")
->andReturn($qbMock);
// ... rest of the expectations ...
$article = m::mock("Article[createQueryBuilder]");
$article->shouldReceive("createQueryBuilder")
->with('a')
->andReturn($qbMock);
$article->findRecent(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment