Skip to content

Commit 484b184

Browse files
author
Ni Nelli
committed
chore: merge with origin
2 parents caf1c8c + c3c6115 commit 484b184

File tree

12 files changed

+71
-7
lines changed

12 files changed

+71
-7
lines changed

src/Generators/NovaTestGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function generateTests(): void
7878
'lower_entities' => $this->getPluralName(Str::snake($this->model)),
7979
'actions' => $actions,
8080
'filters' => $filters,
81+
'models_namespace' => $this->getNamespace('models'),
8182
]);
8283

8384
$this->saveClass('tests', "Nova{$this->model}ResourceTest", $fileContent);

src/Generators/RequestsGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ protected function createRequest($method, $needToValidate = true, $parameters =
7676
'namespace' => $this->getNamespace('requests'),
7777
'servicesNamespace' => $this->getNamespace('services'),
7878
'entityNamespace' => $this->getModelClass($this->model),
79+
'needToValidateWith' => !is_null(Arr::first($parameters, fn ($parameter) => $parameter['name'] === 'with.*')),
7980
]);
8081

8182
$this->saveClass('requests', "{$method}{$modelName}Request",
@@ -195,7 +196,7 @@ protected function getRules($name, $type, $required, $nullable, $present): array
195196
$rules[] = 'present';
196197
}
197198

198-
if ($name === 'order_by') {
199+
if (in_array($name, ['order_by', 'with.*'])) {
199200
$rules[] = 'in:';
200201
}
201202

stubs/nova_test.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use RonasIT\Support\Testing\ModelTestState;
66
use RonasIT\Support\Traits\NovaTestTrait;
77
use {{ $resource_namespace }};
8+
use {{ $models_namespace }}\User;
89

910
class Nova{{ $resource_name }}Test extends TestCase
1011
{

stubs/request.blade.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ class {{ $method }}{{ $entity }}Request extends Request
1616
public function rules(): array
1717
{
1818
@if(!empty($parameters))
19+
@if($needToValidateWith)
20+
$availableRelations = implode(',', $this->getAvailableRelations());
21+
22+
@endif
1923
return [
2024
@foreach($parameters as $parameter)
21-
'{{ $parameter['name'] }}' => '{!! implode('|', $parameter['rules']) !!}'@if ($parameter['name'] === 'order_by') . $this->getOrderableFields({{ Str::singular($entity) }}::class)@endif,
25+
'{{ $parameter['name'] }}' => '{!! implode('|', $parameter['rules']) !!}'@if ($parameter['name'] === 'order_by') . $this->getOrderableFields({{ Str::singular($entity) }}::class)@elseif($parameter['name'] === 'with.*'){{ ' . $availableRelations' }}@endif,
2226
@endforeach
2327
];
2428
@else
@@ -41,4 +45,13 @@ public function validateResolved(): void
4145
}
4246
}
4347
@endif
48+
@if($needToValidateWith)
49+
50+
//TODO: don't forget to review relations list
51+
protected function getAvailableRelations(): array
52+
{
53+
return [
54+
];
55+
}
56+
@endif
4457
}

tests/fixtures/CommandTest/get_request.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ class GetPostRequest extends Request
1010
{
1111
public function rules(): array
1212
{
13+
$availableRelations = implode(',', $this->getAvailableRelations());
14+
1315
return [
1416
'with' => 'array',
15-
'with.*' => 'string|required',
17+
'with.*' => 'string|required|in:' . $availableRelations,
1618
];
1719
}
1820

@@ -26,4 +28,11 @@ public function validateResolved(): void
2628
throw new NotFoundHttpException(__('validation.exceptions.not_found', ['entity' => 'Post']));
2729
}
2830
}
31+
32+
//TODO: don't forget to review relations list
33+
protected function getAvailableRelations(): array
34+
{
35+
return [
36+
];
37+
}
2938
}

tests/fixtures/CommandTest/nova_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RonasIT\Support\Testing\ModelTestState;
88
use RonasIT\Support\Traits\NovaTestTrait;
99
use App\Nova\PostResource;
10+
use RonasIT\Support\Tests\Support\Command\Models\User;
1011

1112
class NovaPostResourceTest extends TestCase
1213
{

tests/fixtures/CommandTest/search_request.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class SearchPostsRequest extends Request
99
{
1010
public function rules(): array
1111
{
12+
$availableRelations = implode(',', $this->getAvailableRelations());
13+
1214
return [
1315
'page' => 'integer',
1416
'per_page' => 'integer',
@@ -17,7 +19,14 @@ public function rules(): array
1719
'all' => 'boolean',
1820
'with' => 'array',
1921
'query' => 'string|nullable',
20-
'with.*' => 'string',
22+
'with.*' => 'string|in:' . $availableRelations,
23+
];
24+
}
25+
26+
//TODO: don't forget to review relations list
27+
protected function getAvailableRelations(): array
28+
{
29+
return [
2130
];
2231
}
2332
}

tests/fixtures/CommandTest/search_request_subfolder_model.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class SearchPostsRequest extends Request
99
{
1010
public function rules(): array
1111
{
12+
$availableRelations = implode(',', $this->getAvailableRelations());
13+
1214
return [
1315
'page' => 'integer',
1416
'per_page' => 'integer',
@@ -17,7 +19,14 @@ public function rules(): array
1719
'all' => 'boolean',
1820
'with' => 'array',
1921
'query' => 'string|nullable',
20-
'with.*' => 'string',
22+
'with.*' => 'string|in:' . $availableRelations,
23+
];
24+
}
25+
26+
//TODO: don't forget to review relations list
27+
protected function getAvailableRelations(): array
28+
{
29+
return [
2130
];
2231
}
2332
}

tests/fixtures/CommandTest/subfolder/nova_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RonasIT\Support\Testing\ModelTestState;
88
use RonasIT\Support\Traits\NovaTestTrait;
99
use App\Nova\Forum\PostResource;
10+
use RonasIT\Support\Tests\Support\Command\Models\User;
1011

1112
class NovaPostResourceTest extends TestCase
1213
{

tests/fixtures/NovaTestGeneratorTest/created_resource_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RonasIT\Support\Testing\ModelTestState;
88
use RonasIT\Support\Traits\NovaTestTrait;
99
use App\Nova\WelcomeBonusResource;
10+
use RonasIT\Support\Tests\Support\Models\User;
1011

1112
class NovaWelcomeBonusResourceTest extends TestCase
1213
{

0 commit comments

Comments
 (0)