Skip to content

Instantly share code, notes, and snippets.

@geggleto
Created May 4, 2015 15:49
Show Gist options
  • Select an option

  • Save geggleto/a288aacba2c51610e553 to your computer and use it in GitHub Desktop.

Select an option

Save geggleto/a288aacba2c51610e553 to your computer and use it in GitHub Desktop.
guzzle app test
<?php
class UserTest extends \PHPUnit_Framework_TestCase {
/**
*
* @var GuzzleHttp\Client
*/
private $client;
public function setUp() {
include "./vendor/autoload.php";
$this->client = new \GuzzleHttp\Client();
\API\Config\Route::setupDatabase();
}
public function testGetUserWithCSRFKey() {
$res = $this->client->get('http://localhost/api/user/1', [
"headers" => [
"X-CSRF-TOKEN" => "1234567890123456"
],
"exceptions" => false
]);
$body = $res->getBody()->read(1024);
$expected = \API\Models\VuPoint\User::find(1)->toJson();
$this->assertEquals(
$expected,
$body
);
}
public function testGetUserWithNoKey() {
$res = $this->client->get('http://localhost/api/user/1', [
"headers" => [
"X-CSRF-TOKEN" => ""
],
"exceptions" => false
]);
$this->assertEquals(401, $res->getStatusCode());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment