Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Service/BrancherApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
class BrancherApp extends AbstractService
{
/**
* Create an brancher app for given parent app.
* Create a brancher app for given parent app.
*
* @param string $app Name of the parent app
* @param array|null $data Extra data to be provided
* @return string Name of the brancher app
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function create(string $app): string
public function create(string $app, ?array $data = null): string
{
$url = sprintf(App::V2_APP_BRANCHER_URL, $app);

$response = $this->client->api->post($url);
$response = $this->client->api->post($url, [], $data ? json_encode($data) : null);

$this->client->maybeThrowApiExceptions($response);

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/Service/BrancherAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ public function testCreateBrancherApp()
$this->assertEquals('johndoe-eph123456', $brancherAppName);
}

public function testCreateBrancherAppWithData()
{
$this->responses->append(
new Response(200, [], json_encode([
'name' => 'johndoe-eph123456',
'parent' => 'johndoe',
'type' => 'brancher',
])),
);

$brancherAppName = $this->client->brancherApp->create(
'johndoe',
['labels' => ['mybranchernode', 'mylabel=myvalue']]
);

$request = $this->responses->getLastRequest();
$this->assertEquals('POST', $request->getMethod());
$this->assertEquals('/v2/app/johndoe/brancher/', $request->getUri());
$this->assertEquals('johndoe-eph123456', $brancherAppName);
$this->assertJson((string)$request->getBody());
$this->assertEquals(
['labels' => ['mybranchernode', 'mylabel=myvalue']],
json_decode((string)$request->getBody(), true)
);
}

public function testCreateBrancherAppRaisesClientExceptions()
{
$badRequestResponse = new Response(400, [], json_encode([
Expand Down