PHP code example of blastcloud / guzzler
1. Go to this page and download the library: Download blastcloud/guzzler library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
blastcloud / guzzler example snippets
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");
});
}
}