Skip to content

Instantly share code, notes, and snippets.

@tamakiii
Last active December 16, 2015 10:19
Show Gist options
  • Save tamakiii/5418948 to your computer and use it in GitHub Desktop.
Save tamakiii/5418948 to your computer and use it in GitHub Desktop.
<?php
class Hoge
{
/**
* "ID" が大文字."Id" ではない
*/
public function getID()
{
return 123;
}
}
class HogeTest extends PHPUnit_Framework_TestCase
{
public function test_HogeのgetIdの振る舞いが適切に書き換えられない()
{
// 実オブジェクトでは呼び出せる
$hoge = new Hoge;
var_dump($hoge->getId()); # => 123
// モック化すると…
$hoge = Phake::mock('Hoge');
Phake::when($hoge)->getId()->thenReturn(1);
var_dump($hoge->getId()); # => null
Phake::verify($hoge)->getId(); // 当然これも通らない
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment