diff --git a/src/DependencyInjection/Configurator.php b/src/DependencyInjection/Configurator.php index 5341f38ed25..48c93194d60 100644 --- a/src/DependencyInjection/Configurator.php +++ b/src/DependencyInjection/Configurator.php @@ -94,6 +94,9 @@ public function loadContainer(): string unset($staticParameters['env']['SHELL_VERBOSITY']); // make sure invocations via blackfire use the same container unset($staticParameters['env']['BLACKFIRE_AGENT_SOCKET']); + // the restart points these at a temporary ini with a random name (RestartManager) + unset($staticParameters['env']['PHPRC']); + unset($staticParameters['env']['PHP_INI_SCAN_DIR']); $containerKey = [ $staticParameters, diff --git a/tests/PHPStan/DependencyInjection/ConfiguratorContainerKeyTest.php b/tests/PHPStan/DependencyInjection/ConfiguratorContainerKeyTest.php new file mode 100644 index 00000000000..7cc09d386d8 --- /dev/null +++ b/tests/PHPStan/DependencyInjection/ConfiguratorContainerKeyTest.php @@ -0,0 +1,63 @@ +tempDirectory = sys_get_temp_dir() . '/' . uniqid('phpstan-configurator-key-', true); + } + + #[Override] + protected function tearDown(): void + { + FileSystem::delete($this->tempDirectory); + } + + public function testTheRestartIniDoesNotChangeTheContainer(): void + { + $first = $this->loadContainer([ + 'PHPRC' => '/tmp/phpstan-restart-ini-first', + 'PHP_INI_SCAN_DIR' => '', + ]); + $second = $this->loadContainer([ + 'PHPRC' => '/tmp/phpstan-restart-ini-second', + ]); + + $this->assertSame($first, $second); + } + + public function testOtherEnvironmentVariablesStillChangeTheContainer(): void + { + $first = $this->loadContainer(['FOO' => 'first']); + $second = $this->loadContainer(['FOO' => 'second']); + + $this->assertNotSame($first, $second); + } + + /** + * @param array $env + */ + private function loadContainer(array $env): string + { + $configurator = new Configurator(new LoaderFactory(new FileHelper(__DIR__), __DIR__, __DIR__, null, []), false); + $configurator->setDebugMode(true); + $configurator->setTempDirectory($this->tempDirectory); + $configurator->addStaticParameters(['env' => $env]); + + return $configurator->loadContainer(); + } + +}