blastcloud/guzzler

Supercharge your app or SDK with a testing library specifically for Guzzle.

Maintainers

👁 adamkelso

Package info

github.com/blastcloud/guzzler

pkg:composer/blastcloud/guzzler

Statistics

Installs: 461 287

Dependents: 31

Suggesters: 2

Stars: 272

Open Issues: 1

2.3.0 2025-07-06 02:01 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT d823d855808823a9fcfb2e76d2b97fef0c3573ba

  • Adam Kelso <kelso.adam.woop@gmail.com>

phptestingphpunitmockGuzzle

This package is auto-updated.

Last update: 2026-06-06 04:05:00 UTC


README

👁 Image

👁 Image
👁 Image
👁 Image
👁 Image
👁 Image

Full Documentation at guzzler.dev

Supercharge your app or SDK with a testing library specifically for Guzzle. Guzzler covers the process of setting up a mock handler, recording history of requests, and provides several convenience methods for creating expectations and assertions on that history.

Installation

composer require --dev --prefer-dist blastcloud/guzzler

Example Usage

<?php

use BlastCloud\Guzzler\UsesGuzzler;
use GuzzleHttp\Client;

class SomeTest extends TestCase
{
 use UsesGuzzler;

 public $classToTest;

 public function setUp(): void
 {
 parent::setUp();
 
 $client = $this->guzzler->getClient([
 /* Any configs for a client */
 "base_uri" => "https://example.com/api"
 ]);
 
 // You can then inject this client object into your code or IOC container.
 $this->classToTest = new ClassToTest($client);
 }

 public function testSomethingWithExpectations()
 {
 $this->guzzler->expects($this->once())
 ->post("/some-url")
 ->withHeader("X-Authorization", "some-key")
 ->willRespond(new Response(201));
 
 $this->classToTest->someMethod();
 }

 public function testSomethingWithAssertions()
 {
 $this->guzzler->queueResponse(
 new Response(204),
 new \Exception("Some message"),
 // any needed responses to return from the client.
 );
 
 $this->classToTest->someMethod();
 // ... Some other number of calls
 
 $this->guzzler->assertAll(function ($expect) {
 return $expect->withHeader("Authorization", "some-key");
 });
 }
}

Documentation

Full Documentation

License

Guzzler is open-source software licensed under the MIT License.