Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/Document/Link/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function fromArray(array $input): self
* @param string $href
* @param array|null $meta
*/
public function __construct(string $href, array $meta = null)
public function __construct(string $href, ?array $meta = null)
{
$this->setHref($href);
$this->setMeta($meta);
Expand Down Expand Up @@ -132,7 +132,7 @@ public function toArray()
/**
* @inheritDoc
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
if ($this->hasMeta()) {
return $this->toArray();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Client/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function willSeeResponse(?array $json = null, $status = 200, array $he
if ($json) {
$body = json_encode($json);
$headers['Content-Type'] = 'application/vnd.api+json';
$headers['Content-Length'] = mb_strlen($body, '8bit');
$headers['Content-Length'] = (string) mb_strlen($body, '8bit');
} else {
$body = null;
}
Expand Down
43 changes: 43 additions & 0 deletions tests/lib/Unit/Document/LinkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace CloudCreativity\LaravelJsonApi\Tests\Unit\Document;

use CloudCreativity\LaravelJsonApi\Document\Link\Link;
use CloudCreativity\LaravelJsonApi\Tests\Unit\TestCase;

class LinkTest extends TestCase
{
public function testLinkWithoutMetadata(): void
{
$url = 'https://example.test/leads/123';

$link = new Link($url);

$this->assertNull($link->getMeta());
$this->assertSame($url, $link->jsonSerialize());
$this->assertSame(
json_encode($url, JSON_THROW_ON_ERROR),
json_encode($link, JSON_THROW_ON_ERROR)
);
}

public function testLinkWithMetadata(): void
{
$url = 'https://example.test/leads/123';
$meta = ['source' => 'test'];

$link = new Link($url, $meta);

$expected = [
'href' => $url,
'meta' => $meta,
];

$this->assertSame($meta, $link->getMeta());
$this->assertSame($expected, $link->jsonSerialize());
$this->assertSame(
json_encode($expected, JSON_THROW_ON_ERROR),
json_encode($link, JSON_THROW_ON_ERROR)
);
}
}
Loading