14
14
15
15
namespace Humbug \PhpScoper \Configuration ;
16
16
17
+ use Humbug \PhpScoper \Patcher \FakePatcher ;
18
+ use Humbug \PhpScoper \Patcher \Patcher ;
17
19
use Humbug \PhpScoper \Patcher \PatcherChain ;
18
- use Humbug \PhpScoper \Whitelist ;
19
20
use InvalidArgumentException ;
20
21
use PHPUnit \Framework \TestCase ;
21
22
@@ -42,12 +43,34 @@ public function test_it_validates_the_prefix(
42
43
[],
43
44
new PatcherChain ([]),
44
45
SymbolsConfiguration::create (),
45
- [],
46
- [],
47
- [],
48
46
);
49
47
}
50
48
49
+ public function test_it_can_create_a_new_instance_with_a_different_prefix (): void
50
+ {
51
+ $ values = [
52
+ '/path/to/config ' ,
53
+ 'initialPrefix ' ,
54
+ ['/path/to/fileA ' => ['/path/to/fileA ' , 'fileAContent ' ]],
55
+ ['/path/to/fileB ' => ['/path/to/fileB ' , 'fileBContent ' ]],
56
+ new FakePatcher (),
57
+ SymbolsConfiguration::create (),
58
+ ];
59
+
60
+ $ config = new Configuration (...$ values );
61
+
62
+ // Sanity check
63
+ self ::assertStateIs ($ config , ...$ values );
64
+
65
+ $ newConfig = $ config ->withPrefix ('newPrefix ' );
66
+
67
+ $ expectedNewConfigValues = $ values ;
68
+ $ expectedNewConfigValues [1 ] = 'newPrefix ' ;
69
+
70
+ self ::assertStateIs ($ config , ...$ values );
71
+ self ::assertStateIs ($ newConfig , ...$ expectedNewConfigValues );
72
+ }
73
+
51
74
public static function prefixProvider (): iterable
52
75
{
53
76
yield [
@@ -60,4 +83,30 @@ public static function prefixProvider(): iterable
60
83
'Invalid namespace separator sequence. Got "App \\\\Foo" ' ,
61
84
];
62
85
}
86
+
87
+ private static function assertStateIs (
88
+ Configuration $ configuration ,
89
+ ?string $ expectedPath ,
90
+ string $ expectedPrefix ,
91
+ array $ expectedFilesWithContents ,
92
+ array $ expectedExcludedFilesWithContents ,
93
+ Patcher $ expectedPatcher ,
94
+ SymbolsConfiguration $ expectedSymbolsConfiguration
95
+ ): void {
96
+ self ::assertSame ($ expectedPath , $ configuration ->getPath ());
97
+ self ::assertSame ($ expectedPrefix , $ configuration ->getPrefix ());
98
+ self ::assertEqualsCanonicalizing (
99
+ $ expectedFilesWithContents ,
100
+ $ configuration ->getFilesWithContents (),
101
+ );
102
+ self ::assertEqualsCanonicalizing (
103
+ $ expectedExcludedFilesWithContents ,
104
+ $ configuration ->getExcludedFilesWithContents (),
105
+ );
106
+ self ::assertEquals ($ expectedPatcher , $ configuration ->getPatcher ());
107
+ self ::assertEquals (
108
+ $ expectedSymbolsConfiguration ,
109
+ $ configuration ->getSymbolsConfiguration (),
110
+ );
111
+ }
63
112
}
0 commit comments