https://github.com/e-moe/guzzle-regexp-mock-plugin
Mock plugin for Guzzle3 with regexp match urls
https://github.com/e-moe/guzzle-regexp-mock-plugin
guzzle mock php plugin
Last synced: 6 days ago
JSON representation
Mock plugin for Guzzle3 with regexp match urls
- Host: GitHub
- URL: https://github.com/e-moe/guzzle-regexp-mock-plugin
- Owner: e-moe
- License: mit
- Created: 2015-04-24T08:18:59.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-04-26T07:30:27.000Z (about 10 years ago)
- Last Synced: 2025-04-24T00:58:09.488Z (6 days ago)
- Topics: guzzle, mock, php, plugin
- Language: PHP
- Size: 129 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Guzzle regexp mock plugin
The mock plugin is useful for testing Guzzle clients. The mock plugin allows you to queue an array of responses that will satisfy requests sent from a client by consuming the request queue in FIFO order. Each request may have optional regexp url match pattern.
_Based on standard mock plugin - http://guzzle3.readthedocs.org/plugins/mock-plugin.html_
```php
use Guzzle\Http\Client;
use Guzzle\Http\Message\Response;
use Emoe\GuzzleRegexpMockPlugin\MockPlugin;$client = new Client('http://www.test.com/');
$mock = new MockPlugin();
$mock->addResponse(new Response(200), '/(foo|bar)page/')
->addResponse(new Response(200), '/article\/\w+/')
->addResponse(new Response(404)); // regexp pattern is optional// Add the mock plugin to the client object
$client->addSubscriber($mock);// The following request will receive a 200 response from the plugin regexp queue
$client->get('/foopage')->send();// The following request will receive a 404 response from the plugin, default behaviour
$client->get('notfound')->send();// The following request will receive a 200 response from the plugin regexp queue
$client->get('/article/about')->send();
```