@@ -88,6 +88,37 @@ public function testOutOfBoundsThrowsException()
88
88
$ cachedKeySet ['bar ' ];
89
89
}
90
90
91
+ public function testInvalidHttpResponseThrowsException ()
92
+ {
93
+ $ this ->expectException (\UnexpectedValueException::class);
94
+ $ this ->expectExceptionMessage ('HTTP Error: 404 URL not found ' );
95
+ $ this ->expectExceptionCode (404 );
96
+
97
+ $ body = $ this ->prophesize ('Psr\Http\Message\StreamInterface ' );
98
+
99
+ $ response = $ this ->prophesize ('Psr\Http\Message\ResponseInterface ' );
100
+ $ response ->getStatusCode ()
101
+ ->shouldBeCalled ()
102
+ ->willReturn (404 );
103
+ $ response ->getReasonPhrase ()
104
+ ->shouldBeCalledTimes (1 )
105
+ ->willReturn ('URL not found ' );
106
+
107
+ $ http = $ this ->prophesize (ClientInterface::class);
108
+ $ http ->sendRequest (Argument::any ())
109
+ ->shouldBeCalledTimes (1 )
110
+ ->willReturn ($ response ->reveal ());
111
+
112
+ $ cachedKeySet = new CachedKeySet (
113
+ $ this ->testJwksUri ,
114
+ $ http ->reveal (),
115
+ $ this ->getMockHttpFactory (),
116
+ $ this ->getMockEmptyCache ()
117
+ );
118
+
119
+ isset ($ cachedKeySet [0 ]);
120
+ }
121
+
91
122
public function testWithExistingKeyId ()
92
123
{
93
124
$ cachedKeySet = new CachedKeySet (
@@ -382,6 +413,9 @@ private function getMockHttpClient($testJwks, int $timesCalled = 1)
382
413
$ response ->getBody ()
383
414
->shouldBeCalledTimes ($ timesCalled )
384
415
->willReturn ($ body ->reveal ());
416
+ $ response ->getStatusCode ()
417
+ ->shouldBeCalledTimes ($ timesCalled )
418
+ ->willReturn (200 );
385
419
386
420
$ http = $ this ->prophesize (ClientInterface::class);
387
421
$ http ->sendRequest (Argument::any ())
0 commit comments