From c1dd798b88b9db01e64d506d849b5a06100870a8 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 19 Nov 2024 16:40:25 +0100 Subject: [PATCH] Use `#[RequiresOperatingSystemFamily]` where possible --- .../Command/DownloadCommandTest.php | 18 +++++------------- .../integration/Command/InstallCommandTest.php | 6 ++---- .../Installing/WindowsInstallTest.php | 7 ++----- test/unit/Command/CommandHelperTest.php | 6 ++---- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/test/integration/Command/DownloadCommandTest.php b/test/integration/Command/DownloadCommandTest.php index 54c4cc8..2baf410 100644 --- a/test/integration/Command/DownloadCommandTest.php +++ b/test/integration/Command/DownloadCommandTest.php @@ -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; @@ -18,7 +20,6 @@ use function file_exists; use function is_executable; -use const PHP_VERSION; use const PHP_VERSION_ID; #[CoversClass(DownloadCommand::class)] @@ -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. @@ -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)) { @@ -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']); diff --git a/test/integration/Command/InstallCommandTest.php b/test/integration/Command/InstallCommandTest.php index e648887..c6ed049 100644 --- a/test/integration/Command/InstallCommandTest.php +++ b/test/integration/Command/InstallCommandTest.php @@ -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; @@ -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(); diff --git a/test/integration/Installing/WindowsInstallTest.php b/test/integration/Installing/WindowsInstallTest.php index 4a6cd9a..e29bedc 100644 --- a/test/integration/Installing/WindowsInstallTest.php +++ b/test/integration/Installing/WindowsInstallTest.php @@ -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; @@ -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; @@ -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), diff --git a/test/unit/Command/CommandHelperTest.php b/test/unit/Command/CommandHelperTest.php index bc6de3a..3842c04 100644 --- a/test/unit/Command/CommandHelperTest.php +++ b/test/unit/Command/CommandHelperTest.php @@ -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; @@ -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();