Created
May 21, 2013 22:37
-
-
Save JeffreyWay/5623836 to your computer and use it in GitHub Desktop.
Revisions
-
JeffreyWay revised this gist
May 21, 2013 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ <?php class PhotoApiTest extends TestCase { -
JeffreyWay created this gist
May 21, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ <?php // TODO: Write this chapter. // Add section to using dbs about SQlite in memory class PhotoApiTest extends TestCase { public function setUp() { parent::setUp(); Route::enableFilters(); Artisan::call('migrate'); Artisan::call('db:seed'); Auth::loginUsingId(1); // OR: //$this->be(User::find(1)); } public function testMustBeAuthenticated() { Auth::logout(); $response = $this->call('GET', 'api/v1/photos'); $this->assertEquals('Invalid credentials.', $response->getContent()); } public function testProvidesErrorFeedback() { $response = $this->call('GET', 'api/v1/photos'); $data = $this->parseJson($response); $this->assertEquals(false, $data->error); } public function testFetchesAllPhotosForUser() { $response = $this->call('GET', 'api/v1/photos'); $data = $this->parseJson($response); $this->assertIsJson($data); $this->assertInternalType('array', $data->photos); } public function testCreatesPhoto() { $photo = [ 'caption' => 'My new photo', 'path' => 'foo.jpg', 'user_id' => 1 ]; $response = $this->call('POST', 'api/v1/photos', $photo); $data = $this->parseJson($response); $this->assertEquals(false, $data->error); $this->assertEquals('Photo was created', $data->message); } protected function parseJson(Illuminate\Http\JsonResponse $response) { return json_decode($response->getContent()); } protected function assertIsJson($data) { $this->assertEquals(0, json_last_error()); } }