blastcloud/hybrid
Composer 安装命令:
composer require blastcloud/hybrid
包简介
Charge up your app or SDK with a testing library specifically for Symfony/HttpClient
README 文档
README
Full Documentation at hybrid.guzzler.dev
Charge up your app or SDK with a testing library specifically for Symfony/HttpClient.
Installation
composer require --dev --prefer-dist blastcloud/hybrid
Example Usage
<?php use BlastCloud\Hybrid\{Expectation, UsesHybrid}; use Symfony\Component\HttpClient\Response\MockResponse; use PHPUnit\Framework\TestCase; class SomeTest extends TestCase { use UsesHybrid; public $classToTest; public function setUp(): void { parent::setUp(); $client = $this->hybrid->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->hybrid->expects($this->once()) ->post("/some-url") ->withHeader("X-Authorization", "some-key") ->willRespond(new MockResponse("Some body")); $this->classToTest->someMethod(); } public function testSomethingWithAssertions() { $this->hybrid->queueResponse( new MockResponse(null, ['http_code' => 204]), new \Exception("Some message"), // any needed responses to return from the client. ); $this->classToTest->someMethod(); // ... Some other number of calls $this->hybrid->assertAll(function (Expectation $expect) { return $expect->withHeader("Authorization", "some-key"); }); } }
Documentation
License
Hybrid is open-source software licensed under the MIT License.
统计信息
- 总下载量: 5.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 43
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-06