Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Tests\Feature;
- use App\Models\SomeClass as Model;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- /**
- * Assert API Endpoint return status code 200.
- * $this->assertOkStatusCode('/api/endpoint'); // to ensure API endpoint return status code 200.
- *
- * Assert API Endpoint return expected output.
- * $this->assertApiResponse('/api/endpoint', []); // second argument is the response expected to be received
- */
- class SomeClassTest extends TestCase
- {
- use RefreshDatabase;
- const API_NAME = 'test';
- protected function setUp(): void
- {
- parent::setUp();
- Model::insert([
- 'type' => 'type1',
- 'created_at' => '2019-09-25 00:00:00',
- 'updated_at' => '2019-09-25 00:00:00',
- ],[
- 'type' => 'type2',
- 'created_at' => '2019-09-25 00:00:00',
- 'updated_at' => '2019-09-25 00:00:00',
- ]);
- }
- /**
- result of this test case is succeed because type1 data available
- */
- /** @test */
- public function it_can_get_latest_list_with_type_param_type1()
- {
- $this->assertApiResponse('api/' . self::API_NAME . '?type=type1', [
- 'data' => [
- 'type' => 'type1',
- ],
- 'meta' => [
- 'last_updated' => '2019-09-25 00:00:00',
- 'total_result' => 1,
- ],
- ]);
- }
- /**
- result of this test case is fail, it returns no records
- */
- /** @test */
- public function it_can_get_latest_list_with_type_param_type2()
- {
- $this->assertApiResponse('api/' . self::API_NAME . '?type=type2', [
- 'data' => [
- 'type' => 'type2',
- ],
- 'meta' => [
- 'last_updated' => '2019-09-25 00:00:00',
- 'total_result' => 1,
- ],
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement