Skip to content

Commit 7d26742

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: [FrameworkBundle] Add config/reference.php as ResourceFile [FrameworkBundle] Skip non-bundle classes in PhpConfigReferenceDumpPass
2 parents d75017e + 70dbd30 commit 7d26742

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

DependencyInjection/Compiler/PhpConfigReferenceDumpPass.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
use Symfony\Component\Config\Definition\ArrayShapeGenerator;
1515
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
use Symfony\Component\Config\Resource\FileResource;
1617
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
1920
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2021
use Symfony\Component\DependencyInjection\Loader\Configurator\AppReference;
22+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
2123
use Symfony\Component\Routing\Loader\Configurator\RoutesReference;
2224

2325
/**
@@ -94,6 +96,9 @@ public function process(ContainerBuilder $container): void
9496

9597
$anyEnvExtensions = [];
9698
foreach ($this->bundlesDefinition as $bundle => $envs) {
99+
if (!is_subclass_of($bundle, BundleInterface::class)) {
100+
continue;
101+
}
97102
if (!$extension = (new $bundle())->getContainerExtension()) {
98103
continue;
99104
}
@@ -156,8 +161,11 @@ public function process(ContainerBuilder $container): void
156161
]);
157162

158163
$dir = \dirname($this->referenceFile);
159-
if (is_dir($dir) && is_writable($dir) && (!is_file($this->referenceFile) || file_get_contents($this->referenceFile) !== $configReference)) {
160-
file_put_contents($this->referenceFile, $configReference);
164+
if (is_dir($dir) && is_writable($dir)) {
165+
if (!is_file($this->referenceFile) || file_get_contents($this->referenceFile) !== $configReference) {
166+
file_put_contents($this->referenceFile, $configReference);
167+
}
168+
$container->addResource(new FileResource($this->referenceFile));
161169
}
162170
}
163171

Tests/DependencyInjection/Compiler/PhpConfigReferenceDumpPassTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\Attributes\TestWith;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PhpConfigReferenceDumpPass;
1617
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1718
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1819
use Symfony\Component\Config\Definition\ConfigurationInterface;
20+
use Symfony\Component\Config\Resource\FileResource;
1921
use Symfony\Component\DependencyInjection\ContainerBuilder;
2022
use Symfony\Component\DependencyInjection\Extension\Extension;
2123
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
@@ -57,6 +59,7 @@ public function testProcessWithConfigDir()
5759
$this->assertStringContainsString('namespace Symfony\Component\DependencyInjection\Loader\Configurator;', $content);
5860
$this->assertStringContainsString('final class App extends AppReference', $content);
5961
$this->assertStringContainsString('public static function config(array $config): array', $content);
62+
$this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
6063
}
6164

6265
public function testProcessIgnoresFileWriteErrors()
@@ -78,6 +81,7 @@ public function testProcessIgnoresFileWriteErrors()
7881

7982
$pass->process($container);
8083
$this->assertFileDoesNotExist($readOnlyDir.'/reference.php');
84+
$this->assertEmpty($container->getResources());
8185
}
8286

8387
public function testProcessGeneratesExpectedReferenceFile()
@@ -99,6 +103,23 @@ public function testProcessGeneratesExpectedReferenceFile()
99103
}
100104

101105
$this->assertFileEquals(__DIR__.'/../../Fixtures/reference.php', $this->tempDir.'/reference.php');
106+
$this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
107+
}
108+
109+
#[TestWith([self::class])]
110+
#[TestWith(['Symfony\\NotARealClass'])]
111+
public function testProcessWithInvalidBundleClass(string $invalidClass)
112+
{
113+
$container = new ContainerBuilder();
114+
$container->setParameter('.container.known_envs', ['test', 'dev']);
115+
116+
$pass = new PhpConfigReferenceDumpPass($this->tempDir.'/reference.php', [
117+
$invalidClass => ['dev' => true],
118+
]);
119+
$pass->process($container);
120+
121+
$referenceFile = $this->tempDir.'/reference.php';
122+
$this->assertFileExists($referenceFile);
102123
}
103124
}
104125

0 commit comments

Comments
 (0)