Passed
Push — main ( a090f0...c348a6 )
by Mohammad
11:53
created

CrudTest::testCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Shamaseen\Repository\Tests\Feature;
4
5
use App\Models\Tests\Test;
0 ignored issues
show
Bug introduced by
The type App\Models\Tests\Test was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Facades\Route;
7
use Shamaseen\Repository\Tests\TestCase;
8
use Symfony\Component\HttpFoundation\Response;
9
10
class CrudTest extends TestCase
11
{
12
    protected string $modelName = 'Test';
13
    protected string $userPath = 'Tests';
14
15
    /**
16
     * @param string $dataName
17
     */
18
    public function __construct(?string $name = null, array $data = [], $dataName = '')
19
    {
20
        parent::__construct($name, $data, $dataName);
21
    }
22
23
    public function setUp(): void
24
    {
25
        parent::setUp();
26
    }
27
28
    public function testIndex()
29
    {
30
        Route::get('tests', [\App\Http\Controllers\Tests\TestController::class, 'index']);
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Tests\TestController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
32
        $response = $this->getJson('tests');
33
        $this->assertContains($response->getStatusCode(), [
34
            Response::HTTP_OK, Response::HTTP_PARTIAL_CONTENT,
35
        ]);
36
    }
37
38
    public function testShow()
39
    {
40
        Route::get('tests/{id}', [\App\Http\Controllers\Tests\TestController::class, 'show']);
41
42
        $response = $this->getJson('tests/1');
43
44
        $this->assertContains($response->getStatusCode(), [
45
            Response::HTTP_OK,
46
        ]);
47
    }
48
49
    public function testCreate()
50
    {
51
        Route::get('tests/create', [\App\Http\Controllers\Tests\TestController::class, 'create']);
52
53
        $response = $this->getJson('tests/create');
54
        $this->assertContains($response->getStatusCode(), [
55
            Response::HTTP_NO_CONTENT,
56
        ]);
57
    }
58
59
    public function testStore()
60
    {
61
        Route::post('tests', [\App\Http\Controllers\Tests\TestController::class, 'store']);
62
63
        $data = [
64
            'name' => 'Create Test',
65
            'type' => 'New',
66
        ];
67
68
        $response = $this->postJson('tests', $data);
69
        $this->assertContains($response->getStatusCode(), [
70
            Response::HTTP_CREATED,
71
        ]);
72
73
        $content = json_decode($response->getContent())->data;
74
75
        $test = Test::findOrFail($content->id);
76
        $this->assertEquals($data['name'], $test->name);
77
        $this->assertEquals($data['type'], $test->type);
78
79
        return $content->id;
80
    }
81
82
    /**
83
     * @depends testStore
84
     */
85
    public function testUpdate(int $id)
86
    {
87
        Route::put('tests/{id}', [\App\Http\Controllers\Tests\TestController::class, 'update']);
88
89
        $data = [
90
            'name' => 'Update Test',
91
            'type' => 'Updated',
92
        ];
93
94
        $response = $this->putJson('tests/'.$id, $data);
95
96
        $this->assertContains($response->getStatusCode(), [
97
            Response::HTTP_OK,
98
        ]);
99
100
        $test = Test::findOrFail($id);
101
        $this->assertEquals($data['name'], $test->name);
102
        $this->assertEquals($data['type'], $test->type);
103
    }
104
105
    /**
106
     * @depends testStore
107
     */
108
    public function testDelete(int $id)
109
    {
110
        Route::delete('tests/{id}', [\App\Http\Controllers\Tests\TestController::class, 'destroy']);
111
112
        $response = $this->deleteJson('tests/'.$id);
113
        $this->assertContains($response->getStatusCode(), [
114
            Response::HTTP_OK,
115
        ]);
116
    }
117
}
118