diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index 8098b448..24215b50 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -109,6 +109,19 @@ public function getExcludedFilesWithContents(): array return $this->excludedFilesWithContents; } + public function withPatcher(Patcher $patcher): self + { + return new self( + $this->path, + $this->outputDir, + $this->prefix, + $this->filesWithContents, + $this->excludedFilesWithContents, + $patcher, + $this->symbolsConfiguration, + ); + } + public function getPatcher(): Patcher { return $this->patcher; diff --git a/tests/Configuration/ConfigurationTest.php b/tests/Configuration/ConfigurationTest.php index 79cf11b0..23a26cb9 100644 --- a/tests/Configuration/ConfigurationTest.php +++ b/tests/Configuration/ConfigurationTest.php @@ -76,6 +76,33 @@ public function test_it_can_create_a_new_instance_with_a_different_prefix(): voi self::assertStateIs($newConfig, ...$expectedNewConfigValues); } + public function test_it_can_create_a_new_instance_with_a_different_patcher(): void + { + $values = [ + '/path/to/config', + '/path/to/outputDir', + 'initialPrefix', + ['/path/to/fileA' => ['/path/to/fileA', 'fileAContent']], + ['/path/to/fileB' => ['/path/to/fileB', 'fileBContent']], + new FakePatcher(), + SymbolsConfiguration::create(), + ]; + + $config = new Configuration(...$values); + + // Sanity check + self::assertStateIs($config, ...$values); + + $newPatcher = new FakePatcher(); + $newConfig = $config->withPatcher($newPatcher); + + $expectedNewConfigValues = $values; + $expectedNewConfigValues[5] = $newPatcher; + + self::assertStateIs($config, ...$values); + self::assertStateIs($newConfig, ...$expectedNewConfigValues); + } + public static function prefixProvider(): iterable { yield [ diff --git a/vendor-hotfix/Configuration.php b/vendor-hotfix/Configuration.php index 370120db..4e69189c 100644 --- a/vendor-hotfix/Configuration.php +++ b/vendor-hotfix/Configuration.php @@ -2764,17 +2764,7 @@ private static function configurePhpScoperPrefix(PhpScoperConfiguration $phpScop return $phpScoperConfig; } - // TODO: provide easier way to change the prefix - // https://github.com/humbug/php-scoper/issues/616 - return new PhpScoperConfiguration( - $phpScoperConfig->getPath(), - $phpScoperConfig->getOutputDir(), - unique_id('_HumbugBox'), - $phpScoperConfig->getFilesWithContents(), - $phpScoperConfig->getExcludedFilesWithContents(), - $phpScoperConfig->getPatcher(), - $phpScoperConfig->getSymbolsConfiguration(), - ); + return $phpScoperConfig->withPrefix(unique_id('_HumbugBox')); } private static function checkIfDefaultValue( diff --git a/vendor-hotfix/SerializableScoper.php b/vendor-hotfix/SerializableScoper.php index 162b70f8..fda54e37 100644 --- a/vendor-hotfix/SerializableScoper.php +++ b/vendor-hotfix/SerializableScoper.php @@ -39,14 +39,8 @@ public function __construct( PhpScoperConfiguration $scoperConfig, string ...$excludedFilePaths, ) { - $this->scoperConfig = new PhpScoperConfiguration( - $scoperConfig->getPath(), - $scoperConfig->getOutputDir(), - $scoperConfig->getPrefix(), - $scoperConfig->getFilesWithContents(), - $scoperConfig->getExcludedFilesWithContents(), - PatcherFactory::createSerializablePatchers($scoperConfig->getPatcher()), - $scoperConfig->getSymbolsConfiguration(), + $this->scoperConfig = $scoperConfig->withPatcher( + PatcherFactory::createSerializablePatchers($scoperConfig->getPatcher()) ); $this->excludedFilePaths = $excludedFilePaths; $this->symbolsRegistry = new SymbolsRegistry();