|
| 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 EphemeralAppTest extends HypernodeClientTestCase |
| 13 | +{ |
| 14 | + public function testCreateEphemeralApp() |
| 15 | + { |
| 16 | + $this->responses->append( |
| 17 | + new Response(200, [], json_encode([ |
| 18 | + 'name' => 'johndoe-eph123456', |
| 19 | + 'parent' => 'johndoe', |
| 20 | + 'type' => 'ephemeral', |
| 21 | + ])), |
| 22 | + ); |
| 23 | + |
| 24 | + $ephemeralAppName = $this->client->ephemeralApp->create('johndoe'); |
| 25 | + |
| 26 | + $request = $this->responses->getLastRequest(); |
| 27 | + $this->assertEquals('POST', $request->getMethod()); |
| 28 | + $this->assertEquals('/v2/app/johndoe/ephemeral/', $request->getUri()); |
| 29 | + $this->assertEquals('johndoe-eph123456', $ephemeralAppName); |
| 30 | + } |
| 31 | + |
| 32 | + public function testCreateEphemeralAppRaisesClientExceptions() |
| 33 | + { |
| 34 | + $badRequestResponse = new Response(400, [], json_encode([ |
| 35 | + 'non_field_errors' => ['Your request was invalid.'] |
| 36 | + ])); |
| 37 | + $this->responses->append($badRequestResponse); |
| 38 | + |
| 39 | + $this->expectExceptionObject(new HypernodeApiClientException($badRequestResponse)); |
| 40 | + |
| 41 | + $this->client->ephemeralApp->create('johndoe'); |
| 42 | + } |
| 43 | + |
| 44 | + public function testCreateEphemeralAppRaisesServerExceptions() |
| 45 | + { |
| 46 | + $badRequestResponse = new Response(500, [], json_encode([ |
| 47 | + 'non_field_errors' => ['Something went wrong processing your request.'] |
| 48 | + ])); |
| 49 | + $this->responses->append($badRequestResponse); |
| 50 | + |
| 51 | + $this->expectExceptionObject(new HypernodeApiServerException($badRequestResponse)); |
| 52 | + |
| 53 | + $this->client->ephemeralApp->create('johndoe'); |
| 54 | + } |
| 55 | + |
| 56 | + public function testCancelEphemeralApp() |
| 57 | + { |
| 58 | + $this->responses->append( |
| 59 | + new Response(204, [], null), |
| 60 | + ); |
| 61 | + |
| 62 | + $this->client->ephemeralApp->cancel('johndoe-eph123456'); |
| 63 | + |
| 64 | + $request = $this->responses->getLastRequest(); |
| 65 | + $this->assertEquals('DELETE', $request->getMethod()); |
| 66 | + $this->assertEquals('/v2/app/johndoe-eph123456/cancel/', $request->getUri()); |
| 67 | + } |
| 68 | + |
| 69 | + public function testCancelEphemeralAppRaisesClientExceptions() |
| 70 | + { |
| 71 | + $badRequestResponse = new Response(400, [], json_encode([ |
| 72 | + 'non_field_errors' => ['Your request was invalid.'] |
| 73 | + ])); |
| 74 | + $this->responses->append($badRequestResponse); |
| 75 | + |
| 76 | + $this->expectExceptionObject(new HypernodeApiClientException($badRequestResponse)); |
| 77 | + |
| 78 | + $this->client->ephemeralApp->cancel('johndoe'); |
| 79 | + } |
| 80 | + |
| 81 | + public function testCancelEphemeralAppRaisesServerExceptions() |
| 82 | + { |
| 83 | + $badRequestResponse = new Response(500, [], json_encode([ |
| 84 | + 'non_field_errors' => ['Something went wrong processing your request.'] |
| 85 | + ])); |
| 86 | + $this->responses->append($badRequestResponse); |
| 87 | + |
| 88 | + $this->expectExceptionObject(new HypernodeApiServerException($badRequestResponse)); |
| 89 | + |
| 90 | + $this->client->ephemeralApp->cancel('johndoe'); |
| 91 | + } |
| 92 | +} |
0 commit comments