avto-dev / guzzle-url-mock
URLs (fixed and regexps-based) mock handler for Guzzle 6/7
Installs: 39 842
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 3
Open Issues: 2
Requires
- php: ^8.0
- ext-mbstring: *
- guzzlehttp/guzzle: ~7.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.6 || ^10.3
This package is auto-updated.
Last update: 2024-12-08 09:45:57 UTC
README
Guzzle URLs mock handler
This package for easy mocking URLs (fixed and regexps-based) using Guzzle 6/Guzzle 7.
Install
Require this package with composer using the following command:
$ composer require avto-dev/guzzle-url-mock "^1.5"
Installed
composer
is required (how to install composer).
You need to fix the major version of package.
Usage
Create Guzzle client instance with passing handler instance, setup it, and make request:
<?php use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; use AvtoDev\GuzzleUrlMock\UrlsMockHandler; $handler = new UrlsMockHandler; $client = new Client([ 'handler' => HandlerStack::create($handler), ]); $handler->onUriRequested('https://goo.gl', 'get', new Response( 200, ['foo' => ['bar']], '<h1>All looks fine!</h1>' )); $handler->onUriRegexpRequested('~https:\/\/goo\.gl\/.*~', 'post', new Response( 404, [], 'Nothing found' )); $client->request('get', 'https://goo.gl')->getBody()->getContents(); // '<h1>All looks fine!</h1>' $client->request('post', 'https://goo.gl/foo', ['http_errors' => false])->getBody()->getContents(); // 'Nothing found'
Also you can use next handler methods:
Testing
For package testing we use phpunit
framework and docker-ce
+ docker-compose
as develop environment. So, just write into your terminal after repository cloning:
$ make build $ make latest # or 'make lowest' $ make test
Changes log
Changes log can be found here.
Support
If you will find any package errors, please, make an issue in current repository.
License
This is open-sourced software licensed under the MIT License.