|
4 | 4 |
|
5 | 5 | use Exonet\Api\Auth\PersonalAccessToken; |
6 | 6 | use Exonet\Api\Exceptions\AuthenticationException; |
| 7 | +use Exonet\Api\Exceptions\ValidationException; |
7 | 8 | use Exonet\Api\Structures\ApiResource; |
8 | 9 | use Exonet\Api\Structures\ApiResourceSet; |
9 | 10 | use GuzzleHttp\Handler\MockHandler; |
@@ -210,4 +211,64 @@ public function testDelete() |
210 | 211 | $this->assertSame('exonet-api-php/'.Client::CLIENT_VERSION, $request->getHeader('User-Agent')[0]); |
211 | 212 | $this->assertSame('application/json', $request->getHeader('Content-Type')[0]); |
212 | 213 | } |
| 214 | + |
| 215 | + public function testInvalidPatch() |
| 216 | + { |
| 217 | + $apiCalls = []; |
| 218 | + $mock = new MockHandler([ |
| 219 | + new Response( |
| 220 | + 422, |
| 221 | + [], |
| 222 | + '{"errors":[{"status":422,"code":"102.10001","title":"validation.generic","detail":"Validation did not pass.","variables":[]}]}' |
| 223 | + ), |
| 224 | + ]); |
| 225 | + |
| 226 | + $history = Middleware::history($apiCalls); |
| 227 | + $handler = HandlerStack::create($mock); |
| 228 | + $handler->push($history); |
| 229 | + |
| 230 | + new Client(new PersonalAccessToken('test-token')); |
| 231 | + $connectorClass = new Connector($handler); |
| 232 | + |
| 233 | + $payload = ['test' => 'demo']; |
| 234 | + |
| 235 | + try { |
| 236 | + $connectorClass->patch('url', $payload); |
| 237 | + } catch (ValidationException $exception) { |
| 238 | + $validationTested = true; |
| 239 | + $this->assertSame($exception->getMessage(), 'There is 1 validation error.'); |
| 240 | + $this->assertCount(1, $exception->getFailedValidations()); |
| 241 | + $this->assertSame('Validation did not pass.', $exception->getFailedValidations()['generic'][0]); |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + public function testInvalidDelete() |
| 246 | + { |
| 247 | + $apiCalls = []; |
| 248 | + $mock = new MockHandler([ |
| 249 | + new Response( |
| 250 | + 422, |
| 251 | + [], |
| 252 | + '{"errors":[{"status":422,"code":"102.10001","title":"validation.generic","detail":"Validation did not pass.","variables":[]}]}' |
| 253 | + ), |
| 254 | + ]); |
| 255 | + |
| 256 | + $history = Middleware::history($apiCalls); |
| 257 | + $handler = HandlerStack::create($mock); |
| 258 | + $handler->push($history); |
| 259 | + |
| 260 | + new Client(new PersonalAccessToken('test-token')); |
| 261 | + $connectorClass = new Connector($handler); |
| 262 | + |
| 263 | + $payload = ['test' => 'demo']; |
| 264 | + |
| 265 | + try { |
| 266 | + $connectorClass->patch('url', $payload); |
| 267 | + } catch (ValidationException $exception) { |
| 268 | + $validationTested = true; |
| 269 | + $this->assertSame($exception->getMessage(), 'There is 1 validation error.'); |
| 270 | + $this->assertCount(1, $exception->getFailedValidations()); |
| 271 | + $this->assertSame('Validation did not pass.', $exception->getFailedValidations()['generic'][0]); |
| 272 | + } |
| 273 | + } |
213 | 274 | } |
0 commit comments