-
Notifications
You must be signed in to change notification settings - Fork 82
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 #15 from HD-CMS/feature/namespace-resource
Add Namespace Resource
- Loading branch information
Showing
11 changed files
with
137 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/vendor | ||
/coverage | ||
/clover.xml | ||
/composer.lock | ||
/composer.lock | ||
/.idea |
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
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,31 @@ | ||
<?php namespace Maclof\Kubernetes\Collections; | ||
|
||
use Maclof\Kubernetes\Models\NamespaceModel; | ||
|
||
class NamespaceCollection extends Collection | ||
{ | ||
/** | ||
* The constructor. | ||
* | ||
* @param array $data | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
parent::__construct($this->getNamespaces(isset($data['items']) ? $data['items'] : [])); | ||
} | ||
|
||
/** | ||
* Get an array of Namespaces. | ||
* | ||
* @param array $items | ||
* @return array | ||
*/ | ||
protected function getNamespaces(array $items) | ||
{ | ||
foreach ($items as &$item) { | ||
$item = new NamespaceModel($item); | ||
} | ||
|
||
return $items; | ||
} | ||
} |
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,11 @@ | ||
<?php namespace Maclof\Kubernetes\Models; | ||
|
||
class NamespaceModel extends Model | ||
{ | ||
/** | ||
* The schema. | ||
* | ||
* @var array | ||
*/ | ||
protected $schema = ['kind' => 'Namespace']; | ||
} |
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,14 @@ | ||
<?php namespace Maclof\Kubernetes\Repositories; | ||
|
||
use Maclof\Kubernetes\Collections\NamespaceCollection; | ||
|
||
class NamespaceRepository extends Repository | ||
{ | ||
protected $uri = 'namespaces'; | ||
protected $namespace = false; | ||
|
||
protected function createCollection($response) | ||
{ | ||
return new NamespaceCollection($response); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
use Maclof\Kubernetes\Collections\NamespaceCollection; | ||
|
||
class NamespaceCollectionTest extends TestCase | ||
{ | ||
protected $items = [ | ||
[], | ||
[], | ||
[], | ||
]; | ||
|
||
protected function getNamespaceCollection() | ||
{ | ||
$namespaceCollection = new NamespaceCollection([ | ||
'items' => $this->items, | ||
]); | ||
|
||
return $namespaceCollection; | ||
} | ||
|
||
public function test_get_items() | ||
{ | ||
$namespaceCollection = $this->getNamespaceCollection(); | ||
$items = $namespaceCollection->toArray(); | ||
|
||
$this->assertTrue(is_array($items)); | ||
$this->assertEquals(3, count($items)); | ||
} | ||
} |
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,4 @@ | ||
{ | ||
"kind": "Namespace", | ||
"apiVersion": "v1" | ||
} |
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,29 @@ | ||
<?php | ||
|
||
use Maclof\Kubernetes\Models\NamespaceModel; | ||
|
||
class NamespaceTest extends TestCase | ||
{ | ||
public function test_get_schema() | ||
{ | ||
$namespace = new NamespaceModel; | ||
|
||
$schema = $namespace->getSchema(); | ||
$fixture = $this->getFixture('namespaces/empty.json'); | ||
|
||
$this->assertEquals($schema, $fixture); | ||
} | ||
|
||
public function test_get_metadata() | ||
{ | ||
$node = new NamespaceModel([ | ||
'metadata' => [ | ||
'name' => 'test', | ||
], | ||
]); | ||
|
||
$metadata = $node->getMetadata('name'); | ||
|
||
$this->assertEquals($metadata, 'test'); | ||
} | ||
} |