Skip to content

Commit

Permalink
Disable uninstall command for Windows
Browse files Browse the repository at this point in the history
See php#190 for details.
  • Loading branch information
asgrim committed Feb 27, 2025
1 parent 927d822 commit 935947b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
4 changes: 3 additions & 1 deletion features/uninstall-extensions.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Feature: Extensions can be uninstalled with PIE

Example: The latest version of an extension can be downloaded
# See https://github.com/php/pie/issues/190 for why this is non-Windows
@non-windows
Example: An extension can be uninstalled
Given an extension was previously installed
When I run a command to uninstall an extension
Then the extension should not be installed anymore
11 changes: 11 additions & 0 deletions src/Command/UninstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Php\Pie\Command;

use Composer\Composer;
use Composer\Util\Platform;
use Php\Pie\ComposerIntegration\ComposerIntegrationHandler;
use Php\Pie\ComposerIntegration\PieComposerFactory;
use Php\Pie\ComposerIntegration\PieComposerRequest;
Expand Down Expand Up @@ -52,6 +53,16 @@ public function configure(): void

public function execute(InputInterface $input, OutputInterface $output): int
{
if (Platform::isWindows()) {
/**
* @todo add support for uninstalling in Windows - see
* {@link https://github.com/php/pie/issues/190} for details
*/
$output->writeln('<warning>Uninstalling extensions on Windows is not currently supported.</warning>');

return 1;
}

$packageToRemove = (string) $input->getArgument(self::ARG_PACKAGE_NAME);
Assert::stringNotEmpty($packageToRemove);
$requestedPackageAndVersionToRemove = new RequestedPackageAndVersion($packageToRemove, null);
Expand Down
21 changes: 21 additions & 0 deletions src/Installing/FailedToRemoveExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Php\Pie\Installing;

use Php\Pie\BinaryFile;
use RuntimeException;

use function sprintf;

class FailedToRemoveExtension extends RuntimeException
{
public static function withFilename(BinaryFile $extension): self
{
return new self(sprintf(
'Failed to remove extension file: %s',
$extension->filePath,
));
}
}
5 changes: 3 additions & 2 deletions src/Installing/UninstallUsingUnlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public function __invoke(Package $package): BinaryFile

$expectedBinaryFile->verify();

unlink($expectedBinaryFile->filePath);
if (! unlink($expectedBinaryFile->filePath)) {
throw FailedToRemoveExtension::withFilename($expectedBinaryFile);
}

// @todo verify the unlink worked etc, maybe permissions failed
return $expectedBinaryFile;
}
}
10 changes: 7 additions & 3 deletions test/behaviour/CliContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ public function theExtensionShouldNotBeInstalled(): void
{
$this->assertCommandSuccessful();

Assert::regex($this->output, '#👋 Removed extension: [-_a-zA-Z0-9/]+/example_pie_extension.so#');
if (Platform::isWindows()) {
Assert::regex($this->output, '#👋 Removed extension: [-\\\_:.a-zA-Z0-9]+\\\php_example_pie_extension.dll#');
} else {
Assert::regex($this->output, '#👋 Removed extension: [-_a-zA-Z0-9/]+/example_pie_extension.so#');
}

$isExtEnabled = (new Process([self::PHP_BINARY, '-r', 'echo extension_loaded("example_pie_extension")?"yes":"no";']))
->mustRun()
->getOutput();

Assert::same('no', $isExtEnabled);
Assert::same($isExtEnabled, 'no');
}

#[Then('the extension should have been installed')]
Expand All @@ -159,7 +163,7 @@ public function theExtensionShouldHaveBeenInstalled(): void
->mustRun()
->getOutput();

Assert::same('yes', $isExtEnabled);
Assert::same($isExtEnabled, 'yes');
}

#[Given('I have an invalid extension installed')]
Expand Down

0 comments on commit 935947b

Please sign in to comment.