Created
November 10, 2017 17:07
-
-
Save aleferreiranogueira/f3311582abaab828ec88e72b2cc8781e to your computer and use it in GitHub Desktop.
Mockery example
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
$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