jonnybarnes.uk/tests/Unit/BookmarksTest.php
Jonny Barnes e08763c526
Migrate outbound HTTP calls from Guzzle to the Http facade
Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.

The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.

Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
2026-07-26 09:12:01 +01:00

57 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit;
use App\Exceptions\InternetArchiveException;
use App\Services\BookmarkService;
use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class BookmarksTest extends TestCase
{
/*
* @\test
*
* @\group puppeteer
*
public function takeScreenshotOfDuckDuckGo()
{
$uuid = (new BookmarkService())->saveScreenshot('https://duckduckgo.com');
$this->assertTrue(file_exists(public_path() . '/assets/img/bookmarks/' . $uuid . '.png'));
}*/
#[Test]
public function archive_link_method_calls_archive_service(): void
{
Http::fake([
'web.archive.org/*' => Http::response('', 200, ['Content-Location' => '/web/1234/example.org']),
]);
$url = (new BookmarkService)->getArchiveLink('https://example.org');
$this->assertEquals('/web/1234/example.org', $url);
}
#[Test]
public function archive_link_method_throws_an_exception_on_error(): void
{
$this->expectException(InternetArchiveException::class);
Http::fake([
'web.archive.org/*' => Http::response('', 403),
]);
(new BookmarkService)->getArchiveLink('https://example.org');
}
#[Test]
public function archive_link_method_throws_an_exception_if_no_location_returned(): void
{
$this->expectException(InternetArchiveException::class);
Http::fake([
'web.archive.org/*' => Http::response('', 200),
]);
(new BookmarkService)->getArchiveLink('https://example.org');
}
}