-
-
Save dshafik/8dd92f2c6cb159993cf2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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