kirouane/imposter
最新稳定版本:1.0.0
Composer 安装命令:
composer require kirouane/imposter
包简介
API mock for PHPUnit
README 文档
README
Imposter
Imposter is a php library that used to serve http stubs and mocks.
Here is an example to emphasize how is simple to mock an HTTP endpoint with this library in PHPUnit.
namespace Imposter; use PHPUnit\Framework\TestCase; /** * Class ScenarioTest * @package Imposter */ class ReadMeTest extends TestCase { /** * @test * */ public function match() { ImposterFactory::get()->mock(8081) ->withPath('/users/1') ->withMethod('POST') ->returnBody('{"response" :"okay"}') ->once() ->send(); $client = new \GuzzleHttp\Client(); $response = $client->post('http://localhost:8081/users/1')->getBody()->getContents(); self::assertSame($response, '{"response" :"okay"}'); } public function tearDown() { ImposterFactory::get()->close(); } }
Install
composer require kirouane/imposter --dev
Features
Display logs
In case of the HTTP request doesn't match any mock, you can find out the reason here http://localhost:2424/mock/log/html
Below, you can see what the logs page looks like.
PHPUnit Asserter
Imposter Library uses PHPunit asserters to match HTTP requests with the mocks you create.
Example :
namespace Imposter; use PHPUnit\Framework\TestCase; /** * Class ScenarioTest * @package Imposter */ class ReadMeTest extends TestCase { /** * @test */ public function match() { ImposterFactory::get()->mock(8081) ->withPath('/users/1') ->withMethod(new RegularExpression('/POST|PUT/')) ->returnBody('{"response" :"okay"}') ->twice() ->send(); $client = new \GuzzleHttp\Client(); $response = $client->post('http://localhost:8081/users/1')->getBody()->getContents(); self::assertSame($response, '{"response" :"okay"}'); $response = $client->put('http://localhost:8081/users/1')->getBody()->getContents(); self::assertSame($response, '{"response" :"okay"}'); } public function tearDown() { ImposterFactory::get()->close(); } }
Proxies
Not implemented yet
统计信息
- 总下载量: 12.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-24
