File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1010class 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
Original file line number Diff line number Diff 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 ([
You can’t perform that action at this time.
0 commit comments