|
7 | 7 | use function Pest\Laravel\artisan; |
8 | 8 | use function PHPUnit\Framework\assertStringEqualsFile; |
9 | 9 |
|
10 | | -test('Check creating Laravel Validation Rules in Request', function () { |
| 10 | +test('Check valid creating Laravel Validation Rules in Request with application/json content type', function () { |
11 | 11 | /** @var TestCase $this */ |
12 | 12 | $mapping = Config::get('openapi-server-generator.api_docs_mappings'); |
13 | 13 | $mappingValue = current($mapping); |
|
24 | 24 | $filesystem->shouldReceive('cleanDirectory', 'ensureDirectoryExists'); |
25 | 25 | $request = null; |
26 | 26 | $filesystem->shouldReceive('put')->withArgs(function ($path, $content) use (&$request) { |
27 | | - if (str_contains($path, 'LaravelValidationsRequest.php')) { |
| 27 | + if (str_contains($path, 'LaravelValidationsApplicationJsonRequest.php')) { |
28 | 28 | $request = $content; |
29 | 29 | } |
30 | 30 |
|
|
37 | 37 | $validationsEnd = strpos($request, '];', $validationsStart) + 2; |
38 | 38 | $validations = substr($request, $validationsStart, $validationsEnd - $validationsStart); |
39 | 39 |
|
40 | | - assertStringEqualsFile(__DIR__ . '/expects/LaravelValidationsRequest.php', $validations); |
| 40 | + assertStringEqualsFile(__DIR__ . '/expects/LaravelValidationsApplicationJsonRequest.php', $validations); |
| 41 | +}); |
| 42 | + |
| 43 | +test('Check valid creating Laravel Validation Rules in Request with multipart/form-data content type', function () { |
| 44 | + /** @var TestCase $this */ |
| 45 | + $mapping = Config::get('openapi-server-generator.api_docs_mappings'); |
| 46 | + $mappingValue = current($mapping); |
| 47 | + $mapping = [$this->makeFilePath(__DIR__ . '/resources/index.yaml') => $mappingValue]; |
| 48 | + Config::set('openapi-server-generator.api_docs_mappings', $mapping); |
| 49 | + |
| 50 | + $filesystem = $this->mock(Filesystem::class); |
| 51 | + $filesystem->shouldReceive('exists')->andReturn(false); |
| 52 | + $filesystem->shouldReceive('get')->withArgs(function ($path) { |
| 53 | + return (bool)strstr($path, '.template'); |
| 54 | + })->andReturnUsing(function ($path) { |
| 55 | + return file_get_contents($path); |
| 56 | + }); |
| 57 | + $filesystem->shouldReceive('cleanDirectory', 'ensureDirectoryExists'); |
| 58 | + $request = null; |
| 59 | + $filesystem->shouldReceive('put')->withArgs(function ($path, $content) use (&$request) { |
| 60 | + if (str_contains($path, 'LaravelValidationsMultipartFormDataRequest.php')) { |
| 61 | + $request = $content; |
| 62 | + } |
| 63 | + |
| 64 | + return true; |
| 65 | + }); |
| 66 | + |
| 67 | + artisan(GenerateServer::class); |
| 68 | + |
| 69 | + $validationsStart = strpos($request, "public function rules(): array") + 37; |
| 70 | + $validationsEnd = strpos($request, '];', $validationsStart) + 2; |
| 71 | + $validations = substr($request, $validationsStart, $validationsEnd - $validationsStart); |
| 72 | + |
| 73 | + assertStringEqualsFile(__DIR__ . '/expects/LaravelValidationsMultipartFormDataRequest.php', $validations); |
| 74 | +}); |
| 75 | + |
| 76 | +test('Check valid creating Laravel Validation Rules in Request with non available content type', function () { |
| 77 | + /** @var TestCase $this */ |
| 78 | + $mapping = Config::get('openapi-server-generator.api_docs_mappings'); |
| 79 | + $mappingValue = current($mapping); |
| 80 | + $mapping = [$this->makeFilePath(__DIR__ . '/resources/index.yaml') => $mappingValue]; |
| 81 | + Config::set('openapi-server-generator.api_docs_mappings', $mapping); |
| 82 | + |
| 83 | + $filesystem = $this->mock(Filesystem::class); |
| 84 | + $filesystem->shouldReceive('exists')->andReturn(false); |
| 85 | + $filesystem->shouldReceive('get')->withArgs(function ($path) { |
| 86 | + return (bool)strstr($path, '.template'); |
| 87 | + })->andReturnUsing(function ($path) { |
| 88 | + return file_get_contents($path); |
| 89 | + }); |
| 90 | + $filesystem->shouldReceive('cleanDirectory', 'ensureDirectoryExists'); |
| 91 | + $request = null; |
| 92 | + $filesystem->shouldReceive('put')->withArgs(function ($path, $content) use (&$request) { |
| 93 | + if (str_contains($path, 'LaravelValidationsNonAvailableContentTypeRequest.php')) { |
| 94 | + $request = $content; |
| 95 | + } |
| 96 | + |
| 97 | + return true; |
| 98 | + }); |
| 99 | + |
| 100 | + artisan(GenerateServer::class); |
| 101 | + |
| 102 | + $validationsStart = strpos($request, "public function rules(): array") + 37; |
| 103 | + $validationsEnd = strpos($request, '];', $validationsStart) + 2; |
| 104 | + $validations = substr($request, $validationsStart, $validationsEnd - $validationsStart); |
| 105 | + |
| 106 | + assertStringEqualsFile(__DIR__ . '/expects/LaravelValidationsNonAvailableContentTypeRequest.php', $validations); |
41 | 107 | }); |
0 commit comments