1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shamaseen\Repository\Tests\Feature; |
4
|
|
|
|
5
|
|
|
use App\Models\Tests\Test; |
|
|
|
|
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']); |
|
|
|
|
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
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths