Created
December 13, 2017 11:12
-
-
Save summerblue/89b4b8f629bf1e1d8f85ddf77de1d0a7 to your computer and use it in GitHub Desktop.
InfyOmLabs/laravel-generator 生成的测试 API 代码
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 | |
use Illuminate\Foundation\Testing\WithoutMiddleware; | |
use Illuminate\Foundation\Testing\DatabaseTransactions; | |
class PoostApiTest extends TestCase | |
{ | |
use MakePoostTrait, ApiTestTrait, WithoutMiddleware, DatabaseTransactions; | |
/** | |
* @test | |
*/ | |
public function testCreatePoost() | |
{ | |
$poost = $this->fakePoostData(); | |
$this->json('POST', '/api/v1/poosts', $poost); | |
$this->assertApiResponse($poost); | |
} | |
/** | |
* @test | |
*/ | |
public function testReadPoost() | |
{ | |
$poost = $this->makePoost(); | |
$this->json('GET', '/api/v1/poosts/'.$poost->id); | |
$this->assertApiResponse($poost->toArray()); | |
} | |
/** | |
* @test | |
*/ | |
public function testUpdatePoost() | |
{ | |
$poost = $this->makePoost(); | |
$editedPoost = $this->fakePoostData(); | |
$this->json('PUT', '/api/v1/poosts/'.$poost->id, $editedPoost); | |
$this->assertApiResponse($editedPoost); | |
} | |
/** | |
* @test | |
*/ | |
public function testDeletePoost() | |
{ | |
$poost = $this->makePoost(); | |
$this->json('DELETE', '/api/v1/poosts/'.$poost->id); | |
$this->assertApiSuccess(); | |
$this->json('GET', '/api/v1/poosts/'.$poost->id); | |
$this->assertResponseStatus(404); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment