1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shamaseen\Repository\Tests\Feature; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Tests\TestController; |
|
|
|
|
6
|
|
|
use App\Models\Tests\Test; |
|
|
|
|
7
|
|
|
use Illuminate\Support\Facades\Route; |
8
|
|
|
use Shamaseen\Repository\Tests\TestCase; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
|
11
|
|
|
class CrudTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param string $dataName |
15
|
|
|
*/ |
16
|
|
|
public function __construct(?string $name = null, array $data = [], $dataName = '') |
17
|
|
|
{ |
18
|
|
|
parent::__construct($name, $data, $dataName); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function setUp(): void |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
$this->artisan("generate:repository $this->userPath/$this->modelName -f"); |
25
|
|
|
$this->createDatabase(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function tearDown(): void |
29
|
|
|
{ |
30
|
|
|
$this->dropDatabase(); |
31
|
|
|
parent::tearDown(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testIndex() |
35
|
|
|
{ |
36
|
|
|
Route::get('tests', [TestController::class, 'index']); |
37
|
|
|
|
38
|
|
|
$response = $this->getJson('tests'); |
39
|
|
|
|
40
|
|
|
$this->assertContains($response->getStatusCode(), [ |
41
|
|
|
Response::HTTP_OK, Response::HTTP_PARTIAL_CONTENT, |
42
|
|
|
]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCreate() |
46
|
|
|
{ |
47
|
|
|
Route::get('tests/create', [TestController::class, 'create']); |
48
|
|
|
|
49
|
|
|
$response = $this->getJson('tests/create'); |
50
|
|
|
$this->assertContains($response->getStatusCode(), [ |
51
|
|
|
Response::HTTP_NO_CONTENT, |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testShow() |
56
|
|
|
{ |
57
|
|
|
$test = Test::create([ |
58
|
|
|
'name' => 'test name', |
59
|
|
|
'type' => 'a test' |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
Route::get('tests/{id}', [TestController::class, 'show']); |
63
|
|
|
|
64
|
|
|
$response = $this->getJson('tests/'.$test->id); |
65
|
|
|
|
66
|
|
|
$this->assertContains($response->getStatusCode(), [ |
67
|
|
|
Response::HTTP_OK, |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testStore() |
72
|
|
|
{ |
73
|
|
|
Route::post('tests', [TestController::class, 'store']); |
74
|
|
|
|
75
|
|
|
$data = [ |
76
|
|
|
'name' => 'Create Test', |
77
|
|
|
'type' => 'New', |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
$response = $this->postJson('tests', $data); |
81
|
|
|
$this->assertContains($response->getStatusCode(), [ |
82
|
|
|
Response::HTTP_CREATED, |
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
$content = json_decode($response->getContent())->data; |
86
|
|
|
|
87
|
|
|
$test = Test::findOrFail($content->id); |
88
|
|
|
$this->assertEquals($data['name'], $test->name); |
89
|
|
|
$this->assertEquals($data['type'], $test->type); |
90
|
|
|
|
91
|
|
|
return $content->id; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testUpdate() |
95
|
|
|
{ |
96
|
|
|
Route::put('tests/{id}', [TestController::class, 'update']); |
97
|
|
|
|
98
|
|
|
$test = Test::create([ |
99
|
|
|
'name' => 'test name', |
100
|
|
|
'type' => 'a test' |
101
|
|
|
]); |
102
|
|
|
|
103
|
|
|
$data = [ |
104
|
|
|
'name' => 'Update Test', |
105
|
|
|
'type' => 'Updated', |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
$response = $this->putJson('tests/'.$test->id, $data); |
109
|
|
|
|
110
|
|
|
$this->assertContains($response->getStatusCode(), [ |
111
|
|
|
Response::HTTP_OK, |
112
|
|
|
]); |
113
|
|
|
|
114
|
|
|
$test = Test::findOrFail($test->id); |
115
|
|
|
$this->assertEquals($data['name'], $test->name); |
116
|
|
|
$this->assertEquals($data['type'], $test->type); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testDelete() |
120
|
|
|
{ |
121
|
|
|
Route::delete('tests/{id}', [TestController::class, 'destroy']); |
122
|
|
|
|
123
|
|
|
$test = Test::create([ |
124
|
|
|
'name' => 'test name', |
125
|
|
|
'type' => 'a test' |
126
|
|
|
]); |
127
|
|
|
|
128
|
|
|
$response = $this->deleteJson('tests/'.$test->id); |
129
|
|
|
$this->assertContains($response->getStatusCode(), [ |
130
|
|
|
Response::HTTP_OK, |
131
|
|
|
]); |
132
|
|
|
|
133
|
|
|
$this->assertNull(Test::find($test->id)); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
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