Skip to content

Instantly share code, notes, and snippets.

@ackintosh
Created October 19, 2013 19:07
Show Gist options
  • Select an option

  • Save ackintosh/7060084 to your computer and use it in GitHub Desktop.

Select an option

Save ackintosh/7060084 to your computer and use it in GitHub Desktop.
<?php
class Foo
{
public function bar()
{
// ...
$posts = get_posts($condition);
if ( !is_array($posts) ){
return;
}
// ...
}
}
<?php
class FooProxy
{
public function __call($name, $args)
{
return call_user_func_array($name, $args);
}
}
class Foo
{
private $proxy;
public function __construct(FooProxy $proxy)
{
$this->proxy = $proxy;
}
public function bar()
{
// ...
$posts = $this->proxy->get_posts($condition);
if ( !is_array($posts) ){
return;
}
// ...
}
}
<?php
class FooTest extends PHPUnit_Framework_TestCase
{
/** @test */
public function barReturnsNullWhenNoPosts()
{
$proxy = $this->getMockBuilder('FooProxy')
->setMethods(array('get_posts'))
->getMock();
$proxy->expects($this->once())
->method('get_posts')
->will($this->returnValue(''));
$foo = new Fooo($proxy);
$this->assertNull($foo->bar());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment