e-moe / guzzle-regexp-mock-plugin
适用于Guzzle3的正则表达式匹配URL的Mock插件
v1.0.0
2015-04-24 09:25 UTC
Requires
- php: >=5.3.3
- guzzle/guzzle: ~3.0
- symfony/event-dispatcher: ~2.1
This package is auto-updated.
Last update: 2024-08-29 03:47:36 UTC
README
Mock插件对测试Guzzle客户端非常有用。该插件允许您通过按FIFO顺序消耗请求队列来排队一组响应,以满足客户端发送的请求。每个请求可以有一个可选的正则表达式URL匹配模式。
基于标准Mock插件 - http://guzzle3.readthedocs.org/plugins/mock-plugin.html
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();