@@ -88,6 +88,37 @@ public function testOutOfBoundsThrowsException()
8888 $ cachedKeySet ['bar ' ];
8989 }
9090
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+
91122 public function testWithExistingKeyId ()
92123 {
93124 $ cachedKeySet = new CachedKeySet (
@@ -382,6 +413,9 @@ private function getMockHttpClient($testJwks, int $timesCalled = 1)
382413 $ response ->getBody ()
383414 ->shouldBeCalledTimes ($ timesCalled )
384415 ->willReturn ($ body ->reveal ());
416+ $ response ->getStatusCode ()
417+ ->shouldBeCalledTimes ($ timesCalled )
418+ ->willReturn (200 );
385419
386420 $ http = $ this ->prophesize (ClientInterface::class);
387421 $ http ->sendRequest (Argument::any ())
0 commit comments