Getting Started GitHub icon Github

Supercharge your app 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.

# 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 ( [ "base_uri" = > "https://example.com/api" ] ) ; $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" ) , ) ; $this - > classToTest - > someMethod ( ) ; $this - > guzzler - > assertAll ( function ( $expect ) { return $expect - > withHeader ( "Authorization" , "some-key" ) ; } ) ; } }

MIT Licensed | Copyright © 2019-present Adam Kelso