commandTester = new CommandTester(Container::testFactory()->get(InstallCommand::class)); } /** @return array */ public static function phpPathProvider(): array { // data providers cannot return empty, even if the test is skipped if (Platform::isWindows()) { return ['skip' => ['skip']]; } $possiblePhpConfigPaths = array_filter( [ '/usr/bin/php-config', '/usr/bin/php-config8.5', '/usr/bin/php-config8.4', '/usr/bin/php-config8.3', '/usr/bin/php-config8.2', '/usr/bin/php-config8.1', '/usr/bin/php-config8.0', '/usr/bin/php-config7.4', ], static fn (string $phpConfigPath) => file_exists($phpConfigPath) && is_executable($phpConfigPath), ); return array_combine( $possiblePhpConfigPaths, array_map(static fn (string $phpConfigPath) => [$phpConfigPath], $possiblePhpConfigPaths), ); } #[DataProvider('phpPathProvider')] public function testInstallCommandWillInstallCompatibleExtensionNonWindows(string $phpConfigPath): void { if (Platform::isWindows()) { self::markTestSkipped('This test can only run on non-Windows systems'); } $this->commandTester->execute( [ 'requested-package-and-version' => self::TEST_PACKAGE, '--with-php-config' => $phpConfigPath, '--skip-enable-extension' => true, ], ['verbosity' => BufferedOutput::VERBOSITY_VERY_VERBOSE], ); $this->commandTester->assertCommandIsSuccessful(); $outputString = $this->commandTester->getDisplay(); self::assertStringContainsString('Install complete: ', $outputString); self::assertStringContainsString('You must now add "extension=example_pie_extension" to your php.ini', $outputString); if ( ! preg_match('#^Install complete: (.*)$#m', $outputString, $matches) || ! array_key_exists(1, $matches) || $matches[1] === '' || ! file_exists($matches[1]) || ! is_file($matches[1]) ) { return; } $fileToRemove = $matches[1]; assert(is_string($fileToRemove)); $rmCommand = ['rm', $fileToRemove]; if (! is_writable($fileToRemove)) { array_unshift($rmCommand, 'sudo'); } (new Process($rmCommand))->mustRun(); } #[RequiresOperatingSystemFamily('Windows')] public function testInstallCommandWillInstallCompatibleExtensionWindows(): void { $this->commandTester->execute([ 'requested-package-and-version' => self::TEST_PACKAGE, '--skip-enable-extension' => true, ]); $this->commandTester->assertCommandIsSuccessful(); $outputString = $this->commandTester->getDisplay(); self::assertStringContainsString('Copied DLL to: ', $outputString); self::assertStringContainsString('You must now add "extension=example_pie_extension" to your php.ini', $outputString); if ( ! preg_match('#^Copied DLL to: (.*)$#m', $outputString, $matches) || ! array_key_exists(1, $matches) || $matches[1] === '' || ! file_exists($matches[1]) || ! is_file($matches[1]) ) { return; } (new Process(['rm', $matches[1]]))->mustRun(); } }