diff --git a/composer.json b/composer.json index aa0a00f..c0eb884 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Hal.php b/src/Hal.php index 5b42976..2c93be4 100644 --- a/src/Hal.php +++ b/src/Hal.php @@ -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( @@ -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; diff --git a/src/HalJsonRenderer.php b/src/HalJsonRenderer.php index 0398721..1bb7dbe 100644 --- a/src/HalJsonRenderer.php +++ b/src/HalJsonRenderer.php @@ -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); diff --git a/tests/Hal/HalTest.php b/tests/Hal/HalTest.php index 241c297..d9e739b 100644 --- a/tests/Hal/HalTest.php +++ b/tests/Hal/HalTest.php @@ -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'); @@ -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); } @@ -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); @@ -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'); } @@ -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); } @@ -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()