Skip to content
Supercharge your app or SDK with a testing library specifically for Guzzle
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Fixes issue for changed invoker namespace in PHPUnit 8.2 Jun 10, 2019
tests Fixing failure with PHPUnit 8 May 20, 2019
.gitattributes All the changes after watching Marcel's course Feb 21, 2019
.gitignore Updates for Code-Climate based on tutorial Feb 28, 2019
.styleci.yml
.travis.yml
CHANGELOG.md Updating docs for the progress and this release. Jun 10, 2019
Guzzler-logo.svg Adding the logo Feb 28, 2019
LICENSE.md All the changes after watching Marcel's course Feb 21, 2019
README.md Updating docs for the progress and this release. Jun 10, 2019
composer.json Testing using code climate's coverage package Apr 21, 2019
composer.lock Testing using code climate's coverage package Apr 21, 2019
phpunit.xml.dist Removing interfaces directory from test coverage. Makes no sense for … Jun 10, 2019

README.md


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.

You can’t perform that action at this time.