diff --git a/src/Fakes/BausteinFake.php b/src/Fakes/BausteinFake.php index 3a9693b..67119a1 100644 --- a/src/Fakes/BausteinFake.php +++ b/src/Fakes/BausteinFake.php @@ -24,4 +24,15 @@ class BausteinFake extends Fake { return $this; } + public function failsToFetch(): self + { + Http::fake(function($request) { + if ($request->url() === "https://nami.dpsg.de/ica/rest/module/baustein") { + return $this->errorResponse('error'); + } + }); + + return $this; + } + } diff --git a/tests/Unit/BausteinTest.php b/tests/Unit/BausteinTest.php index def78a8..4e5a98d 100644 --- a/tests/Unit/BausteinTest.php +++ b/tests/Unit/BausteinTest.php @@ -35,4 +35,13 @@ class BausteinTest extends TestCase $this->assertEquals('abc', $courses->first()->name); } + public function test_throw_exception_when_baustein_fetching_fails(): void + { + $this->expectException(NamiException::class); + Auth::success(12345, 'secret'); + app(BausteinFake::class)->failsToFetch(); + + Nami::login(12345, 'secret')->courses(); + } + }