From 36673fcc7ec4a6e0d44439666b7f40fd661036de Mon Sep 17 00:00:00 2001 From: Derek Blasutti <9371128+dawgbone@users.noreply.github.com> Date: Thu, 26 Nov 2026 15:45:48 -0500 Subject: [PATCH] Fix PHP 8.4 deprecations and Guzzle test compatibility --- src/Document/Link/Link.php | 4 +-- tests/lib/Integration/Client/TestCase.php | 2 +- tests/lib/Unit/Document/LinkTest.php | 43 +++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/lib/Unit/Document/LinkTest.php diff --git a/src/Document/Link/Link.php b/src/Document/Link/Link.php index bd2ca888..c7b81a81 100644 --- a/src/Document/Link/Link.php +++ b/src/Document/Link/Link.php @@ -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); @@ -132,7 +132,7 @@ public function toArray() /** * @inheritDoc */ - public function jsonSerialize() + public function jsonSerialize(): mixed { if ($this->hasMeta()) { return $this->toArray(); diff --git a/tests/lib/Integration/Client/TestCase.php b/tests/lib/Integration/Client/TestCase.php index aea3689d..4a2e5d6d 100644 --- a/tests/lib/Integration/Client/TestCase.php +++ b/tests/lib/Integration/Client/TestCase.php @@ -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; } diff --git a/tests/lib/Unit/Document/LinkTest.php b/tests/lib/Unit/Document/LinkTest.php new file mode 100644 index 00000000..cfb6118e --- /dev/null +++ b/tests/lib/Unit/Document/LinkTest.php @@ -0,0 +1,43 @@ +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) + ); + } +}