Skip to content

Instantly share code, notes, and snippets.

@paquettg
Last active January 4, 2016 19:49
Show Gist options
  • Save paquettg/8669675 to your computer and use it in GitHub Desktop.
Save paquettg/8669675 to your computer and use it in GitHub Desktop.
Sample phpunit test
<?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