Skip to content

Commit 030feed

Browse files
committed
Accept intermediate Symfony branches
1 parent 11c58a3 commit 030feed

6 files changed

Lines changed: 62 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Unreleased
44

5-
- Report unsupported Symfony branches from live release metadata
5+
- Report Symfony branches outside the live supported range
66
- Ignore Twig macro declarations that share a name with custom functions
77
- Recognize PHP heredoc translation messages and global parameters
88
- Buffer persistent source index rewrites

docs/features/index.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,15 @@ Symfony Version Support
174174
-----------------------
175175

176176
During runtime indexing, Symfony Language Tools checks the installed branch
177-
against Symfony's `release metadata`_. Each project's metadata cache is
178-
refreshed at most once per hour under ``var/symfony-lsp/``. If a refresh fails,
179-
the last cached metadata is used. Without a cache, runtime indexing continues
180-
without the support check.
181-
182-
If the installed branch isn't supported, the application isn't booted. The
183-
editor or diagnostics checker reports the detected version and static-only
184-
features remain active.
177+
against the range between the oldest and newest branches in Symfony's `release
178+
metadata`_. Intermediate branches are accepted. Each project's metadata cache
179+
is refreshed at most once per hour under ``var/symfony-lsp/``. If a refresh
180+
fails, the last cached metadata is used. Without a cache, runtime indexing
181+
continues without the support check.
182+
183+
If the installed branch falls outside the supported range, the application
184+
isn't booted. The editor or diagnostics checker reports the detected version
185+
and static-only features remain active.
185186

186187
Unsaved Files and Refreshes
187188
---------------------------

resources/bridge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
&& is_string($releaseMetadataCache) && '' !== $releaseMetadataCache
109109
) {
110110
$supportedVersions = symfonyLspBridgeSupportedVersions($releaseMetadataUrl, $releaseMetadataCache);
111-
if (is_array($supportedVersions) && !in_array($matches[1], $supportedVersions, true)) {
111+
if (is_array($supportedVersions) && !symfonyLspBridgeSupportsBranch($matches[1], $supportedVersions)) {
112112
fwrite(STDOUT, json_encode([
113113
'schemaVersion' => 1,
114114
'project' => $projectMetadata,

resources/bridge/support.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ function symfonyLspBridgeSupportedVersions(string $url, string $cache): ?array
4949
return is_string($cached) ? symfonyLspBridgeDecodeSupportedVersions($cached) : null;
5050
}
5151

52+
/** @param list<string> $supportedVersions */
53+
function symfonyLspBridgeSupportsBranch(string $branch, array $supportedVersions): bool
54+
{
55+
if ([] === $supportedVersions) {
56+
return false;
57+
}
58+
59+
$oldest = $newest = $supportedVersions[0];
60+
foreach ($supportedVersions as $version) {
61+
if (version_compare($version, $oldest, '<')) {
62+
$oldest = $version;
63+
}
64+
if (version_compare($version, $newest, '>')) {
65+
$newest = $version;
66+
}
67+
}
68+
69+
return version_compare($branch, $oldest, '>=') && version_compare($branch, $newest, '<=');
70+
}
71+
5272
/** @return list<string>|null */
5373
function symfonyLspBridgeDecodeSupportedVersions(string $metadata): ?array
5474
{

tests/Runtime/BridgeTest.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public function testReportsProjectMetadataWithoutAStaticBranchList(string $versi
4242
self::assertFalse($result['project']['debug']);
4343
}
4444

45-
public function testReportsBranchesMissingFromReleaseMetadataWithoutBootingTheApplication(): void
45+
#[DataProvider('unsupportedBranchProvider')]
46+
public function testReportsBranchesOutsideTheReleaseMetadataRangeWithoutBootingTheApplication(string $version, string $branch): void
4647
{
47-
(new AutoloaderFixtureBuilder($this->workspace))->writeAutoloader('5.4.45');
48+
(new AutoloaderFixtureBuilder($this->workspace))->writeAutoloader($version);
4849
$metadata = $this->workspace->write('releases.json', json_encode([
4950
'supported_versions' => ['6.4', '7.4', '8.1'],
5051
], \JSON_THROW_ON_ERROR));
@@ -60,11 +61,28 @@ public function testReportsBranchesMissingFromReleaseMetadataWithoutBootingTheAp
6061
self::assertTrue($process->snapshot['unsupportedSymfonyVersion'] ?? false);
6162
$project = $process->snapshot['project'] ?? null;
6263
self::assertIsArray($project);
63-
self::assertSame('5.4', $project['symfonyBranch'] ?? null);
64+
self::assertSame($branch, $project['symfonyBranch'] ?? null);
6465
self::assertArrayNotHasKey('configurationValidation', $process->snapshot);
6566
self::assertSame((string) file_get_contents($metadata), (string) file_get_contents($cache));
6667
}
6768

69+
public function testAcceptsIntermediateBranchesWithinTheReleaseMetadataRange(): void
70+
{
71+
(new AutoloaderFixtureBuilder($this->workspace))->writeAutoloader('8.0.13');
72+
$metadata = $this->workspace->write('releases.json', json_encode([
73+
'supported_versions' => ['8.1', '6.4', '7.4'],
74+
], \JSON_THROW_ON_ERROR));
75+
76+
$process = $this->bridge->run([
77+
'--release-metadata-url='.$metadata,
78+
'--release-metadata-cache='.$this->workspace->path.'/release-metadata-cache.json',
79+
]);
80+
81+
self::assertSame(0, $process->exitCode, $process->stderr."\n".$process->stdout);
82+
self::assertIsArray($process->snapshot);
83+
self::assertArrayNotHasKey('unsupportedSymfonyVersion', $process->snapshot);
84+
}
85+
6886
public function testUsesStaleReleaseMetadataWhenRefreshFails(): void
6987
{
7088
(new AutoloaderFixtureBuilder($this->workspace))->writeAutoloader('5.4.45');
@@ -131,6 +149,13 @@ public static function versionProvider(): iterable
131149
yield 'prerelease' => ['42.7.0-RC1'];
132150
}
133151

152+
/** @return iterable<string, array{string, string}> */
153+
public static function unsupportedBranchProvider(): iterable
154+
{
155+
yield 'older' => ['5.4.45', '5.4'];
156+
yield 'newer' => ['8.2.0-BETA1', '8.2'];
157+
}
158+
134159
public function testKeepsStrayProjectOutputOffTheStdoutPayload(): void
135160
{
136161
(new AutoloaderFixtureBuilder($this->workspace))->writeStrayOutputApplication();

tests/Runtime/ProjectRuntimeInitializerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,16 @@ public function testReportsSymfonyBranchesRejectedByReleaseMetadata(): void
245245
$initializer->initialize($project);
246246
}
247247

248-
public function testAcceptsFutureSymfonyBranchesWithoutAStaticBranchList(): void
248+
public function testAcceptsIntermediateSymfonyBranchesWithoutAnUnsupportedMarker(): void
249249
{
250250
$source = $this->temporaryDirectory.'/source.php';
251251
file_put_contents($source, '<?php');
252252
$processRunner = new CapturingProcessRunner(new ProcessResult(0, json_encode([
253253
'schemaVersion' => 1,
254-
'project' => ['symfonyBranch' => '42.7'],
254+
'project' => ['symfonyBranch' => '8.0'],
255255
'sections' => [],
256256
], \JSON_THROW_ON_ERROR), ''));
257-
$project = new Project($this->temporaryDirectory, 'file://'.$this->temporaryDirectory, '^42.7');
257+
$project = new Project($this->temporaryDirectory, 'file://'.$this->temporaryDirectory, '^8.0');
258258
$initializer = (new ProjectRuntimeInitializerFixtureBuilder($source))->build(
259259
$processRunner,
260260
new RuntimeSnapshotLoaderRegistry([]),

0 commit comments

Comments
 (0)