Browse Source

DX: Test on PHP 8.2 (#6558)

Jeremiasz Major 2 years ago
parent
commit
058107c79f

+ 5 - 0
.github/workflows/ci.yml

@@ -46,6 +46,11 @@ jobs:
             job-description: 'with deployment'
             execute-deployment: 'yes'
 
+          - operating-system: 'ubuntu-20.04'
+            php-version: '8.2'
+            PHP_CS_FIXER_IGNORE_ENV: 1
+            composer-flags: '--ignore-platform-req=PHP'
+
           - operating-system: 'windows-latest'
             php-version: '8.1'
             job-description: 'on Windows'

+ 2 - 2
composer.json

@@ -43,8 +43,8 @@
         "phpspec/prophecy": "^1.15",
         "phpspec/prophecy-phpunit": "^2.0",
         "phpunit/phpunit": "^9.5",
-        "phpunitgoodpractices/polyfill": "^1.5",
-        "phpunitgoodpractices/traits": "^1.9.1",
+        "phpunitgoodpractices/polyfill": "^1.6",
+        "phpunitgoodpractices/traits": "^1.9.2",
         "symfony/phpunit-bridge": "^6.0",
         "symfony/yaml": "^5.4 || ^6.0"
     },

+ 3 - 3
src/Cache/Signature.php

@@ -43,7 +43,7 @@ final class Signature implements SignatureInterface
         $this->fixerVersion = $fixerVersion;
         $this->indent = $indent;
         $this->lineEnding = $lineEnding;
-        $this->rules = self::utf8Encode($rules);
+        $this->rules = self::makeJsonEncodable($rules);
     }
 
     public function getPhpVersion(): string
@@ -85,11 +85,11 @@ final class Signature implements SignatureInterface
      *
      * @return array<string, array<string, mixed>|bool>
      */
-    private static function utf8Encode(array $data): array
+    private static function makeJsonEncodable(array $data): array
     {
         array_walk_recursive($data, static function (&$item): void {
             if (\is_string($item) && !mb_detect_encoding($item, 'utf-8', true)) {
-                $item = utf8_encode($item);
+                $item = base64_encode($item);
             }
         });
 

+ 2 - 2
src/Fixer/Operator/BinaryOperatorSpacesFixer.php

@@ -807,12 +807,12 @@ $array = [
 
                 $rightmostSymbol = 0;
                 foreach ($group as $index) {
-                    $rightmostSymbol = max($rightmostSymbol, strpos(utf8_decode($lines[$index]), $placeholder));
+                    $rightmostSymbol = max($rightmostSymbol, mb_strpos($lines[$index], $placeholder));
                 }
 
                 foreach ($group as $index) {
                     $line = $lines[$index];
-                    $currentSymbol = strpos(utf8_decode($line), $placeholder);
+                    $currentSymbol = mb_strpos($line, $placeholder);
                     $delta = abs($rightmostSymbol - $currentSymbol);
 
                     if ($delta > 0) {

+ 5 - 2
tests/Console/ApplicationTest.php

@@ -26,8 +26,11 @@ final class ApplicationTest extends TestCase
 {
     public function testApplication(): void
     {
-        $app = new Application();
-        static::assertStringMatchesFormat("%s by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>.\nPHP runtime: <info>%d.%d.%d</info>", $app->getLongVersion());
+        $regex = '/^PHP CS Fixer <info>\\d+.\\d+.\\d+(-DEV)?<\\/info> <info>.+<\\/info>'
+            .' by <comment>Fabien Potencier<\\/comment> and <comment>Dariusz Ruminski<\\/comment>.'
+            ."\nPHP runtime: <info>\\d+.\\d+.\\d+(-dev)?<\\/info>$/";
+
+        static::assertMatchesRegularExpression($regex, (new Application())->getLongVersion());
     }
 
     public function testGetMajorVersion(): void

+ 5 - 0
tests/Fixtures/Test/FileReaderTest/StdinFakeStream.php

@@ -25,6 +25,11 @@ namespace PhpCsFixer\Tests\Fixtures\Test\FileReaderTest;
  */
 final class StdinFakeStream
 {
+    /**
+     * @var resource
+     */
+    public $context;
+
     private static bool $hasReadContent = false;
 
     private string $content = '<?php echo "foo";';

+ 6 - 3
tests/PregTest.php

@@ -46,20 +46,23 @@ final class PregTest extends TestCase
         static::assertSame($expectedMatches, $actualMatches);
     }
 
-    public function providePatternValidationCases(): array
+    public function providePatternValidationCases(): iterable
     {
-        return [
+        yield from [
             'invalid_blank' => ['', null, PregException::class],
             'invalid_open' => ["\1", null, PregException::class, "'\1' found"],
             'valid_control_character_delimiter' => ["\1\1", 1],
             'invalid_control_character_modifier' => ["\1\1\1", null, PregException::class, ' Unknown modifier '],
             'valid_slate' => ['//', 1],
             'valid_paired' => ['()', 1],
-            'null_byte_injection' => ['()'."\0", null, PregException::class, ' Null byte in regex '],
             'paired_non_utf8_only' => ["((*UTF8)\xFF)", null, PregException::class, 'UTF-8'],
             'valid_paired_non_utf8_only' => ["(\xFF)", 1],
             'php_version_dependent' => ['([\\R])', 0, PregException::class, 'Compilation failed: escape sequence is invalid '],
         ];
+
+        $nullByteMessage = \PHP_VERSION_ID >= 80200 ? 'NUL is not a valid modifier' : 'Null byte in regex';
+
+        yield 'null_byte_injection' => ['()'."\0", null, PregException::class, " {$nullByteMessage} "];
     }
 
     /**