Просмотр исходного кода

DX: Allow OS conditions for integration tests (#7161)

Greg Korba 1 год назад
Родитель
Сommit
a02fc0462f

+ 4 - 0
tests/Fixtures/Integration/misc/meta_insert_64566_tokens.test

@@ -1,6 +1,10 @@
 --TEST--
 Test of super huge file that would require 64566 tokens to be inserted! Basically, this tests Tokens::insertSlices, without which this test would take few hours to execute.
+
+Test is disabled for MacOS because it regularly fails with timeout (see: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7141)
 --RULESET--
 {
     "whitespace_after_comma_in_array": true
 }
+--REQUIREMENTS--
+{"os":["Linux","Windows"]}

+ 9 - 1
tests/Test/AbstractIntegrationCaseFactory.php

@@ -105,12 +105,13 @@ abstract class AbstractIntegrationCaseFactory implements IntegrationCaseFactoryI
     /**
      * Parses the '--REQUIREMENTS--' block of a '.test' file and determines requirements.
      *
-     * @return array<string, int>|array{php: int}
+     * @return array{php: int, "php<"?: int, os: list<string>}
      */
     protected function determineRequirements(SplFileInfo $file, ?string $config): array
     {
         $parsed = $this->parseJson($config, [
             'php' => \PHP_VERSION_ID,
+            'os' => ['Linux', 'Darwin', 'Windows'],
         ]);
 
         if (!\is_int($parsed['php'])) {
@@ -120,6 +121,13 @@ abstract class AbstractIntegrationCaseFactory implements IntegrationCaseFactoryI
             ));
         }
 
+        if (!\is_array($parsed['os'])) {
+            throw new \InvalidArgumentException(sprintf(
+                'Expected array of OS names for "os", got "%s".',
+                get_debug_type($parsed['os']).' ('.$parsed['os'].')',
+            ));
+        }
+
         return $parsed;
     }
 

+ 11 - 0
tests/Test/AbstractIntegrationTestCase.php

@@ -195,6 +195,17 @@ abstract class AbstractIntegrationTestCase extends TestCase
             self::markTestSkipped(sprintf('PHP %d (or later) is required for "%s", current "%d".', $case->getRequirement('php'), $case->getFileName(), \PHP_VERSION_ID));
         }
 
+        if (!\in_array(PHP_OS, $case->getRequirement('os'), true)) {
+            self::markTestSkipped(
+                sprintf(
+                    'Unsupported OS (%s) for "%s", allowed are: %s.',
+                    PHP_OS,
+                    $case->getFileName(),
+                    implode(', ', $case->getRequirement('os'))
+                )
+            );
+        }
+
         $input = $case->getInputCode();
         $expected = $case->getExpectedCode();
 

+ 7 - 6
tests/Test/IntegrationCase.php

@@ -35,9 +35,7 @@ final class IntegrationCase
     private ?string $inputCode;
 
     /**
-     * Env requirements (possible keys: 'php' or 'php<').
-     *
-     * @var array<string, int>|array{php: int}
+     * @var array{php: int, "php<"?: int, os: list<string>}
      */
     private array $requirements;
 
@@ -54,7 +52,7 @@ final class IntegrationCase
 
     /**
      * @param array{checkPriority: bool, deprecations: list<string>, isExplicitPriorityCheck?: bool} $settings
-     * @param array<string, int>|array{php: int}                                                     $requirements
+     * @param array{php: int, "php<"?: int, os: list<string>}                                        $requirements
      * @param array{indent: string, lineEnding: string}                                              $config
      */
     public function __construct(
@@ -105,7 +103,10 @@ final class IntegrationCase
         return $this->inputCode;
     }
 
-    public function getRequirement(string $name): int
+    /**
+     * @return mixed
+     */
+    public function getRequirement(string $name)
     {
         if (!\array_key_exists($name, $this->requirements)) {
             throw new \InvalidArgumentException(sprintf(
@@ -119,7 +120,7 @@ final class IntegrationCase
     }
 
     /**
-     * @return array<string, int>|array{php: int}
+     * @return array{php: int, "php<"?: int, os: list<string>}
      */
     public function getRequirements(): array
     {