Skip to content

Instantly share code, notes, and snippets.

@rslhdyt
Created April 20, 2019 16:41
Show Gist options
  • Save rslhdyt/b34bacc49f22d57681bfe112b0a8deaf to your computer and use it in GitHub Desktop.
Save rslhdyt/b34bacc49f22d57681bfe112b0a8deaf to your computer and use it in GitHub Desktop.
[Mock Koperasi Api Request] example mocking koperasi io request #mocking #phpunit #laravel
<?php
...
/**
* A basic test example.
*
* @return void
*/
public function testSearchPageResult()
{
// Create a mock and queue two responses.
$mockUser = \Mockery::mock(\KoperasiIo\KoperasiApi\Api\User::class, ['getMember' => ['data' => [
'id' => 1,
'name' => 'Foo',
'number' => '1234',
'gender' => 'Male',
'photo_url' => 'http://photo.com/image.jpg'
]]]);
$mock = \Mockery::mock(\KoperasiIo\KoperasiApi\KoperasiApi::class, ['user' => $mockUser]);
$this->app->instance(\KoperasiIo\KoperasiApi\KoperasiApi::class, $mock);
$response = $this->actingAs($this->authUser)
->get('deposits/transactions/search?' . http_build_query([
'member_id' => 1,
'deposit_type_id' => 1,
'start_date' => '2018-01-01',
'end_date' => '2018-01-02',
]));
$response->assertStatus(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment