Skip to content

Commit c0ce143

Browse files
committed
#81891 Tests
1 parent 881e4e8 commit c0ce143

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/GenerateServerTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Illuminate\Support\Facades\Config;
77
use function Pest\Laravel\artisan;
88
use function PHPUnit\Framework\assertEqualsCanonicalizing;
9+
use function PHPUnit\Framework\assertNotTrue;
10+
use function PHPUnit\Framework\assertStringContainsString;
911

1012
test("Command GenerateServer success", function () {
1113
/** @var TestCase $this */
@@ -50,3 +52,59 @@
5052
$this->makeFilePath('/app/Http/ApiV1/OpenApiGenerated/Enums/TestStringEnum.php'),
5153
], $putFiles);
5254
});
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

Comments
 (0)