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
This commit is contained in:
Jonny Barnes 2026-07-26 09:12:01 +01:00
commit e08763c526
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
26 changed files with 337 additions and 630 deletions

View file

@ -6,12 +6,9 @@ namespace Tests\Feature\Admin;
use App\Models\Contact;
use App\Models\User;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
@ -141,14 +138,12 @@ class ContactsTest extends TestCase
<img class="u-photo" alt="" src="http://tantek.com/tantek.png">
</div>
HTML;
$file = fopen(__DIR__.'/../../aaron.png', 'rb');
$mock = new MockHandler([
new Response(200, ['Content-Type' => 'text/html'], $html),
new Response(200, ['Content-Type' => 'image/png'], $file),
$file = file_get_contents(__DIR__.'/../../aaron.png');
Http::fake([
'*' => Http::sequence()
->push($html, 200, ['Content-Type' => 'text/html'])
->push($file, 200, ['Content-Type' => 'image/png']),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$user = User::factory()->make();
$contact = Contact::factory()->create([
'homepage' => 'https://tantek.com',
@ -165,12 +160,9 @@ class ContactsTest extends TestCase
#[Test]
public function getting_remote_avatar_fails_gracefully_with_remote_not_found(): void
{
$mock = new MockHandler([
new Response(404),
Http::fake([
'*' => Http::response('', 404),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$user = User::factory()->make();
$contact = Contact::factory()->create();
@ -187,13 +179,11 @@ class ContactsTest extends TestCase
<img class="u-photo" src="http://tantek.com/tantek.png">
</div>
HTML;
$mock = new MockHandler([
new Response(200, ['Content-Type' => 'text/html'], $html),
new Response(404),
Http::fake([
'*' => Http::sequence()
->push($html, 200, ['Content-Type' => 'text/html'])
->push('', 404),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$user = User::factory()->make();
$contact = Contact::factory()->create();

View file

@ -5,14 +5,11 @@ declare(strict_types=1);
namespace Tests\Feature;
use App\Models\User;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Psr7\UriResolver;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
@ -269,12 +266,9 @@ class IndieAuthTest extends TestCase
</html>
HTML;
$mockHandler = new MockHandler([
new Response(200, [], $appPageHtml),
Http::fake([
'*' => Http::response($appPageHtml, 200),
]);
$handlerStack = HandlerStack::create($mockHandler);
$mockGuzzleClient = new Client(['handler' => $handlerStack]);
$this->app->instance(Client::class, $mockGuzzleClient);
$user = User::factory()->make();
$url = url()->query('/auth', [
@ -313,12 +307,9 @@ class IndieAuthTest extends TestCase
</html>
HTML;
$mockHandler = new MockHandler([
new Response(200, [], $appPageHtml),
Http::fake([
'*' => Http::response($appPageHtml, 200),
]);
$handlerStack = HandlerStack::create($mockHandler);
$mockGuzzleClient = new Client(['handler' => $handlerStack]);
$this->app->instance(Client::class, $mockGuzzleClient);
$user = User::factory()->make();
$url = url()->query('/auth', [

View file

@ -6,11 +6,8 @@ namespace Tests\Feature;
use App\Jobs\ProcessLike;
use App\Models\Like;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Queue;
use Jonnybarnes\WebmentionsParser\Authorship;
use PHPUnit\Framework\Attributes\Test;
@ -98,18 +95,12 @@ class LikesTest extends TestCase
</html>
END;
$mock = new MockHandler([
new Response(200, [], $content),
new Response(200, [], $content),
Http::fake([
'*' => Http::response($content, 200),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->bind(Client::class, function () use ($client) {
return $client;
});
$authorship = new Authorship;
$job->handle($client, $authorship);
$job->handle($authorship);
$this->assertEquals('Fred Bloggs', Like::find($id)->author_name);
}
@ -141,18 +132,12 @@ class LikesTest extends TestCase
</html>
END;
$mock = new MockHandler([
new Response(200, [], $content),
new Response(200, [], $content),
Http::fake([
'*' => Http::response($content, 200),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->bind(Client::class, function () use ($client) {
return $client;
});
$authorship = new Authorship;
$job->handle($client, $authorship);
$job->handle($authorship);
$this->assertEquals('Fred Bloggs', Like::find($id)->author_name);
}
@ -177,18 +162,12 @@ class LikesTest extends TestCase
</html>
END;
$mock = new MockHandler([
new Response(200, [], $content),
new Response(200, [], $content),
Http::fake([
'*' => Http::response($content, 200),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->bind(Client::class, function () use ($client) {
return $client;
});
$authorship = new Authorship;
$job->handle($client, $authorship);
$job->handle($authorship);
$this->assertNull(Like::find($id)->author_name);
}