ExampleTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createApplication() 0 7 1
A testStore() 0 4 1
A testShow() 0 5 1
A testUpdate() 0 5 1
A testDestroy() 0 5 1
A __construct() 0 3 1
A testIndex() 0 3 1
1
<?php
2
3
namespace Modules\Example\Tests;
4
5
use Illuminate\Contracts\Console\Kernel;
6
use Illuminate\Foundation\Testing\RefreshDatabase;
7
use Illuminate\Foundation\Testing\TestCase;
8
use Illuminate\Support\Str;
9
use Modules\Core\Enums\StatusCodeEnum;
10
use Modules\Example\Database\Seeders\ExampleTableSeederTableSeeder;
11
12
class ExampleTest extends TestCase
13
{
14
    use RefreshDatabase;
15
16
    protected $connectionsToTransact = [null];
17
    protected $dropViews = false;
18
    protected $dropTypes = false;
19
20
    private $baseUri = 'api/v1/';
21
    private $resource = 'examples';
22
    private $uri;
23
24
    /**
25
     * Creates the application.
26
     *
27
     * @return \Illuminate\Foundation\Application
28
     */
29
    public function createApplication()
30
    {
31
        $app = require __DIR__.'/../../../bootstrap/app.php';
32
33
        $app->make(Kernel::class)->bootstrap();
34
35
        return $app;
36
    }
37
38
    public function __construct()
39
    {
40
        $this->uri = $this->baseUri.Str::plural($this->resource);
41
    }
42
43
    public function testIndex()
44
    {
45
        $this->get("{$this->uri}")->assertStatus(StatusCodeEnum::HTTP_OK);
46
    }
47
48
    public function testStore()
49
    {
50
        $this->post("{$this->uri}", ['name' => 'demo', 'value' => 'hello world'])
51
             ->assertStatus(StatusCodeEnum::HTTP_CREATED);
52
    }
53
54
    public function testShow()
55
    {
56
        $this->seed(ExampleTableSeederTableSeeder::class);
57
58
        $this->get("{$this->uri}/1")->assertStatus(StatusCodeEnum::HTTP_OK);
59
    }
60
61
    public function testUpdate()
62
    {
63
        $this->seed(ExampleTableSeederTableSeeder::class);
64
65
        $this->put("{$this->uri}/1", ['value' => 'Hello World'])->assertStatus(StatusCodeEnum::HTTP_RESET_CONTENT);
66
    }
67
68
    public function testDestroy()
69
    {
70
        $this->seed(ExampleTableSeederTableSeeder::class);
71
72
        $this->delete("{$this->uri}/1")->assertStatus(StatusCodeEnum::HTTP_NO_CONTENT);
73
    }
74
}
75