-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ByteInternet/app_list
- Loading branch information
Showing
4 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hypernode\Api\Resource; | ||
|
||
use Hypernode\Api\HypernodeClient; | ||
use Hypernode\Api\Resource\AbstractResource; | ||
|
||
/** | ||
* @property-read string $name | ||
* @property-read string $type | ||
* @property-read string|null $parent | ||
*/ | ||
class App extends AbstractResource | ||
{ | ||
protected HypernodeClient $client; | ||
|
||
public function __construct(HypernodeClient $client, array $data = []) | ||
{ | ||
$this->client = $client; | ||
$this->data = $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hypernode\Api\Service; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Hypernode\Api\HypernodeClientTestCase; | ||
|
||
class AppTest extends HypernodeClientTestCase | ||
{ | ||
public function testGetList() | ||
{ | ||
$this->responses->append( | ||
new Response(200, [], json_encode([ | ||
'next' => null, | ||
'results' => [ | ||
[ | ||
'name' => 'johndoe', | ||
'type' => 'persistent', | ||
'product' => 'FALCON_M_202203', | ||
], | ||
[ | ||
'name' => 'tdgroot', | ||
'type' => 'persistent', | ||
'product' => 'FALCON_M_202203', | ||
], | ||
] | ||
])), | ||
); | ||
|
||
$result = $this->client->app->getList(); | ||
|
||
$this->assertCount(2, $result); | ||
$this->assertContainsOnlyInstancesOf(\Hypernode\Api\Resource\App::class, $result); | ||
$this->assertEquals('johndoe', $result[0]->name); | ||
$this->assertEquals('tdgroot', $result[1]->name); | ||
|
||
$request = $this->responses->getLastRequest(); | ||
$this->assertEquals('GET', $request->getMethod()); | ||
$this->assertEquals('/v2/app/', $request->getUri()); | ||
} | ||
|
||
public function testGetListAcceptsParams() | ||
{ | ||
$this->responses->append( | ||
new Response(200, [], json_encode([ | ||
'next' => null, | ||
'results' => [ | ||
[ | ||
'name' => 'johndoe', | ||
'type' => 'persistent', | ||
'parent' => null, | ||
'product' => 'FALCON_M_202203', | ||
], | ||
[ | ||
'name' => 'tdgroot', | ||
'type' => 'persistent', | ||
'parent' => 'johndoe', | ||
'product' => 'FALCON_M_202203', | ||
], | ||
] | ||
])), | ||
); | ||
|
||
$result = $this->client->app->getList(['parent' => 'johndoe']); | ||
|
||
$this->assertCount(2, $result); | ||
$this->assertContainsOnlyInstancesOf(\Hypernode\Api\Resource\App::class, $result); | ||
$this->assertEquals('johndoe', $result[0]->name); | ||
$this->assertEquals('tdgroot', $result[1]->name); | ||
$this->assertEquals('johndoe', $result[1]->parent); | ||
|
||
$request = $this->responses->getLastRequest(); | ||
$this->assertEquals('GET', $request->getMethod()); | ||
$this->assertEquals('/v2/app/?parent=johndoe', $request->getUri()); | ||
} | ||
|
||
public function testGetListPaginates() | ||
{ | ||
$this->responses->append( | ||
new Response(200, [], json_encode([ | ||
'next' => 'https://api.hypernode.com/v2/app/?limit=1&offset=1', | ||
'results' => [ | ||
[ | ||
'name' => 'johndoe', | ||
'type' => 'persistent', | ||
'product' => 'FALCON_M_202203', | ||
], | ||
] | ||
])), | ||
new Response(200, [], json_encode([ | ||
'next' => null, | ||
'results' => [ | ||
[ | ||
'name' => 'tdgroot', | ||
'type' => 'persistent', | ||
'product' => 'FALCON_M_202203', | ||
], | ||
] | ||
])), | ||
); | ||
|
||
$result = $this->client->app->getList(); | ||
|
||
$this->assertCount(2, $result); | ||
$this->assertContainsOnlyInstancesOf(\Hypernode\Api\Resource\App::class, $result); | ||
$this->assertEquals('johndoe', $result[0]->name); | ||
$this->assertEquals('tdgroot', $result[1]->name); | ||
|
||
$request = $this->responses->getLastRequest(); | ||
$this->assertEquals('GET', $request->getMethod()); | ||
$this->assertEquals('https://api.hypernode.com/v2/app/?limit=1&offset=1', $request->getUri()); | ||
} | ||
} |