diff --git a/src/Dto/BrokenLink.php b/src/Dto/BrokenLink.php index 52e6b25..690ad8b 100644 --- a/src/Dto/BrokenLink.php +++ b/src/Dto/BrokenLink.php @@ -5,7 +5,7 @@ class BrokenLink { public function __construct( - public int $statusCode, + public ?int $statusCode, public string $crawledUrl, public string $relativeCrawledUrl, public string $foundOnUrl, diff --git a/tests/Fixtures/Saloon/broken-links-null-status.json b/tests/Fixtures/Saloon/broken-links-null-status.json new file mode 100644 index 0000000..7c763c1 --- /dev/null +++ b/tests/Fixtures/Saloon/broken-links-null-status.json @@ -0,0 +1,7 @@ +{ + "statusCode": 200, + "headers": { + "Content-Type": "application/json" + }, + "data": "{\"data\":[{\"status_code\":null,\"crawled_url\":\"https://2019.wiadswitzerland.org/\",\"relative_crawled_url\":\"https://2019.wiadswitzerland.org/\",\"found_on_url\":\"https://zeix.com/magazin/inclusive-design-in-der-sprache\",\"relative_found_on_url\":\"/magazin/inclusive-design-in-der-sprache\",\"link_text\":\"WorldInformationArchitectureDay(WIAD)inZürich\",\"internal\":false}],\"links\":{\"first\":\"/?page=1\",\"last\":\"/?page=1\",\"prev\":null,\"next\":null},\"meta\":{\"current_page\":1,\"from\":1,\"last_page\":1,\"links\":[{\"url\":null,\"label\":\"«Previous\",\"page\":null,\"active\":false},{\"url\":\"/?page=1\",\"label\":\"1\",\"page\":1,\"active\":true},{\"url\":null,\"label\":\"Next»\",\"page\":null,\"active\":false}],\"path\":\"/\",\"per_page\":1000,\"to\":1,\"total\":1}}" +} diff --git a/tests/OhDearTests/BrokenLinksTest.php b/tests/OhDearTests/BrokenLinksTest.php index d56f246..4ffabba 100644 --- a/tests/OhDearTests/BrokenLinksTest.php +++ b/tests/OhDearTests/BrokenLinksTest.php @@ -25,3 +25,21 @@ expect($brokenLink->internal)->toBeBool(); } }); + +it('handles null status codes in broken links payload without throwing', function () { + MockClient::global([ + GetBrokenLinksRequest::class => MockResponse::fixture('broken-links-null-status'), + ]); + + $brokenLinks = $this->ohDear->brokenLinks(82060); + + foreach ($brokenLinks as $brokenLink) { + expect($brokenLink->statusCode)->toBeNull() + ->and($brokenLink->crawledUrl)->toBeString() + ->and($brokenLink->relativeCrawledUrl)->toBeString() + ->and($brokenLink->foundOnUrl)->toBeString() + ->and($brokenLink->relativeFoundOnUrl)->toBeString() + ->and($brokenLink->linkText)->toBeString() + ->and($brokenLink->internal)->toBeBool(); + } +});