Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Pashkevich committed Jul 15, 2021
1 parent 3adbd71 commit f42a764
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/Actions/ManagesReceipts.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public function receipt(string $receiptNumber): Receipt
* @param array $data
* @return Receipt
*/
public function createReceipt(array $data): Receipt
{
$item = $this->post('receipts', $data);

return new Receipt($item, $this);
}
// public function createReceipt(array $data): Receipt
// {
// $item = $this->post('receipts', $data);
//
// return new Receipt($item, $this);
// }

/**
* Create a refund receipt.
Expand Down
66 changes: 49 additions & 17 deletions tests/LoyverseSDKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Mockery;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Psr7\{Utils, Response};
use Pashkevich\Loyverse\{Loyverse, Exceptions};

/**
Expand All @@ -29,7 +29,9 @@ public function test_making_basic_requests()
);

$response->shouldReceive('getStatusCode')->once()->andReturn(200);
$response->shouldReceive('getBody')->once()->andReturn('{"employees": [{"key": "value"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"employees": [{"key": "value"}]}'));

$this->assertCount(1, $loyverse->employees());
}
Expand All @@ -45,7 +47,9 @@ public function test_handling_unknown_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(500);
$response->shouldReceive('getBody')->once()->andReturn('');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor());

$loyverse->employees();
}
Expand All @@ -61,7 +65,9 @@ public function test_handling_internal_server_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(500);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "INTERNAL_SERVER_ERROR"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "INTERNAL_SERVER_ERROR"}]}'));

$loyverse->employees();
}
Expand All @@ -77,7 +83,9 @@ public function test_handling_bad_request_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(400);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "BAD_REQUEST"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "BAD_REQUEST"}]}'));

$loyverse->employees();
}
Expand All @@ -93,7 +101,9 @@ public function test_handling_incorrect_value_type_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(400);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "INCORRECT_VALUE_TYPE"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "INCORRECT_VALUE_TYPE"}]}'));

$loyverse->employees();
}
Expand All @@ -109,7 +119,9 @@ public function test_handling_missing_required_parameter_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(400);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "MISSING_REQUIRED_PARAMETER"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "MISSING_REQUIRED_PARAMETER"}]}'));

$loyverse->employees();
}
Expand All @@ -125,7 +137,9 @@ public function test_handling_invalid_value_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(400);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "INVALID_VALUE"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "INVALID_VALUE"}]}'));

$loyverse->employees();
}
Expand All @@ -141,7 +155,9 @@ public function test_handling_invalid_range_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(400);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "INVALID_RANGE"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "INVALID_RANGE"}]}'));

$loyverse->employees();
}
Expand All @@ -157,7 +173,9 @@ public function test_handling_invalid_cursor_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(400);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "INVALID_CURSOR"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "INVALID_CURSOR"}]}'));

$loyverse->employees();
}
Expand All @@ -173,7 +191,9 @@ public function test_handling_conflicting_parameters_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(400);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "CONFLICTING_PARAMETERS"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "CONFLICTING_PARAMETERS"}]}'));

$loyverse->employees();
}
Expand All @@ -189,7 +209,9 @@ public function test_handling_unauthorized_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(401);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "UNAUTHORIZED"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "UNAUTHORIZED"}]}'));

$loyverse->employees();
}
Expand All @@ -205,7 +227,9 @@ public function test_handling_payment_required_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(402);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "PAYMENT_REQUIRED"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "PAYMENT_REQUIRED"}]}'));

$loyverse->employees();
}
Expand All @@ -221,7 +245,9 @@ public function test_handling_forbidden_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(403);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "FORBIDDEN"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "FORBIDDEN"}]}'));

$loyverse->employees();
}
Expand All @@ -237,7 +263,9 @@ public function test_handling_not_found_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(404);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "NOT_FOUND"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "NOT_FOUND"}]}'));

$loyverse->employees();
}
Expand All @@ -253,7 +281,9 @@ public function test_handling_unsupported_media_type_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(415);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "UNSUPPORTED_MEDIA_TYPE"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "UNSUPPORTED_MEDIA_TYPE"}]}'));

$loyverse->employees();
}
Expand All @@ -269,7 +299,9 @@ public function test_handling_rate_limited_exception()
);

$response->shouldReceive('getStatusCode')->andReturn(429);
$response->shouldReceive('getBody')->once()->andReturn('{"errors": [{"code": "RATE_LIMITED"}]}');
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"errors": [{"code": "RATE_LIMITED"}]}'));

$loyverse->employees();
}
Expand Down

0 comments on commit f42a764

Please sign in to comment.