Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
InfyOmLabs/laravel-generator 生成的测试 API 代码
<?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
You can’t perform that action at this time.