Skip to content

Commit 5ca61e8

Browse files
Merge pull request #66 from ohdearapp/handle-case-for-broken-links-with-status-code-as-null
fix: handle null status codes in `BrokenLink` DTO and update tests
2 parents a0d1f15 + 1815602 commit 5ca61e8

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/Dto/BrokenLink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class BrokenLink
66
{
77
public function __construct(
8-
public int $statusCode,
8+
public ?int $statusCode,
99
public string $crawledUrl,
1010
public string $relativeCrawledUrl,
1111
public string $foundOnUrl,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"statusCode": 200,
3+
"headers": {
4+
"Content-Type": "application/json"
5+
},
6+
"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}}"
7+
}

tests/OhDearTests/BrokenLinksTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,21 @@
2525
expect($brokenLink->internal)->toBeBool();
2626
}
2727
});
28+
29+
it('handles null status codes in broken links payload without throwing', function () {
30+
MockClient::global([
31+
GetBrokenLinksRequest::class => MockResponse::fixture('broken-links-null-status'),
32+
]);
33+
34+
$brokenLinks = $this->ohDear->brokenLinks(82060);
35+
36+
foreach ($brokenLinks as $brokenLink) {
37+
expect($brokenLink->statusCode)->toBeNull()
38+
->and($brokenLink->crawledUrl)->toBeString()
39+
->and($brokenLink->relativeCrawledUrl)->toBeString()
40+
->and($brokenLink->foundOnUrl)->toBeString()
41+
->and($brokenLink->relativeFoundOnUrl)->toBeString()
42+
->and($brokenLink->linkText)->toBeString()
43+
->and($brokenLink->internal)->toBeBool();
44+
}
45+
});

0 commit comments

Comments
 (0)