Skip to content

Commit 742a59b

Browse files
authored
Merge pull request #7 from ByteInternet/brancher_create_data
2 parents 01f8bf2 + dda1ac8 commit 742a59b

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/Service/BrancherApp.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
class BrancherApp extends AbstractService
1111
{
1212
/**
13-
* Create an brancher app for given parent app.
13+
* Create a brancher app for given parent app.
1414
*
1515
* @param string $app Name of the parent app
16+
* @param array|null $data Extra data to be provided
1617
* @return string Name of the brancher app
1718
* @throws HypernodeApiClientException
1819
* @throws HypernodeApiServerException
1920
*/
20-
public function create(string $app): string
21+
public function create(string $app, ?array $data = null): string
2122
{
2223
$url = sprintf(App::V2_APP_BRANCHER_URL, $app);
2324

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

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

tests/unit/Service/BrancherAppTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@ public function testCreateBrancherApp()
2929
$this->assertEquals('johndoe-eph123456', $brancherAppName);
3030
}
3131

32+
public function testCreateBrancherAppWithData()
33+
{
34+
$this->responses->append(
35+
new Response(200, [], json_encode([
36+
'name' => 'johndoe-eph123456',
37+
'parent' => 'johndoe',
38+
'type' => 'brancher',
39+
])),
40+
);
41+
42+
$brancherAppName = $this->client->brancherApp->create(
43+
'johndoe',
44+
['labels' => ['mybranchernode', 'mylabel=myvalue']]
45+
);
46+
47+
$request = $this->responses->getLastRequest();
48+
$this->assertEquals('POST', $request->getMethod());
49+
$this->assertEquals('/v2/app/johndoe/brancher/', $request->getUri());
50+
$this->assertEquals('johndoe-eph123456', $brancherAppName);
51+
$this->assertJson((string)$request->getBody());
52+
$this->assertEquals(
53+
['labels' => ['mybranchernode', 'mylabel=myvalue']],
54+
json_decode((string)$request->getBody(), true)
55+
);
56+
}
57+
3258
public function testCreateBrancherAppRaisesClientExceptions()
3359
{
3460
$badRequestResponse = new Response(400, [], json_encode([

0 commit comments

Comments
 (0)