|
40 | 40 |
|
41 | 41 | use GuzzleHttp\Client; |
42 | 42 | use GuzzleHttp\Handler\MockHandler; |
| 43 | +use GuzzleHttp\HandlerStack; |
43 | 44 | use GuzzleHttp\Psr7\Response; |
44 | 45 | use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; |
45 | 46 | use OpenConext\EngineBlock\Http\Exception\AccessDeniedException; |
46 | 47 | use OpenConext\EngineBlock\Http\Exception\MalformedResponseException; |
| 48 | +use OpenConext\EngineBlock\Http\Exception\UnreadableResourceException; |
47 | 49 | use PHPUnit\Framework\Attributes\Group; |
48 | 50 | use PHPUnit\Framework\Attributes\Test; |
49 | 51 | use PHPUnit\Framework\TestCase; |
@@ -196,4 +198,36 @@ public function an_access_denied_exception_is_thrown_if_the_response_status_code |
196 | 198 |
|
197 | 199 | $client->post('post-and-give-me/403', 'Post body'); |
198 | 200 | } |
| 201 | + |
| 202 | + #[Group('EngineBlock')] |
| 203 | + #[Group('Http')] |
| 204 | + #[Test] |
| 205 | + public function an_unreadable_resource_exception_is_thrown_if_the_response_status_code_is_400_when_reading() |
| 206 | + { |
| 207 | + $mockHandler = new MockHandler([ |
| 208 | + new Response(400, [], '{"error":"Bad Request"}') |
| 209 | + ]); |
| 210 | + $guzzle = new Client(['handler' => HandlerStack::create($mockHandler)]); |
| 211 | + $client = new HttpClient($guzzle); |
| 212 | + |
| 213 | + $this->expectException(UnreadableResourceException::class); |
| 214 | + |
| 215 | + $client->read('/some-resource'); |
| 216 | + } |
| 217 | + |
| 218 | + #[Group('EngineBlock')] |
| 219 | + #[Group('Http')] |
| 220 | + #[Test] |
| 221 | + public function an_unreadable_resource_exception_is_thrown_if_the_response_status_code_is_400_when_posting() |
| 222 | + { |
| 223 | + $mockHandler = new MockHandler([ |
| 224 | + new Response(400, [], '{"error":"Bad Request"}') |
| 225 | + ]); |
| 226 | + $guzzle = new Client(['handler' => HandlerStack::create($mockHandler)]); |
| 227 | + $client = new HttpClient($guzzle); |
| 228 | + |
| 229 | + $this->expectException(UnreadableResourceException::class); |
| 230 | + |
| 231 | + $client->post('{"id":1}', '/some-resource'); |
| 232 | + } |
199 | 233 | } |
0 commit comments