class TwitterClient { public function tweet($message) { return true; } } $hoge = new TwitterClient(); $hoge->tweet('大心なう'); // trueが返る class ClientContainerTest extends PHPUnit_Framework_TestCase { public function test_モックを書いてみる() { $hoge = $this->getMock('TwitterClient', array('tweet')); $hoge->expects($this->any()) ->method('tweet') ->will($this->returnValue(true)); $hoge->tweet('大心なう'); // true
![PHPUnitのモックで設計とリファクタが捗る | 48JIGEN *Reloaded*](https://cdn-ak-scissors.b.st-hatena.com/image/square/e017361b2180713a5c8500bd6057a0638c888faa/height=288;version=1;width=512/https%3A%2F%2Frimuru.lunanet.gr.jp%2Ffiles%2F2950%2F8001786818_6efb062bbf_m.jpg)