Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dshafik
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dshafik/8dd92f2c6cb159993cf2 to your computer and use it in GitHub Desktop.
Save dshafik/8dd92f2c6cb159993cf2 to your computer and use it in GitHub Desktop.
<?php
class ApiClientTest {
/**
* @var \GuzzleHttp\Client
*/
protected $client;
public function setUp()
{
if (!file_exists(__DIR__ . '/fixtures')) {
mkdir(__DIR__ . '/fixtures');
}
$handler = \Dshafik\GuzzleHttp\VcrHandler::turnOn(
__DIR__ . '/fixtures/' . lcfirst(substr($this->getName(), 4)) . '.json'
);
$this->client = new \GuzzleHttp\Client([
'base_uri' => $this->host,
'handler' => $handler
]);
}
public function testSomething()
{
// will be recorded to __DIR__/fixtures/something.json
$this->assertInstanceOf(\GuzzleHttp\Psr7\Response::class, $this->client->get('/test'));
}
public function testSomethingElse()
{
// will record to __DIR__/fixtures/somethingElse.json
$this->asserInstanceOf(\GuzzleHttp\Psr7\Response::class, $this->client->post('/test', ['body' => 'contents']));
$response = $this->client->get('/test');
$this->assertInstanceOf(\GuzzleHttp\Psr7\Response::class, $response);
$this->assertEquals('contents', (string) $response->getBody());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment