|
8 | 8 | use Symfony\Component\Filesystem\Filesystem; |
9 | 9 | use Symfony\Component\Filesystem\Path; |
10 | 10 | use Symfony\Lsp\Check\CheckCommand; |
| 11 | +use Symfony\Lsp\Runtime\PartialRuntimeMetadataException; |
11 | 12 | use Symfony\Lsp\Runtime\UnsupportedSymfonyVersionException; |
12 | 13 | use Symfony\Lsp\Server\ServerVersion; |
13 | 14 |
|
|
25 | 26 | * @phpstan-type SarifReport array{version: string, runs: list<SarifRun>} |
26 | 27 | * @phpstan-type CheckReport array{ |
27 | 28 | * complete: bool, |
28 | | - * projects: list<array{environment: string, analysis: array{mode: string, reason: string|null}}>, |
| 29 | + * projects: list<array{environment: string, analysis: array{mode: string, reason: string|null}, runtime: array{state: string}, complete: bool}>, |
29 | 30 | * diagnostics: list<array{code: string, path: string}>, |
30 | 31 | * summary: array{blocking: int, stale: int}, |
31 | 32 | * errors: list<array{category: string, message: string, cause?: array{class: string, message: string}}> |
@@ -311,6 +312,65 @@ public static function getPrettyVersion(string $package): ?string { return '5.4. |
311 | 312 | self::assertSame(UnsupportedSymfonyVersionException::class, $report['errors'][0]['cause']['class'] ?? null); |
312 | 313 | } |
313 | 314 |
|
| 315 | + public function testKeepsDiagnosticsBackedByHealthyRuntimeSections(): void |
| 316 | + { |
| 317 | + if ('Windows' === \PHP_OS_FAMILY) { |
| 318 | + self::markTestSkipped('The source executable integration requires Unix executable scripts.'); |
| 319 | + } |
| 320 | + |
| 321 | + mkdir($this->directory.'/src'); |
| 322 | + file_put_contents($this->directory.'/src/ArticleController.php', <<<'PHP' |
| 323 | + <?php |
| 324 | + namespace App\Controller; |
| 325 | +
|
| 326 | + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 327 | +
|
| 328 | + final class ArticleController extends AbstractController |
| 329 | + { |
| 330 | + public function show(): void |
| 331 | + { |
| 332 | + $this->generateUrl('article_show'); |
| 333 | + } |
| 334 | + } |
| 335 | + PHP); |
| 336 | + $snapshot = [ |
| 337 | + 'schemaVersion' => 1, |
| 338 | + 'project' => ['environment' => 'dev'], |
| 339 | + 'configurationValidation' => ['status' => 'valid'], |
| 340 | + 'sections' => [ |
| 341 | + 'routes' => [ |
| 342 | + 'complete' => true, |
| 343 | + 'items' => [[ |
| 344 | + 'name' => 'article_show', |
| 345 | + 'path' => '/article/{id}', |
| 346 | + ]], |
| 347 | + ], |
| 348 | + ], |
| 349 | + 'errors' => [[ |
| 350 | + 'section' => 'twig', |
| 351 | + 'message' => 'CANARY_RUNTIME_SECTION_ERROR', |
| 352 | + ]], |
| 353 | + ]; |
| 354 | + $symfonyCli = $this->directory.'/partial-runtime'; |
| 355 | + file_put_contents($symfonyCli, "#!/usr/bin/env php\n<?php\nfwrite(STDOUT, json_encode(".var_export($snapshot, true).", JSON_THROW_ON_ERROR).\"\\n\");\n"); |
| 356 | + chmod($symfonyCli, 0700); |
| 357 | + |
| 358 | + $result = $this->execute( |
| 359 | + ['check', '--format=json', '--workspace='.$this->directory, 'src/ArticleController.php'], |
| 360 | + ['SYMFONY_LSP_SYMFONY_CLI' => $symfonyCli], |
| 361 | + ); |
| 362 | + $report = $this->decodeReport($result['stdout']); |
| 363 | + |
| 364 | + self::assertSame(CheckCommand::EXIT_OPERATIONAL, $result['exitCode'], $result['stderr']); |
| 365 | + self::assertFalse($report['complete']); |
| 366 | + self::assertFalse($report['projects'][0]['complete']); |
| 367 | + self::assertSame('failed', $report['projects'][0]['runtime']['state']); |
| 368 | + self::assertSame('route.missing_parameters', $report['diagnostics'][0]['code']); |
| 369 | + self::assertSame('The project bridge could not load runtime metadata: twig.', $report['errors'][0]['message']); |
| 370 | + self::assertSame(PartialRuntimeMetadataException::class, $report['errors'][0]['cause']['class'] ?? null); |
| 371 | + self::assertSame(1, $report['summary']['blocking']); |
| 372 | + } |
| 373 | + |
314 | 374 | public function testDoesNotReportACleanResultWhenRuntimeIndexingFails(): void |
315 | 375 | { |
316 | 376 | $result = $this->execute(['check', '--format=json', '--workspace='.$this->directory]); |
|
0 commit comments