项目
在 GitHub 查看
blastcloud/guzzler
关于
使用专为 Guzzle 打造的测试库,增强你的应用或 SDK。
开发工具实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文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.
探索相关项目
加载中…