blastcloud/guzzler
最新稳定版本:2.3.0
Composer 安装命令:
composer require --dev blastcloud/guzzler
包简介
Supercharge your app or SDK with a testing library specifically for Guzzle.
README 文档
README
Full Documentation at 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
composer require --dev --prefer-dist blastcloud/guzzler
Example Usage
<?php use BlastCloud\Guzzler\UsesGuzzler; use GuzzleHttp\Client; class SomeTest extends TestCase { use UsesGuzzler; public $classToTest; public function setUp(): void { parent::setUp(); $client = $this->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
License
Guzzler is open-source software licensed under the MIT License.
统计信息
- 总下载量: 393.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 272
- 点击次数: 1
- 依赖项目数: 33
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-28