1818use Php \Pie \Platform \ThreadSafetyMode ;
1919use PHPUnit \Framework \Attributes \CoversClass ;
2020use PHPUnit \Framework \Attributes \DataProvider ;
21+ use PHPUnit \Framework \Attributes \RequiresOperatingSystemFamily ;
2122use PHPUnit \Framework \TestCase ;
2223use Symfony \Component \Console \Output \OutputInterface ;
2324use Webmozart \Assert \Assert ;
2425
2526use function file_get_contents ;
2627use function file_put_contents ;
28+ use function is_link ;
2729use function mkdir ;
30+ use function realpath ;
31+ use function symlink ;
2832use function sys_get_temp_dir ;
33+ use function tempnam ;
2934use function uniqid ;
35+ use function unlink ;
3036
3137use const DIRECTORY_SEPARATOR ;
3238
@@ -42,7 +48,7 @@ public function setUp(): void
4248 {
4349 parent ::setUp ();
4450
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 );
4652 mkdir ($ this ->iniFilePath );
4753 Assert::positiveInteger (file_put_contents (
4854 $ this ->iniFilePath . DIRECTORY_SEPARATOR . 'with_commented_exts.ini ' ,
@@ -121,4 +127,66 @@ public function testRelevantIniFilesHaveExtensionRemoved(ExtensionType $extensio
121127 file_get_contents ($ this ->iniFilePath . DIRECTORY_SEPARATOR . 'with_active_exts.ini ' ),
122128 );
123129 }
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+ }
124192}
0 commit comments