Skip to content

Instantly share code, notes, and snippets.

@Zetzumarshen
Last active May 17, 2016 03:50
Show Gist options
  • Save Zetzumarshen/301cddfea1f9c451d2a01a3a9a758f99 to your computer and use it in GitHub Desktop.
Save Zetzumarshen/301cddfea1f9c451d2a01a3a9a758f99 to your computer and use it in GitHub Desktop.
// Testingclass untuk User.php
// pakai TestCase karena gw pakai kenjis testing framework
Class User_test extends TestCase
{
public function test_mockUsername(){
// secara implisit, melakukan mock ke method getPost()
// sekarang getPost() akan return NULL
$model = $this->getMockBuilder('Users')
->setMethods(array('getUsername'))
->getMock();
// sekarang kita buat getPost() return 'Dimas'
$model->expects($this->once())
->method('getUsername')
->willReturn('Dimas')
// public function getUsername(){
// return $this->getPost(); // akan return 'Dimas'
// }
// green test
$this->assertEquals('Dimas', $model->getUsername());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment