|
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 | use function PHPUnit\Framework\assertEqualsCanonicalizing; |
9 | 10 | use function PHPUnit\Framework\assertNotTrue; |
10 | 11 | use function PHPUnit\Framework\assertStringContainsString; |
|
162 | 163 | ); |
163 | 164 | }); |
164 | 165 |
|
165 | | -test("Update tests success", function () { |
| 166 | +test("Update tests success", function (array $parameters, bool $withControllerEntity) { |
166 | 167 | /** @var TestCase $this */ |
167 | 168 | $mapping = Config::get('openapi-server-generator.api_docs_mappings'); |
168 | 169 | $mappingValue = current($mapping); |
169 | 170 | $mapping = [$this->makeFilePath(__DIR__ . '/resources/index.yaml') => $mappingValue]; |
170 | 171 | Config::set('openapi-server-generator.api_docs_mappings', $mapping); |
171 | 172 |
|
| 173 | + $appRoot = realpath($this->makeFilePath(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/')); |
| 174 | + |
172 | 175 | $existTest = $this->makeFilePath('/app/Http/Tests/ResourcesComponentTest.php'); |
173 | 176 |
|
174 | 177 | $filesystem = $this->mock(Filesystem::class); |
175 | | - $filesystem->shouldReceive('exists')->andReturnUsing(function ($path) { |
176 | | - // todo |
177 | | - return false; |
| 178 | + $filesystem->shouldReceive('exists')->andReturnUsing(function ($path) use ($appRoot, $existTest) { |
| 179 | + $filePath = $this->makeFilePath(str_replace($appRoot, '', $path)); |
| 180 | + |
| 181 | + return $filePath === $existTest; |
178 | 182 | }); |
179 | 183 |
|
180 | 184 | $filesystem->shouldReceive('get')->withArgs(function ($path) { |
|
183 | 187 | return file_get_contents($path); |
184 | 188 | }); |
185 | 189 | $filesystem->shouldReceive('cleanDirectory', 'ensureDirectoryExists'); |
186 | | - $appRoot = realpath($this->makeFilePath(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/')); |
| 190 | + |
187 | 191 | $putFiles = []; |
188 | 192 | $filesystem->shouldReceive('put')->withArgs(function ($path, $content) use (&$putFiles, $appRoot) { |
189 | 193 | $filePath = $this->makeFilePath(str_replace($appRoot, '', $path)); |
|
192 | 196 | return true; |
193 | 197 | }); |
194 | 198 |
|
195 | | - artisan(GenerateServer::class); |
| 199 | + $appendFiles = []; |
| 200 | + $filesystem->shouldReceive('append')->withArgs(function ($filePath, $data) use (&$appendFiles, $appRoot, $existTest) { |
| 201 | + $filePath = $this->makeFilePath(str_replace($appRoot, '', $filePath)); |
| 202 | + $appendFiles[$filePath] = $data; |
196 | 203 |
|
197 | | - // todo: check exist test |
| 204 | + return true; |
| 205 | + }); |
198 | 206 |
|
199 | | -}); |
| 207 | + artisan(GenerateServer::class, $parameters); |
| 208 | + |
| 209 | + $appendData = [ |
| 210 | + 'POST /resources:test-generate-without-properties 200', |
| 211 | + 'POST /resources:test-empty-rename-request 200', |
| 212 | + 'POST /resources:test-rename-request 200', |
| 213 | + 'POST /resources:test-laravel-validations-application-json-request 200', |
| 214 | + 'POST /resources:test-laravel-validations-multipart-form-data-request 200', |
| 215 | + 'POST /resources:test-laravel-validations-non-available-content-type 200', |
| 216 | + 'POST /resources:test-generate-resource-bad-response-key 200', |
| 217 | + 'POST /resources:test-generate-without-properties 200', |
| 218 | + ]; |
| 219 | + |
| 220 | + assertEquals(isset($appendFiles[$existTest]), $withControllerEntity); |
| 221 | + |
| 222 | + if ($withControllerEntity) { |
| 223 | + $appendTestData = $appendFiles[$existTest]; |
| 224 | + foreach ($appendData as $data) { |
| 225 | + assertStringContainsString($data, $appendTestData); |
| 226 | + } |
| 227 | + } |
| 228 | +})->with([ |
| 229 | + [['-e' => 'pest_tests'], false], |
| 230 | + [['-e' => 'controllers,pest_tests'], true], |
| 231 | + [['-e' => 'pest_tests,controllers'], true], |
| 232 | + [[], true], |
| 233 | +]); |
0 commit comments