18
18
use Php \Pie \Platform \ThreadSafetyMode ;
19
19
use PHPUnit \Framework \Attributes \CoversClass ;
20
20
use PHPUnit \Framework \Attributes \DataProvider ;
21
+ use PHPUnit \Framework \Attributes \RequiresOperatingSystemFamily ;
21
22
use PHPUnit \Framework \TestCase ;
22
23
use Symfony \Component \Console \Output \OutputInterface ;
23
24
use Webmozart \Assert \Assert ;
24
25
25
26
use function file_get_contents ;
26
27
use function file_put_contents ;
28
+ use function is_link ;
27
29
use function mkdir ;
30
+ use function realpath ;
31
+ use function symlink ;
28
32
use function sys_get_temp_dir ;
33
+ use function tempnam ;
29
34
use function uniqid ;
35
+ use function unlink ;
30
36
31
37
use const DIRECTORY_SEPARATOR ;
32
38
@@ -42,7 +48,7 @@ public function setUp(): void
42
48
{
43
49
parent ::setUp ();
44
50
45
- $ this ->iniFilePath = sys_get_temp_dir () . DIRECTORY_SEPARATOR . uniqid ('pie_remove_ini_test ' , true );
51
+ $ this ->iniFilePath = realpath ( sys_get_temp_dir () ) . DIRECTORY_SEPARATOR . uniqid ('pie_remove_ini_test ' , true );
46
52
mkdir ($ this ->iniFilePath );
47
53
Assert::positiveInteger (file_put_contents (
48
54
$ this ->iniFilePath . DIRECTORY_SEPARATOR . 'with_commented_exts.ini ' ,
@@ -121,4 +127,66 @@ public function testRelevantIniFilesHaveExtensionRemoved(ExtensionType $extensio
121
127
file_get_contents ($ this ->iniFilePath . DIRECTORY_SEPARATOR . 'with_active_exts.ini ' ),
122
128
);
123
129
}
130
+
131
+ #[RequiresOperatingSystemFamily('Linux ' )]
132
+ public function testSymlinkedIniFilesAreResolved (): void
133
+ {
134
+ $ realIni = $ this ->iniFilePath . DIRECTORY_SEPARATOR . 'with_active_exts.ini ' ;
135
+ $ symlinkedIni = tempnam (sys_get_temp_dir (), 'pie_ini_removal_test_link_ ' );
136
+ unlink ($ symlinkedIni );
137
+ symlink ($ realIni , $ symlinkedIni );
138
+ self ::assertTrue (is_link ($ symlinkedIni ));
139
+
140
+ $ phpBinaryPath = $ this ->createMock (PhpBinaryPath::class);
141
+ $ phpBinaryPath
142
+ ->method ('loadedIniConfigurationFile ' )
143
+ ->willReturn ($ symlinkedIni );
144
+ $ phpBinaryPath
145
+ ->method ('additionalIniDirectory ' )
146
+ ->willReturn (null );
147
+
148
+ $ package = new Package (
149
+ $ this ->createMock (CompletePackageInterface::class),
150
+ ExtensionType::PhpModule,
151
+ ExtensionName::normaliseFromString ('foobar ' ),
152
+ 'foobar/foobar ' ,
153
+ '1.2.3 ' ,
154
+ null ,
155
+ );
156
+
157
+ $ targetPlatform = new TargetPlatform (
158
+ OperatingSystem::NonWindows,
159
+ OperatingSystemFamily::Linux,
160
+ $ phpBinaryPath ,
161
+ Architecture::x86_64,
162
+ ThreadSafetyMode::ThreadSafe,
163
+ 1 ,
164
+ null ,
165
+ );
166
+
167
+ $ affectedFiles = (new RemoveIniEntryWithFileGetContents ())(
168
+ $ package ,
169
+ $ targetPlatform ,
170
+ $ this ->createMock (OutputInterface::class),
171
+ );
172
+
173
+ self ::assertSame (
174
+ [$ realIni ],
175
+ $ affectedFiles ,
176
+ );
177
+
178
+ self ::assertTrue (is_link ($ symlinkedIni ));
179
+
180
+ $ expectedIniContent = "; extension=foobar ; removed by PIE \nzend_extension=foobar \n" ;
181
+ self ::assertSame (
182
+ $ expectedIniContent ,
183
+ file_get_contents ($ realIni ),
184
+ );
185
+ self ::assertSame (
186
+ $ expectedIniContent ,
187
+ file_get_contents ($ symlinkedIni ),
188
+ );
189
+
190
+ unlink ($ symlinkedIni );
191
+ }
124
192
}
0 commit comments