PHPackages                             webwhales/guzzle-conditional-mock-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. webwhales/guzzle-conditional-mock-handler

ActiveLibrary[HTTP &amp; Networking](/categories/http)

webwhales/guzzle-conditional-mock-handler
=========================================

Offers a way to load mocked responses conditionally with Guzzle instead of a fixed queue

v1.0.5(1y ago)130.9k↓100%11MITPHPPHP ^7.2|^8.0CI failing

Since Mar 30Pushed 1y agoCompare

[ Source](https://github.com/WebWhales/guzzle-conditional-mock-handler)[ Packagist](https://packagist.org/packages/webwhales/guzzle-conditional-mock-handler)[ Docs](https://github.com/WebWhales/guzzle-conditional-mock-handler)[ RSS](/packages/webwhales-guzzle-conditional-mock-handler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (8)Used By (1)

Conditional Mock Handler for Guzzle
===================================

[](#conditional-mock-handler-for-guzzle)

This is a package that offers a way to load mock responses conditionally based on the URL, instead of a fixed queue.

Installation
------------

[](#installation)

Install this package using composer:

```
composer require --dev webwhales/guzzle-conditional-mock-handler

```

Simple Example
--------------

[](#simple-example)

To use this Conditional Mock Handler, use the following example:

```
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use WebWhales\GuzzleConditionalMockHandler\Handler as MockHandler;

$mockHandler = new MockHandler();

// Create a handler stack to mock the Guzzle Client with
$handler = HandlerStack::create($mockHandler);
$client  = new Client(['handler' => $handler]);

// Add mocked responses
$mockHandler->addResponse('https://example.com', new Response(200, [], 'This is a test'));

// Make a request to a matching URL
$response = $client->request('GET', 'https://example.com');

echo $response->getBody();
// Outputs "This is a test"

// Make a request to a non matching URL
$response = $client->request('GET', 'https://www.example.com');

echo $response->getBody();
// Outputs the actual content of https://www.example.com
```

Regex example
-------------

[](#regex-example)

This packages also supports regex patterns:

```
// Add mocked responses
$mockHandler->addResponse('^http(s)?://example\.', new Response(200, [], 'This is a test'));

// Make a request to a matching URL
$response = $client->request('GET', 'https://example.com');

echo $response->getBody();
// Outputs "This is a test"

// Make a request to a non matching URL
$response = $client->request('GET', 'https://www.example.com');

echo $response->getBody();
// Outputs the actual content of https://www.example.com
```

Initialization Helper
---------------------

[](#initialization-helper)

Using this handler can also be simplified using the the following helper:

```
$client      = null;
$mockHandler = MockHandler::initializeWithClient($client);
```

License
-------

[](#license)

The this package is open source software licensed under the [MIT license](https://opensource.org/licenses/MIT)

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~302 days

Recently: every ~371 days

Total

6

Last Release

717d ago

PHP version history (3 changes)1.0PHP ^7.2

1.0.2PHP ^7.2|^8.0

1.0.4PHP ^7.2|^8.0|^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8b6bb09e85274734d6040f0e6b3fcb393db59c20d984f5e217be3b272550089?d=identicon)[redelschaap](/maintainers/redelschaap)

---

Top Contributors

[![redelschaap](https://avatars.githubusercontent.com/u/6915990?v=4)](https://github.com/redelschaap "redelschaap (9 commits)")[![Th3Cod3](https://avatars.githubusercontent.com/u/21333805?v=4)](https://github.com/Th3Cod3 "Th3Cod3 (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![colinodell](https://avatars.githubusercontent.com/u/202034?v=4)](https://github.com/colinodell "colinodell (1 commits)")

---

Tags

httpmockingGuzzle

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webwhales-guzzle-conditional-mock-handler/health.svg)

```
[![Health](https://phpackages.com/badges/webwhales-guzzle-conditional-mock-handler/health.svg)](https://phpackages.com/packages/webwhales-guzzle-conditional-mock-handler)
```

###  Alternatives

[kevinrob/guzzle-cache-middleware

A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)

43117.4M104](/packages/kevinrob-guzzle-cache-middleware)[kitetail/zttp

A developer-experience focused HTTP client, optimized for most common use cases.

1.7k1.2M72](/packages/kitetail-zttp)[php-http/guzzle7-adapter

Guzzle 7 HTTP Adapter

9057.1M553](/packages/php-http-guzzle7-adapter)[graham-campbell/guzzle-factory

Provides A Simple Guzzle Factory With Good Defaults

916.4M49](/packages/graham-campbell-guzzle-factory)[graze/guzzle-jsonrpc

JSON-RPC 2.0 client for Guzzle

981.2M24](/packages/graze-guzzle-jsonrpc)[rtheunissen/guzzle-log-middleware

Guzzle middleware to log requests and responses

842.3M17](/packages/rtheunissen-guzzle-log-middleware)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
