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(2y ago)130.9k11MITPHPPHP ^7.2|^8.0CI failing

Since Mar 30Pushed 2y 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 2w 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

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity66

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

762d 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

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[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)

43518.2M126](/packages/kevinrob-guzzle-cache-middleware)[graham-campbell/guzzle-factory

Provides A Simple Guzzle Factory With Good Defaults

926.8M53](/packages/graham-campbell-guzzle-factory)[graze/guzzle-jsonrpc

JSON-RPC 2.0 client for Guzzle

981.2M24](/packages/graze-guzzle-jsonrpc)[eljam/guzzle-jwt-middleware

A jwt authentication middleware for guzzle 6

28750.0k3](/packages/eljam-guzzle-jwt-middleware)[rtheunissen/guzzle-rate-limiter

Guzzle 6 middleware used to delay requests dynamically

52179.4k1](/packages/rtheunissen-guzzle-rate-limiter)

PHPackages © 2026

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