|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Hypernode\Api\Service; |
| 6 | + |
| 7 | +use GuzzleHttp\Psr7\Response; |
| 8 | +use Hypernode\Api\Exception\HypernodeApiClientException; |
| 9 | +use Hypernode\Api\Exception\HypernodeApiServerException; |
| 10 | +use Hypernode\Api\HypernodeClientTestCase; |
| 11 | + |
| 12 | +class ProductTest extends HypernodeClientTestCase |
| 13 | +{ |
| 14 | + public function testGetList() |
| 15 | + { |
| 16 | + $products = [ |
| 17 | + [ |
| 18 | + 'code' => 'FALCON_XS_202203', |
| 19 | + 'name' => 'Falcon XS', |
| 20 | + 'backups_enabled' => true, |
| 21 | + 'is_development' => false, |
| 22 | + 'varnish_supported' => false, |
| 23 | + 'supports_sla' => true, |
| 24 | + 'price' => 1234, |
| 25 | + 'currency' => 'EUR', |
| 26 | + ], |
| 27 | + [ |
| 28 | + 'code' => 'FALCON_M_202203', |
| 29 | + 'name' => 'Falcon M', |
| 30 | + 'backups_enabled' => true, |
| 31 | + 'is_development' => false, |
| 32 | + 'varnish_supported' => true, |
| 33 | + 'supports_sla' => true, |
| 34 | + 'price' => 2345, |
| 35 | + 'currency' => 'EUR', |
| 36 | + ], |
| 37 | + ]; |
| 38 | + $this->responses->append( |
| 39 | + new Response(200, [], json_encode($products)), |
| 40 | + ); |
| 41 | + |
| 42 | + $result = $this->client->product->getList(); |
| 43 | + |
| 44 | + $request = $this->responses->getLastRequest(); |
| 45 | + $this->assertEquals('GET', $request->getMethod()); |
| 46 | + $this->assertEquals('/v2/product/', $request->getUri()); |
| 47 | + $this->assertEquals($products, $result); |
| 48 | + } |
| 49 | + |
| 50 | + public function testGetListRaisesClientExceptions() |
| 51 | + { |
| 52 | + $badRequestResponse = new Response(400, [], json_encode([ |
| 53 | + 'non_field_errors' => ['Your request was invalid.'] |
| 54 | + ])); |
| 55 | + $this->responses->append($badRequestResponse); |
| 56 | + |
| 57 | + $this->expectExceptionObject(new HypernodeApiClientException($badRequestResponse)); |
| 58 | + |
| 59 | + $this->client->product->getList(); |
| 60 | + } |
| 61 | + |
| 62 | + public function testGetListRaisesServerExceptions() |
| 63 | + { |
| 64 | + $badRequestResponse = new Response(500, [], json_encode([ |
| 65 | + 'non_field_errors' => ['Something went wrong processing your request.'] |
| 66 | + ])); |
| 67 | + $this->responses->append($badRequestResponse); |
| 68 | + |
| 69 | + $this->expectExceptionObject(new HypernodeApiServerException($badRequestResponse)); |
| 70 | + |
| 71 | + $this->client->product->getList(); |
| 72 | + } |
| 73 | +} |
0 commit comments