https://github.com/blastcloud/guzzler
Supercharge your app or SDK with a testing library specifically for Guzzle
https://github.com/blastcloud/guzzler
guzzlehttp mock php phpunit testing
Last synced: about 1 month ago
JSON representation
Supercharge your app or SDK with a testing library specifically for Guzzle
- Host: GitHub
- URL: https://github.com/blastcloud/guzzler
- Owner: blastcloud
- License: mit
- Created: 2019-02-08T03:58:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-20T03:56:33.000Z (over 1 year ago)
- Last Synced: 2025-04-03T23:11:37.845Z (about 2 months ago)
- Topics: guzzlehttp, mock, php, phpunit, testing
- Language: PHP
- Homepage: https://guzzler.dev
- Size: 630 KB
- Stars: 272
- Watchers: 7
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
![]()
![]()
![]()
![]()
![]()
---
> Full Documentation at [guzzler.dev](https://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
```bash
composer require --dev --prefer-dist blastcloud/guzzler
```## Example Usage
```php
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](https://guzzler.dev)
## License
Guzzler is open-source software licensed under the [MIT License](https://opensource.org/licenses/MIT).