Skip to content

Instantly share code, notes, and snippets.

@aleferreiranogueira
Created November 10, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleferreiranogueira/f3311582abaab828ec88e72b2cc8781e to your computer and use it in GitHub Desktop.
Save aleferreiranogueira/f3311582abaab828ec88e72b2cc8781e to your computer and use it in GitHub Desktop.
Mockery example
$user = [
"username" => $post['username'],
"password" => $post['password'],
"name" => $post['name'],
];
// Simple Mock
$mock_class = SomeDamnClass::class;
$mock = Mockery::mock($nero_class);
$mock->shouldReceive('getUserByUsername')
->times(1)
->with($user)
->andReturn(false);
// Chained Method mock
$mock->shouldReceive('getErrorMessage->getMessage')
->times(1)
->withAnyArgs()
->andReturn('
{
"errors": [
"The username has already been taken"
]
}
');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment