Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/DependencyInjection/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 63 additions & 0 deletions tests/PHPStan/DependencyInjection/ConfiguratorContainerKeyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php declare(strict_types = 1);

namespace PHPStan\DependencyInjection;

use Nette\Utils\FileSystem;
use Override;
use PHPStan\File\FileHelper;
use PHPUnit\Framework\TestCase;
use function sys_get_temp_dir;
use function uniqid;

final class ConfiguratorContainerKeyTest extends TestCase
{

private string $tempDirectory;

#[Override]
protected function setUp(): void
{
$this->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<string, string> $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();
}

}
Loading