Skip to content
Closed
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"psr/link": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.0 || ^7.0 || ^6.4 || ^5.7 || ^4.8.35"
},
"minimum-stability": "dev",
"autoload": {
Expand Down
6 changes: 3 additions & 3 deletions src/Hal.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ public function addHalLink($rel, HalLink $link, $forceArray = false)
* Add an embedded resource, identified by $rel and represented by $resource.
*
* @param string $rel
* @param \Nocarrier\Hal $resource
* @param \Nocarrier\Hal|null $resource
*
* @return \Nocarrier\Hal
*/
public function addResource($rel, \Nocarrier\Hal $resource = null, $forceArray = true)
public function addResource($rel, $resource = null, $forceArray = true)
{
if (!is_string($rel)) {
throw new \InvalidArgumentException(
Expand Down Expand Up @@ -231,7 +231,7 @@ public function setResource($rel, $resource)
/**
* Set resource's data
*/
public function setData(Array $data = null)
public function setData($data = null)
{
$this->data = $data;
return $this;
Expand Down
6 changes: 4 additions & 2 deletions src/HalJsonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,17 @@ protected function stripAttributeMarker(array $data)
* Return an array (compatible with the hal+json format) representing the
* complete response.
*
* @param \Nocarrier\Hal $resource
* @param \Nocarrier\Hal|null $resource
* @return array
*/
protected function arrayForJson(Hal $resource = null)
protected function arrayForJson($resource = null)
{
if ($resource == null) {
return array();
}

assert($resource instanceof Hal);

$data = $resource->getData();
if ($resource->getShouldStripAttributes()) {
$data = $this->stripAttributeMarker($data);
Expand Down
14 changes: 6 additions & 8 deletions tests/Hal/HalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testResourceJsonResponse()

$resource = json_decode($hal->asJson());
$this->assertInstanceOf('StdClass', $resource->_embedded);
$this->assertInternalType('array', $resource->_embedded->resource);
$this->assertIsArray( $resource->_embedded->resource);
$this->assertEquals($resource->_embedded->resource[0]->_links->self->href, '/resource/1');
$this->assertEquals($resource->_embedded->resource[0]->field1, 'value1');
$this->assertEquals($resource->_embedded->resource[0]->field2, 'value2');
Expand Down Expand Up @@ -150,7 +150,7 @@ public function testEmbeddedResourceInResourceJsonResponse()

$hal->addResource('resource', $res);
$result = json_decode($hal->asJson());
$this->assertInternalType('array', $result->_embedded->resource[0]->_embedded->item);
$this->assertIsArray( $result->_embedded->resource[0]->_embedded->item);
$this->assertEquals('/resource/1/item/1', $result->_embedded->resource[0]->_embedded->item[0]->_links->self->href);
$this->assertEquals('itemValue1', $result->_embedded->resource[0]->_embedded->item[0]->itemField1);
}
Expand Down Expand Up @@ -513,7 +513,7 @@ public function testAddCurieConformsToSpecification()
$x = new Hal('/orders');
$x->addCurie('acme', 'http://docs.acme.com/relations/{rel}');
$obj = json_decode($x->asJson());
$this->assertInternalType('array', $obj->_links->curies);
$this->assertIsArray( $obj->_links->curies);
$this->assertTrue($obj->_links->curies[0]->templated);
$this->assertEquals('acme', $obj->_links->curies[0]->name);
$this->assertEquals('http://docs.acme.com/relations/{rel}', $obj->_links->curies[0]->href);
Expand Down Expand Up @@ -624,7 +624,7 @@ public function testSetResourceWithArrayOfResources()

$resource = json_decode($hal->asJson());
$this->assertInstanceOf('StdClass', $resource->_embedded);
$this->assertInternalType('array', $resource->_embedded->resource);
$this->assertIsArray( $resource->_embedded->resource);
$this->assertEquals($resource->_embedded->resource[0]->field1, '1');
$this->assertEquals($resource->_embedded->resource[1]->field1, '2');
}
Expand Down Expand Up @@ -735,11 +735,9 @@ public function testGetFirstResourceReturnsFirstOfMultipleItems()
$this->assertEquals($res1, $hal->getFirstResource("resource"));
}

/**
* @expectedException RuntimeException
*/
public function testHalFromJsonThrowsExceptionOnInvalidJSON()
{
$this->expectException('RuntimeException');
$invalidJson = 'foo';
Hal::fromJson($invalidJson);
}
Expand Down Expand Up @@ -786,7 +784,7 @@ public function testEmbeddingResourceWithSingleElement()
);

$json = json_decode($hal->asJson());
$this->assertInternalType('array', $json->_embedded->foo->_embedded->bar);
$this->assertIsArray( $json->_embedded->foo->_embedded->bar);
}

public function testErrorAddResource()
Expand Down