Passed
Push — hotfix/fix-patch-5 ( 649db8...a85fda )
by Fu
03:18
created

ExampleTest::createApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Modules\Example\Tests;
4
5
use Illuminate\Contracts\Console\Kernel;
6
use Illuminate\Support\Str;
7
use Modules\Core\Enums\StatusCodeEnum;
8
use Modules\Example\Database\Seeders\ExampleTableSeederTableSeeder;
9
use Illuminate\Foundation\Testing\TestCase;
10
use Illuminate\Foundation\Testing\RefreshDatabase;
11
12
class ExampleTest extends TestCase
13
{
14
    use RefreshDatabase;
0 ignored issues
show
introduced by
The trait Illuminate\Foundation\Testing\RefreshDatabase requires some properties which are not provided by Modules\Example\Tests\ExampleTest: $connectionsToTransact, $dropViews, $dropTypes
Loading history...
15
16
    private $baseUri = 'api/v1/';
17
    private $resource = 'examples';
18
    private $uri;
19
20
    /**
21
     * Creates the application.
22
     *
23
     * @return \Illuminate\Foundation\Application
24
     */
25
    public function createApplication()
26
    {
27
        $app = require __DIR__.'/../../../bootstrap/app.php';
28
29
        $app->make(Kernel::class)->bootstrap();
30
31
        return $app;
32
    }
33
34
    public function __construct()
35
    {
36
        $this->uri = $this->baseUri.Str::plural($this->resource);
37
    }
38
39
    public function testIndex()
40
    {
41
        $this->get("{$this->uri}")->assertStatus(StatusCodeEnum::HTTP_OK);
42
    }
43
44
    public function testStore()
45
    {
46
        $this->post("{$this->uri}", ['name' => 'demo', 'value' => 'hello world'])
47
             ->assertStatus(StatusCodeEnum::HTTP_CREATED);
48
    }
49
50
    public function testShow()
51
    {
52
        $this->seed(ExampleTableSeederTableSeeder::class);
53
54
        $this->get("{$this->uri}/1")->assertStatus(StatusCodeEnum::HTTP_OK);
55
    }
56
57
    public function testUpdate()
58
    {
59
        $this->seed(ExampleTableSeederTableSeeder::class);
60
61
        $this->put("{$this->uri}/1", ['value' => 'Hello World'])->assertStatus(StatusCodeEnum::HTTP_RESET_CONTENT);
62
    }
63
64
    public function testDestroy()
65
    {
66
        $this->seed(ExampleTableSeederTableSeeder::class);
67
68
        $this->delete("{$this->uri}/1")->assertStatus(StatusCodeEnum::HTTP_NO_CONTENT);
69
    }
70
}
71