1616use Php \Pie \Util \Process ;
1717use PHPUnit \Framework \Attributes \CoversClass ;
1818use PHPUnit \Framework \Attributes \DataProvider ;
19+ use PHPUnit \Framework \Attributes \RequiresOperatingSystemFamily ;
1920use PHPUnit \Framework \TestCase ;
21+ use ReflectionMethod ;
2022use Symfony \Component \Console \Output \OutputInterface ;
2123use Symfony \Component \Process \PhpExecutableFinder ;
2224
3537use function ini_get ;
3638use function is_dir ;
3739use function is_executable ;
40+ use function mkdir ;
3841use function php_uname ;
3942use function phpversion ;
4043use function sprintf ;
4144use function strtolower ;
4245use function sys_get_temp_dir ;
46+ use function trim ;
4347use function uniqid ;
4448
4549use const DIRECTORY_SEPARATOR ;
@@ -235,11 +239,28 @@ public function testPhpIntSize(): void
235239 );
236240 }
237241
238- public function testExtensionPath (): void
242+ #[RequiresOperatingSystemFamily('Linux ' )]
243+ public function testExtensionPathOnLinuxThatAlreadyExists (): void
239244 {
240245 $ phpBinary = PhpBinaryPath::fromCurrentProcess ();
241246
242- $ expectedExtensionDir = ini_get ('extension_dir ' );
247+ $ expectedExtensionDir = (string ) ini_get ('extension_dir ' );
248+ self ::assertNotEmpty ($ expectedExtensionDir );
249+ self ::assertDirectoryExists ($ expectedExtensionDir );
250+
251+ self ::assertSame (
252+ $ expectedExtensionDir ,
253+ $ phpBinary ->extensionPath (),
254+ );
255+ }
256+
257+ #[RequiresOperatingSystemFamily('Windows ' )]
258+ public function testExtensionPathOnWindows (): void
259+ {
260+ $ phpBinary = PhpBinaryPath::fromCurrentProcess ();
261+
262+ $ expectedExtensionDir = (string ) ini_get ('extension_dir ' );
263+ self ::assertNotEmpty ($ expectedExtensionDir );
243264
244265 // `extension_dir` may be a relative URL on Windows (e.g. "ext"), so resolve it according to the location of PHP
245266 if (! file_exists ($ expectedExtensionDir ) || ! is_dir ($ expectedExtensionDir )) {
@@ -255,9 +276,32 @@ public function testExtensionPath(): void
255276 );
256277 }
257278
279+ #[RequiresOperatingSystemFamily('Windows ' )]
280+ public function testRelativeExtensionPathOnWindowsIsFilled (): void
281+ {
282+ $ phpBinary = $ this ->createPartialMock (PhpBinaryPath::class, ['phpinfo ' ]);
283+ (new ReflectionMethod ($ phpBinary , '__construct ' ))
284+ ->invoke ($ phpBinary , trim ((string ) (new PhpExecutableFinder ())->find ()), null );
285+
286+ $ configuredExtensionPath = 'foo ' ;
287+ self ::assertDirectoryDoesNotExist ($ configuredExtensionPath , 'test cannot run if the same-named extension dir already exists in cwd ' );
288+
289+ $ fullExtensionPath = dirname ($ phpBinary ->phpBinaryPath ) . DIRECTORY_SEPARATOR . $ configuredExtensionPath ;
290+ mkdir ($ fullExtensionPath , 0777 , true );
291+ self ::assertDirectoryExists ($ fullExtensionPath );
292+
293+ $ phpBinary ->expects (self ::once ())
294+ ->method ('phpinfo ' )
295+ ->willReturn (sprintf ('extension_dir => %s => %s ' , $ configuredExtensionPath , $ configuredExtensionPath ));
296+
297+ self ::assertSame ($ fullExtensionPath , $ phpBinary ->extensionPath ());
298+ }
299+
258300 public function testExtensionPathIsImplicitlyCreated (): void
259301 {
260302 $ phpBinary = $ this ->createPartialMock (PhpBinaryPath::class, ['phpinfo ' ]);
303+ (new ReflectionMethod ($ phpBinary , '__construct ' ))
304+ ->invoke ($ phpBinary , trim ((string ) (new PhpExecutableFinder ())->find ()), null );
261305
262306 $ configuredExtensionPath = sys_get_temp_dir () . DIRECTORY_SEPARATOR . uniqid ('PIE_non_existent_extension_path ' , true );
263307 self ::assertDirectoryDoesNotExist ($ configuredExtensionPath );
0 commit comments