PHPackages                             alekseytupichenkov/guzzle\_stub - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. alekseytupichenkov/guzzle\_stub

ActiveGuzzle-extension[Testing &amp; Quality](/categories/testing)

alekseytupichenkov/guzzle\_stub
===============================

This repository provides guzzle stubs with flexible fixtures

2.0.0(4y ago)012.7kMITPHPPHP ^8.0

Since Sep 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/alekseytupichenkov/GuzzleStub)[ Packagist](https://packagist.org/packages/alekseytupichenkov/guzzle_stub)[ RSS](/packages/alekseytupichenkov-guzzle-stub/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

GuzzleStub
==========

[](#guzzlestub)

[![Build Status](https://camo.githubusercontent.com/1129300d1619f47dc2da9ee134dcd463e6823ec61ffdd255eb0817e7b75e2af3/68747470733a2f2f7472617669732d63692e6f72672f616c656b736579747570696368656e6b6f762f47757a7a6c65537475622e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/alekseytupichenkov/GuzzleStub)[![Coverage Status](https://camo.githubusercontent.com/d0d61404035437039174f1af0f8c689cc267847e53e461b3944202baaa6c87c1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f616c656b736579747570696368656e6b6f762f47757a7a6c65537475622f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/alekseytupichenkov/GuzzleStub?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5802a1c5ff2c09572f747c4d5553c45afadc55ff495d1fcca9d0143f007c3856/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c656b736579747570696368656e6b6f762f47757a7a6c65537475622f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alekseytupichenkov/GuzzleStub/?branch=master)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/digiaonline/graphql-php/master/LICENSE)

Table of contents:

- [Installation](#installation)
- [Basic usage and methods](#basic-usage)

Introduction
============

[](#introduction)

This repository provides guzzle stubs with flexible fixtures.

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

[](#installation)

1. Download

    Run command in console

    ```
    $ composer require --dev alekseytupichenkov/guzzle_stub
    ```

Basic usage
-----------

[](#basic-usage)

In case of you have guzzle client for which it is necessary to write stubs and exclude the possibility make requests to external services

For example:

```
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

class MySuperGuzzleClient extends Client
{
    public function __construct(HandlerStack $handlerStack = null)
    {
        parent::__construct([
            'timeout' => 300,
            'base_uri' => 'http://foo.bar',
            'handler' => $handlerStack ?? HandlerStack::create(),
        ]);
    }
}
```

Create Guzzle client stub class using existing guzzle client, add trait GuzzleClientTrait, implement method `loadFixtures` and add fixtures to it

```
use Alekseytupichenkov\GuzzleStub\Model\Fixture;
use Alekseytupichenkov\GuzzleStub\Traits\GuzzleClientTrait;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;

class MySuperGuzzleClientStub extends MySuperGuzzleClient
{
    use GuzzleClientTrait;

    function loadFixtures()
    {
        $this->append(new Fixture(
            new Request('GET', 'http://foo.bar/baz', ['token' => '.*']),
            new Response(200, [], '{"result":"ok"}')
        ));

        $this->append(new Fixture(
            new Request('POST', 'http://foo.bar/baz', ['token' => '.*'], '{"data":".*"}'),
            new Response(200, [], '{"result":"ok"}')
        ));
    }
}
```

Now you can write tests checking history of requests/responses

```
use PHPUnit\Framework\TestCase;

class MySuperGuzzleClientStubTest extends TestCase
{
    /** @var MySuperGuzzleClientStub */
    private $client;

    public function setUp()
    {
        $this->client = new MySuperGuzzleClientStub();
    }

    public function testPost()
    {
        $response = $this->client->post('/baz', [
            'headers' => [
                'token' => '123'
            ],
            'body' => '{"data":"test"}'
        ]);

        $this->assertEquals(200, $response->getStatusCode());
        $this->assertEquals('{"result":"ok"}', $response->getBody()->__toString());
        $this->assertEquals(1, $this->client->getHistoryCount());
        $this->assertEquals($response, $this->client->getLatestHistoryResponse());
    }
}
```

If stub haven't sutible fixture, you'll get exception like this

```
1) MySuperGuzzleClientStubTest::testException
Alekseytupichenkov\GuzzleStub\Exception\GuzzleStubException: Can't find suitable response for request [array (
  'method' => 'POST',
  'uri' => '/without/fixture',
  'body' => '',
  'protocol_version' => '1.1',
  'headers' =>
  array (
    'User-Agent' =>
    array (
      0 => 'GuzzleHttp/6.3.3 curl/7.54.0 PHP/7.1.18',
    ),
    'Host' =>
    array (
      0 => 'foo.bar',
    ),
  ),
)]
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~210 days

Recently: every ~263 days

Total

6

Last Release

1734d ago

Major Versions

1.0.4 → 2.0.02021-08-12

PHP version history (2 changes)1.0.0PHP ^7.0

2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0353c785cf2048e5bd73d1a0ad16d5f252000e02b28f0d89b358e93fa9329dce?d=identicon)[alekseytupichenkov](/maintainers/alekseytupichenkov)

---

Top Contributors

[![alekseytupichenkov](https://avatars.githubusercontent.com/u/8191991?v=4)](https://github.com/alekseytupichenkov "alekseytupichenkov (5 commits)")

---

Tags

testingmockingGuzzlefixturesmockstub

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alekseytupichenkov-guzzle-stub/health.svg)

```
[![Health](https://phpackages.com/badges/alekseytupichenkov-guzzle-stub/health.svg)](https://phpackages.com/packages/alekseytupichenkov-guzzle-stub)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[phake/phake

The Phake mock testing library

4758.0M324](/packages/phake-phake)[kahlan/kahlan

The PHP Test Framework for Freedom, Truth and Justice.

1.2k1.2M247](/packages/kahlan-kahlan)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[blastcloud/guzzler

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

272419.3k35](/packages/blastcloud-guzzler)

PHPackages © 2026

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