Created
May 4, 2015 15:49
-
-
Save geggleto/a288aacba2c51610e553 to your computer and use it in GitHub Desktop.
guzzle app test
This file contains hidden or 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 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