Skip to content

Commit 9d4a20e

Browse files
author
Anton Filippov
committed
#81781
1 parent 04705c9 commit 9d4a20e

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

tests/LaravelValidationRulesRequestTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use function Pest\Laravel\artisan;
88
use function PHPUnit\Framework\assertStringEqualsFile;
99

10-
test('Create Request from ResourceForTestValidationRules', function () {
10+
test('Check creating Laravel Validation Rules in Request', function () {
1111
/** @var TestCase $this */
1212
$mapping = Config::get('openapi-server-generator.api_docs_mappings');
1313
$mappingValue = current($mapping);
@@ -33,5 +33,9 @@
3333

3434
artisan(GenerateServer::class);
3535

36-
assertStringEqualsFile(__DIR__ . '/expects/LaravelValidationsRequest.php', $request);
36+
$validationsStart = strpos($request, "public function rules(): array") + 37;
37+
$validationsEnd = strpos($request, '];', $validationsStart) + 2;
38+
$validations = substr($request, $validationsStart, $validationsEnd - $validationsStart);
39+
40+
assertStringEqualsFile(__DIR__ . '/expects/LaravelValidationsRequest.php', $validations);
3741
});

tests/expects/LaravelValidationsRequest.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
<?php
2-
3-
namespace App\Http\Requests;
4-
5-
use App\Http\ApiV1\OpenApiGenerated\Enums\TestIntegerEnum;
6-
use App\Http\ApiV1\Support\Requests\BaseFormRequest;
7-
use Illuminate\Validation\Rules\Enum;
8-
9-
class LaravelValidationsRequest extends BaseFormRequest
10-
{
11-
/**
12-
* Get the validation rules that apply to the request.
13-
*
14-
* @return array
15-
*/
16-
public function rules(): array
17-
{
181
return [
192
'field_object_nullable' => ['nullable'],
203
'field_object_nullable.field' => ['integer'],
@@ -43,6 +26,4 @@ public function rules(): array
4326
'field_boolean' => ['required', 'boolean'],
4427
'field_string' => ['required', 'string'],
4528
'field_integer' => ['required', 'integer'],
46-
];
47-
}
48-
}
29+
];

0 commit comments

Comments
 (0)