|
6 | 6 | use Illuminate\Support\Facades\Config; |
7 | 7 | use function Pest\Laravel\artisan; |
8 | 8 | use function PHPUnit\Framework\assertEqualsCanonicalizing; |
| 9 | +use function PHPUnit\Framework\assertNotTrue; |
| 10 | +use function PHPUnit\Framework\assertStringContainsString; |
9 | 11 |
|
10 | 12 | test("Command GenerateServer success", function () { |
11 | 13 | /** @var TestCase $this */ |
|
50 | 52 | $this->makeFilePath('/app/Http/ApiV1/OpenApiGenerated/Enums/TestStringEnum.php'), |
51 | 53 | ], $putFiles); |
52 | 54 | }); |
| 55 | + |
| 56 | +test("Correct requests in controller methods", function () { |
| 57 | + /** @var TestCase $this */ |
| 58 | + $mapping = Config::get('openapi-server-generator.api_docs_mappings'); |
| 59 | + $mappingValue = current($mapping); |
| 60 | + $mapping = [$this->makeFilePath(__DIR__ . '/resources/index.yaml') => $mappingValue]; |
| 61 | + Config::set('openapi-server-generator.api_docs_mappings', $mapping); |
| 62 | + |
| 63 | + $filesystem = $this->mock(Filesystem::class); |
| 64 | + $filesystem->shouldReceive('exists')->andReturn(false); |
| 65 | + $filesystem->shouldReceive('get')->withArgs(function ($path) { |
| 66 | + return (bool)strstr($path, '.template'); |
| 67 | + })->andReturnUsing(function ($path) { |
| 68 | + return file_get_contents($path); |
| 69 | + }); |
| 70 | + $filesystem->shouldReceive('cleanDirectory', 'ensureDirectoryExists'); |
| 71 | + $resourceController = null; |
| 72 | + $withoutResponsesController = null; |
| 73 | + $filesystem->shouldReceive('put')->withArgs(function ($path, $content) use (&$resourceController, &$withoutResponsesController) { |
| 74 | + if (str_contains($path, 'ResourcesController.php')) { |
| 75 | + $resourceController = $content; |
| 76 | + } |
| 77 | + |
| 78 | + if (str_contains($path, 'WithoutResponsesController.php')) { |
| 79 | + $withoutResponsesController = $content; |
| 80 | + } |
| 81 | + |
| 82 | + return true; |
| 83 | + }); |
| 84 | + |
| 85 | + artisan(GenerateServer::class); |
| 86 | + |
| 87 | + assertNotTrue(is_null($resourceController), 'ResourceController exist'); |
| 88 | + assertStringContainsString( |
| 89 | + 'use App\Http\Requests\TestFooRenameRequest', |
| 90 | + $resourceController, |
| 91 | + 'ResourceController import' |
| 92 | + ); |
| 93 | + assertStringContainsString( |
| 94 | + 'TestFullGenerateRequest $testFullGenerateRequest', |
| 95 | + $resourceController, |
| 96 | + 'ResourceController function parameter' |
| 97 | + ); |
| 98 | + |
| 99 | + assertNotTrue(is_null($withoutResponsesController), 'WithoutResponsesController exist'); |
| 100 | + assertStringContainsString( |
| 101 | + 'use Illuminate\Http\Request', |
| 102 | + $withoutResponsesController, |
| 103 | + 'WithoutResponsesController import' |
| 104 | + ); |
| 105 | + assertStringContainsString( |
| 106 | + 'Request $request', |
| 107 | + $withoutResponsesController, |
| 108 | + 'WithoutResponsesController function parameter' |
| 109 | + ); |
| 110 | +}); |
0 commit comments