File tree Expand file tree Collapse file tree 4 files changed +43
-19
lines changed Expand file tree Collapse file tree 4 files changed +43
-19
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,19 @@ public function getExcludedFilesWithContents(): array
109
109
return $ this ->excludedFilesWithContents ;
110
110
}
111
111
112
+ public function withPatcher (Patcher $ patcher ): self
113
+ {
114
+ return new self (
115
+ $ this ->path ,
116
+ $ this ->outputDir ,
117
+ $ this ->prefix ,
118
+ $ this ->filesWithContents ,
119
+ $ this ->excludedFilesWithContents ,
120
+ $ patcher ,
121
+ $ this ->symbolsConfiguration ,
122
+ );
123
+ }
124
+
112
125
public function getPatcher (): Patcher
113
126
{
114
127
return $ this ->patcher ;
Original file line number Diff line number Diff line change @@ -76,6 +76,33 @@ public function test_it_can_create_a_new_instance_with_a_different_prefix(): voi
76
76
self ::assertStateIs ($ newConfig , ...$ expectedNewConfigValues );
77
77
}
78
78
79
+ public function test_it_can_create_a_new_instance_with_a_different_patcher (): void
80
+ {
81
+ $ values = [
82
+ '/path/to/config ' ,
83
+ '/path/to/outputDir ' ,
84
+ 'initialPrefix ' ,
85
+ ['/path/to/fileA ' => ['/path/to/fileA ' , 'fileAContent ' ]],
86
+ ['/path/to/fileB ' => ['/path/to/fileB ' , 'fileBContent ' ]],
87
+ new FakePatcher (),
88
+ SymbolsConfiguration::create (),
89
+ ];
90
+
91
+ $ config = new Configuration (...$ values );
92
+
93
+ // Sanity check
94
+ self ::assertStateIs ($ config , ...$ values );
95
+
96
+ $ newPatcher = new FakePatcher ();
97
+ $ newConfig = $ config ->withPatcher ($ newPatcher );
98
+
99
+ $ expectedNewConfigValues = $ values ;
100
+ $ expectedNewConfigValues [5 ] = $ newPatcher ;
101
+
102
+ self ::assertStateIs ($ config , ...$ values );
103
+ self ::assertStateIs ($ newConfig , ...$ expectedNewConfigValues );
104
+ }
105
+
79
106
public static function prefixProvider (): iterable
80
107
{
81
108
yield [
Original file line number Diff line number Diff line change @@ -2764,17 +2764,7 @@ private static function configurePhpScoperPrefix(PhpScoperConfiguration $phpScop
2764
2764
return $ phpScoperConfig ;
2765
2765
}
2766
2766
2767
- // TODO: provide easier way to change the prefix
2768
- // https://github.com/humbug/php-scoper/issues/616
2769
- return new PhpScoperConfiguration (
2770
- $ phpScoperConfig ->getPath (),
2771
- $ phpScoperConfig ->getOutputDir (),
2772
- unique_id ('_HumbugBox ' ),
2773
- $ phpScoperConfig ->getFilesWithContents (),
2774
- $ phpScoperConfig ->getExcludedFilesWithContents (),
2775
- $ phpScoperConfig ->getPatcher (),
2776
- $ phpScoperConfig ->getSymbolsConfiguration (),
2777
- );
2767
+ return $ phpScoperConfig ->withPrefix (unique_id ('_HumbugBox ' ));
2778
2768
}
2779
2769
2780
2770
private static function checkIfDefaultValue (
Original file line number Diff line number Diff line change @@ -39,14 +39,8 @@ public function __construct(
39
39
PhpScoperConfiguration $ scoperConfig ,
40
40
string ...$ excludedFilePaths ,
41
41
) {
42
- $ this ->scoperConfig = new PhpScoperConfiguration (
43
- $ scoperConfig ->getPath (),
44
- $ scoperConfig ->getOutputDir (),
45
- $ scoperConfig ->getPrefix (),
46
- $ scoperConfig ->getFilesWithContents (),
47
- $ scoperConfig ->getExcludedFilesWithContents (),
48
- PatcherFactory::createSerializablePatchers ($ scoperConfig ->getPatcher ()),
49
- $ scoperConfig ->getSymbolsConfiguration (),
42
+ $ this ->scoperConfig = $ scoperConfig ->withPatcher (
43
+ PatcherFactory::createSerializablePatchers ($ scoperConfig ->getPatcher ())
50
44
);
51
45
$ this ->excludedFilePaths = $ excludedFilePaths ;
52
46
$ this ->symbolsRegistry = new SymbolsRegistry ();
You can’t perform that action at this time.
0 commit comments