GrafiteInc/CrudMaker

View on GitHub
src/Templates/Laravel/Tests/Feature/AcceptanceApiTest.txt

Summary

Maintainability
Test Coverage
<?php

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class _camel_case_AcceptanceApiTest extends TestCase
{
    use DatabaseMigrations;
    use WithoutMiddleware;

    public function setUp()
    {
        parent::setUp();

        $this->_camel_case_ = factory(_namespace_model_\_camel_case_::class)->make([
            // _camel_case_ table data
        ]);
        $this->_camel_case_Edited = factory(_namespace_model_\_camel_case_::class)->make([
            // _camel_case_ table data
        ]);
        $user = factory(_app_namespace_Models\User::class)->make();
        $this->actor = $this->actingAs($user);
    }

    public function testIndex()
    {
        $response = $this->actor->call('GET', 'api/v1/_sectionRoutePrefix__lower_casePlural_');
        $this->assertEquals(200, $response->getStatusCode());
    }

    public function testStore()
    {
        $response = $this->actor->call('POST', 'api/v1/_sectionRoutePrefix__lower_casePlural_', $this->_camel_case_->toArray());
        $this->assertEquals(200, $response->getStatusCode());
        $this->seeJson(['id' => 1]);
    }

    public function testUpdate()
    {
        $this->actor->call('POST', 'api/v1/_sectionRoutePrefix__lower_casePlural_', $this->_camel_case_->toArray());
        $response = $this->actor->call('PATCH', 'api/v1/_sectionRoutePrefix__lower_casePlural_/1', $this->_camel_case_Edited->toArray());
        $this->assertEquals(200, $response->getStatusCode());
        $this->assertDatabaseHas('_table_name_', $this->_camel_case_Edited->toArray());
    }

    public function testDelete()
    {
        $this->actor->call('POST', 'api/v1/_sectionRoutePrefix__lower_casePlural_', $this->_camel_case_->toArray());
        $response = $this->call('DELETE', 'api/v1/_sectionRoutePrefix__lower_casePlural_/'.$this->_camel_case_->id);
        $this->assertEquals(200, $response->getStatusCode());
        $this->seeJson(['success' => '_lower_case_ was deleted']);
    }

}