Skip to content

Commit

Permalink
✅ Add test for throwing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonJnsson committed Jan 18, 2024
1 parent 91b6117 commit 28b144c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Unit/DriverTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Http\Client\Request;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;
use Morningtrain\Economic\Resources\Customer;

Expand Down Expand Up @@ -33,3 +34,26 @@
];
});
});

it('does not throw on 404', function () {
Http::fake([
'https://restapi.e-conomic.com/customers/1' => Http::response([], 404),
]);

Customer::find(1);
})->throwsNoExceptions();

it('throws on error status code', function (int $statusCode) {
Http::fake([
'https://restapi.e-conomic.com/customers/1' => Http::response([], $statusCode),
]);

Customer::find(1);
})
->throws(RequestException::class)
->with([
400,
401,
403,
500,
]);

0 comments on commit 28b144c

Please sign in to comment.