From 55b5b8749a927cb4c2e9fa210775f39e0e7c256d Mon Sep 17 00:00:00 2001 From: Sammyjo20 <29132017+Sammyjo20@users.noreply.github.com> Date: Wed, 13 Apr 2022 19:31:12 +0100 Subject: [PATCH 1/2] Mock exceptions --- tests/Unit/MockClientAssertionsTest.php | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Unit/MockClientAssertionsTest.php b/tests/Unit/MockClientAssertionsTest.php index 63ee44e..66a7b33 100644 --- a/tests/Unit/MockClientAssertionsTest.php +++ b/tests/Unit/MockClientAssertionsTest.php @@ -1,5 +1,6 @@ 'Sam']), + MockResponse::make(['name' => 'Patrick'])->throw(fn ($guzzleRequest) => new ConnectException('Unable to connect!', $guzzleRequest)), + ]); + + $okResponse = (new UserRequest)->send(); + + expect($okResponse->json())->toEqual(['name' => 'Sam']); + + $this->expectException(ConnectException::class); + $this->expectExceptionMessage('Unable to connect!'); + + (new UserRequest())->send(); +}); + +test('you can mock normal exceptions', function () { + Saloon::fake([ + MockResponse::make(['name' => 'Michael'])->throw(new Exception('Custom Exception!')), + ]); + + $this->expectException(Exception::class); + $this->expectExceptionMessage('Custom Exception!'); + + (new UserRequest())->send(); +}); From 8858bed5124db61e993732a104ba30ac07d58c18 Mon Sep 17 00:00:00 2001 From: Sammyjo20 <29132017+Sammyjo20@users.noreply.github.com> Date: Wed, 13 Apr 2022 19:37:20 +0100 Subject: [PATCH 2/2] Upgraded Saloon --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 437d6bb..03d28f7 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "^8.0", "illuminate/support": "^8.0|^9.0", "illuminate/console": "^8.0|^9.0", - "sammyjo20/saloon": "^0.10.0" + "sammyjo20/saloon": "^0.11.0" }, "extra": { "laravel": {