Skip to content

Commit

Permalink
Use #[RequiresOperatingSystemFamily] where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Nov 19, 2024
1 parent e4b1fd1 commit c1dd798
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
18 changes: 5 additions & 13 deletions test/integration/Command/DownloadCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Php\Pie\DependencyResolver\UnableToResolveRequirement;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -18,7 +20,6 @@
use function file_exists;
use function is_executable;

use const PHP_VERSION;
use const PHP_VERSION_ID;

#[CoversClass(DownloadCommand::class)]
Expand Down Expand Up @@ -96,13 +97,10 @@ public function testDownloadCommandWillDownloadSpecificCommits(): void
);
}

#[RequiresOperatingSystemFamily('Windows')]
#[DataProvider('validVersionsList')]
public function testDownloadingWithPhpConfig(string $requestedVersion, string $expectedVersion): void
{
if (! Platform::isWindows()) {
self::markTestSkipped('This test can only run on Windows');
}

// @todo This test makes an assumption you're using `ppa:ondrej/php` to have multiple PHP versions. This allows
// us to test scenarios where you run with PHP 8.1 but want to install to a PHP 8.3 instance, for example.
// However, this test isn't very portable, and won't run in CI, so we could do with improving this later.
Expand All @@ -124,13 +122,10 @@ public function testDownloadingWithPhpConfig(string $requestedVersion, string $e
self::assertStringContainsString('Extracted ' . $expectedVersion . ' source to', $outputString);
}

#[RequiresOperatingSystemFamily('Windows')]
#[DataProvider('validVersionsList')]
public function testDownloadingWithPhpPath(string $requestedVersion, string $expectedVersion): void
{
if (! Platform::isWindows()) {
self::markTestSkipped('This test can only run on Windows');
}

$phpBinaryPath = 'C:\php-8.3.6\php.exe';

if (! file_exists($phpBinaryPath) || ! is_executable($phpBinaryPath)) {
Expand All @@ -149,12 +144,9 @@ public function testDownloadingWithPhpPath(string $requestedVersion, string $exp
self::assertStringContainsString('Extracted ' . $expectedVersion . ' source to', $outputString);
}

#[RequiresPhp('<8.2')]
public function testDownloadCommandFailsWhenUsingIncompatiblePhpVersion(): void
{
if (PHP_VERSION_ID >= 80200) {
self::markTestSkipped('This test can only run on older than PHP 8.2 - you are running ' . PHP_VERSION);
}

$this->expectException(UnableToResolveRequirement::class);
// 1.0.0 is only compatible with PHP 8.3.0
$this->commandTester->execute(['requested-package-and-version' => self::TEST_PACKAGE . ':1.0.0']);
Expand Down
6 changes: 2 additions & 4 deletions test/integration/Command/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Php\Pie\Container;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Tester\CommandTester;
Expand Down Expand Up @@ -108,12 +109,9 @@ public function testInstallCommandWillInstallCompatibleExtensionNonWindows(strin
(new Process($rmCommand))->mustRun();
}

#[RequiresOperatingSystemFamily('Windows')]
public function testInstallCommandWillInstallCompatibleExtensionWindows(): void
{
if (! Platform::isWindows()) {
self::markTestSkipped('This test can only run on Windows systems');
}

$this->commandTester->execute(['requested-package-and-version' => self::TEST_PACKAGE]);

$this->commandTester->assertCommandIsSuccessful();
Expand Down
7 changes: 2 additions & 5 deletions test/integration/Installing/WindowsInstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Php\PieIntegrationTest\Installing;

use Composer\Package\CompletePackage;
use Composer\Util\Platform;
use Php\Pie\DependencyResolver\Package;
use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\ExtensionName;
Expand All @@ -18,6 +17,7 @@
use Php\Pie\Platform\ThreadSafetyMode;
use Php\Pie\Platform\WindowsCompiler;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
use PHPUnit\Framework\TestCase;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
Expand All @@ -39,12 +39,9 @@ final class WindowsInstallTest extends TestCase
{
private const TEST_EXTENSION_PATH = __DIR__ . '/../../assets/pie_test_ext_win';

#[RequiresOperatingSystemFamily('Windows')]
public function testWindowsInstallCanInstallExtension(): void
{
if (! Platform::isWindows()) {
self::markTestSkipped('Test can only be run on Windows');
}

$downloadedPackage = DownloadedPackage::fromPackageAndExtractedPath(
new Package(
$this->createMock(CompletePackage::class),
Expand Down
6 changes: 2 additions & 4 deletions test/unit/Command/CommandHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Php\Pie\ExtensionType;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -126,12 +127,9 @@ public function testProcessingConfigureOptionsFromInput(): void
);
}

#[RequiresOperatingSystemFamily('Windows')]
public function testWindowsMachinesCannotUseWithPhpConfigOption(): void
{
if (! Platform::isWindows()) {
self::markTestSkipped('This test can only run on Windows');
}

$command = new Command();
$input = new ArrayInput(['--with-php-config' => 'C:\path\to\php-config']);
$output = new NullOutput();
Expand Down

0 comments on commit c1dd798

Please sign in to comment.