Last active
January 4, 2016 19:49
-
-
Save paquettg/8669675 to your computer and use it in GitHub Desktop.
Sample phpunit test
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
<?php | |
// set up the mock | |
class testUser extends PHPUnit_Test_Case { | |
public function testUserCreate() | |
{ | |
$user = Mockery::mock('models_user'); | |
$user->shouldReceive('select') | |
->once() | |
->with($id) | |
->andReturn($user); | |
$user->shouldReceive('isLoader') | |
->once() | |
->andReturn(false); | |
$user->shouldReceive('create') | |
->with($id, $username, $password) | |
->once() | |
->andReturn(true); | |
// initiate your controller | |
$controller = new Controllers_Users($user); // your inject the mock instead of the real user model | |
$_post['user'] = 'userinfo'; // set up the | |
$_server['http_verb'] = 'POST'; // fake php post verb | |
$response = $controller->create_user() // what ever the way you would inact the action | |
$this->assertEquals(['status' => 1], $response->toJson()); // or what ever | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment