Created
October 19, 2013 19:07
-
-
Save ackintosh/7060084 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| class Foo | |
| { | |
| public function bar() | |
| { | |
| // ... | |
| $posts = get_posts($condition); | |
| if ( !is_array($posts) ){ | |
| return; | |
| } | |
| // ... | |
| } | |
| } |
This file contains hidden or 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 | |
| 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; | |
| } | |
| // ... | |
| } | |
| } |
This file contains hidden or 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 | |
| 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