Last active
May 17, 2016 03:50
-
-
Save Zetzumarshen/301cddfea1f9c451d2a01a3a9a758f99 to your computer and use it in GitHub Desktop.
This file contains 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
// 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