Skip to content

Commit 70dbd30

Browse files
committed
[FrameworkBundle] Add config/reference.php as ResourceFile
1 parent d968f40 commit 70dbd30

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

DependencyInjection/Compiler/PhpConfigReferenceDumpPass.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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;
@@ -160,8 +161,11 @@ public function process(ContainerBuilder $container): void
160161
]);
161162

162163
$dir = \dirname($this->referenceFile);
163-
if (is_dir($dir) && is_writable($dir) && (!is_file($this->referenceFile) || file_get_contents($this->referenceFile) !== $configReference)) {
164-
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));
165169
}
166170
}
167171

Tests/DependencyInjection/Compiler/PhpConfigReferenceDumpPassTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1818
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1919
use Symfony\Component\Config\Definition\ConfigurationInterface;
20+
use Symfony\Component\Config\Resource\FileResource;
2021
use Symfony\Component\DependencyInjection\ContainerBuilder;
2122
use Symfony\Component\DependencyInjection\Extension\Extension;
2223
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
@@ -58,6 +59,7 @@ public function testProcessWithConfigDir()
5859
$this->assertStringContainsString('namespace Symfony\Component\DependencyInjection\Loader\Configurator;', $content);
5960
$this->assertStringContainsString('final class App extends AppReference', $content);
6061
$this->assertStringContainsString('public static function config(array $config): array', $content);
62+
$this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
6163
}
6264

6365
public function testProcessIgnoresFileWriteErrors()
@@ -79,6 +81,7 @@ public function testProcessIgnoresFileWriteErrors()
7981

8082
$pass->process($container);
8183
$this->assertFileDoesNotExist($readOnlyDir.'/reference.php');
84+
$this->assertEmpty($container->getResources());
8285
}
8386

8487
public function testProcessGeneratesExpectedReferenceFile()
@@ -100,6 +103,7 @@ public function testProcessGeneratesExpectedReferenceFile()
100103
}
101104

102105
$this->assertFileEquals(__DIR__.'/../../Fixtures/reference.php', $this->tempDir.'/reference.php');
106+
$this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
103107
}
104108

105109
#[TestWith([self::class])]

0 commit comments

Comments
 (0)