diff --git a/src/Link.php b/src/Link.php index 5bd49d4..be1c19f 100644 --- a/src/Link.php +++ b/src/Link.php @@ -201,15 +201,14 @@ private function validateAttributeName($name, string $context): void /** * @param mixed $value - * @throws InvalidArgumentException If $value is neither a scalar nor an array. - * @throws InvalidArgumentException If $value is an array, but one or more values - * is not a string. + * @throws InvalidArgumentException If $value is neither a scalar, an array nor null. + * @throws InvalidArgumentException If $value is an array, but one or more values is not a string. */ private function validateAttributeValue($value, string $context): void { - if (! is_scalar($value) && ! is_array($value)) { + if (! is_scalar($value) && ! is_array($value) && $value !== null) { throw new InvalidArgumentException(sprintf( - '%s expects the $value to be a PHP primitive or array of strings; received %s', + '%s expects the $value to be a PHP primitive, an array of strings or null; received %s', $context, is_object($value) ? $value::class : gettype($value) )); diff --git a/test/LinkTest.php b/test/LinkTest.php index 0723de9..093f527 100644 --- a/test/LinkTest.php +++ b/test/LinkTest.php @@ -45,9 +45,10 @@ public function testCanConstructLinkWithRelationAndTemplatedFlag(): void public function testCanConstructLinkWithRelationAndAttributes(): void { - $link = new Link('self', '', false, ['foo' => 'bar']); + $attributes = ['foo' => 'bar', 'baz' => null]; + $link = new Link('self', '', false, $attributes); $this->assertEquals(['self'], $link->getRels()); - $this->assertEquals(['foo' => 'bar'], $link->getAttributes()); + $this->assertEquals($attributes, $link->getAttributes()); } public function testCanConstructFullyPopulatedLink(): void