|
5 | 5 | use Illuminate\Filesystem\Filesystem; |
6 | 6 | use Illuminate\Support\Facades\Config; |
7 | 7 | use function Pest\Laravel\artisan; |
| 8 | +use function PHPUnit\Framework\assertEquals; |
8 | 9 |
|
| 10 | +function makeFilePath(string $path): string |
| 11 | +{ |
| 12 | + return str_replace('/', DIRECTORY_SEPARATOR, $path); |
| 13 | +} |
9 | 14 | test("Command GenerateServer success", function () { |
10 | 15 | /** @var TestCase $this */ |
11 | 16 | $mapping = Config::get('openapi-server-generator.api_docs_mappings'); |
12 | 17 | $mappingValue = current($mapping); |
13 | | - $mapping = [__DIR__ . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'index.yaml' => $mappingValue]; |
| 18 | + $mapping = [makeFilePath(__DIR__ . '/resources/index.yaml') => $mappingValue]; |
14 | 19 | Config::set('openapi-server-generator.api_docs_mappings', $mapping); |
15 | 20 |
|
16 | 21 | $filesystem = $this->mock(Filesystem::class); |
|
20 | 25 | })->andReturnUsing(function ($path) { |
21 | 26 | return file_get_contents($path); |
22 | 27 | }); |
23 | | - $filesystem->shouldReceive('put', 'cleanDirectory', 'ensureDirectoryExists'); |
| 28 | + $filesystem->shouldReceive('cleanDirectory', 'ensureDirectoryExists'); |
| 29 | + $appRoot = realpath(makeFilePath(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/')); |
| 30 | + $putFiles = []; |
| 31 | + $filesystem->shouldReceive('put')->withArgs(function ($path, $content) use (&$putFiles, $appRoot) { |
| 32 | + $putFiles[] = str_replace($appRoot, '', $path); |
| 33 | + |
| 34 | + return true; |
| 35 | + }); |
24 | 36 |
|
25 | 37 | artisan(GenerateServer::class); |
| 38 | + |
| 39 | + $needFiles = [ |
| 40 | + makeFilePath('/app/Http/ApiV1/OpenApiGenerated/routes.php'), |
| 41 | + |
| 42 | + makeFilePath('/app/Http/Controllers/ResourcesController.php'), |
| 43 | + makeFilePath('/app/Http/Requests/TestFullGenerateRequest.php'), |
| 44 | + makeFilePath('/app/Http/Tests/ResourcesComponentTest.php'), |
| 45 | + makeFilePath('/app/Http/Requests/TestFooRenameRequest.php'), |
| 46 | + |
| 47 | + makeFilePath('/app/Http/Controllers/WithoutResponsesController.php'), |
| 48 | + |
| 49 | + makeFilePath('/WithoutNamespaceController.php'), |
| 50 | + makeFilePath('/WithoutNamespaceRequest.php'), |
| 51 | + makeFilePath('/WithoutNamespaceComponentTest.php'), |
| 52 | + |
| 53 | + makeFilePath('/app/Http/ApiV1/OpenApiGenerated/Enums/TestIntegerEnum.php'), |
| 54 | + makeFilePath('/app/Http/ApiV1/OpenApiGenerated/Enums/TestStringEnum.php'), |
| 55 | + ]; |
| 56 | + sort($needFiles); |
| 57 | + sort($putFiles); |
| 58 | + assertEquals($needFiles, $putFiles); |
26 | 59 | }); |
0 commit comments