|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Hypernode\Api\Service; |
| 4 | + |
| 5 | +use GuzzleHttp\Psr7\Response; |
| 6 | +use Hypernode\Api\HypernodeClientTestCase; |
| 7 | + |
| 8 | +class SettingsTest extends HypernodeClientTestCase |
| 9 | +{ |
| 10 | + public function testSetSingleSettingToSameValue() |
| 11 | + { |
| 12 | + $this->responses->append( |
| 13 | + new Response(200, [], null), |
| 14 | + ); |
| 15 | + |
| 16 | + $job = $this->client->settings->set('johndoe', 'php_version', '8.1'); |
| 17 | + |
| 18 | + $request = $this->responses->getLastRequest(); |
| 19 | + |
| 20 | + $this->assertNull($job); |
| 21 | + $this->assertEquals('PATCH', $request->getMethod()); |
| 22 | + $this->assertEquals('/v2/app/johndoe/', $request->getUri()); |
| 23 | + $this->assertJson($request->getBody()); |
| 24 | + $this->assertEquals( |
| 25 | + ['php_version' => '8.1'], |
| 26 | + json_decode($request->getBody(), true) |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + public function testSetSingleSettingToDifferentValue() |
| 31 | + { |
| 32 | + $jobUrl = 'https://api.hypernode.com/logbook/v1/jobs/abcd/'; |
| 33 | + $this->responses->append( |
| 34 | + new Response(202, ['Location: ' . $jobUrl], null), |
| 35 | + ); |
| 36 | + |
| 37 | + $job = $this->client->settings->set('johndoe', 'php_version', '8.1'); |
| 38 | + |
| 39 | + $request = $this->responses->getLastRequest(); |
| 40 | + |
| 41 | + $this->assertNotNull($job); |
| 42 | + $this->assertEquals('PATCH', $request->getMethod()); |
| 43 | + $this->assertEquals('/v2/app/johndoe/', $request->getUri()); |
| 44 | + $this->assertJson($request->getBody()); |
| 45 | + $this->assertEquals( |
| 46 | + ['php_version' => '8.1'], |
| 47 | + json_decode($request->getBody(), true) |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + public function testSetMultipleSettings() |
| 52 | + { |
| 53 | + $jobUrl = 'https://api.hypernode.com/logbook/v1/jobs/abcd/'; |
| 54 | + $this->responses->append( |
| 55 | + new Response(202, ['Location: ' . $jobUrl], null), |
| 56 | + ); |
| 57 | + |
| 58 | + $job = $this->client->settings->setBatch( |
| 59 | + 'johndoe', |
| 60 | + [ |
| 61 | + 'php_version' => '8.1', |
| 62 | + 'nodejs_version' => '18' |
| 63 | + ] |
| 64 | + ); |
| 65 | + |
| 66 | + $request = $this->responses->getLastRequest(); |
| 67 | + |
| 68 | + $this->assertNotNull($job); |
| 69 | + $this->assertEquals('PATCH', $request->getMethod()); |
| 70 | + $this->assertEquals('/v2/app/johndoe/', $request->getUri()); |
| 71 | + $this->assertJson($request->getBody()); |
| 72 | + $this->assertEquals( |
| 73 | + [ |
| 74 | + 'php_version' => '8.1', |
| 75 | + 'nodejs_version' => '18' |
| 76 | + ], |
| 77 | + json_decode($request->getBody(), true) |
| 78 | + ); |
| 79 | + } |
| 80 | +} |
0 commit comments