diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e8b7c19..513fd35 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,8 +13,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: ['7.4', '8.0', '8.1', '8.2'] - + php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] steps: - name: Checkout uses: actions/checkout@v5 @@ -33,15 +32,9 @@ jobs: restore-keys: ${{ runner.os }}-composer- - name: Install dependencies run: composer update $DEFAULT_COMPOSER_FLAGS - - name: Run unit tests with coverage - run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover --colors=always - if: matrix.php == '7.1' - - name: Run unit tests without coverage - run: vendor/bin/phpunit --verbose --colors=always - if: matrix.php != '7.1' - - name: Upload code coverage - run: | - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover coverage.clover - if: matrix.php == '7.1' - continue-on-error: true # if is fork + - name: Run unit tests PHP 7.x. + run: vendor/bin/phpunit -c phpunit-7x.xml.dist + if: matrix.php == '7.4' + - name: Run unit tests PHP 8.x. + run: vendor/bin/phpunit + if: matrix.php != '7.4' diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ddaf4a..141c60e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Yii Framework 2 apidoc extension Change Log - Bug #313: Fix deprecation error `Method deprecated, use ::getParameters()` (mspirkov) - Bug #317: Fix `trim` deprecation errors `Passing null to parameter #1 ($string) of type string is deprecated` (mspirkov) - Bug #318: Fix deprecation errors `mb_convert_encoding(): Handling HTML entities via mbstring is deprecated` (mspirkov) +- Bug #312: Fix `MarkdownHighlightTrait::highlight()` behavior for PHP 8.3 (mspirkov) - Enh #319: Determining types by type hints for properties, methods and params (mspirkov) - Enh #320: Expand the list of built-in PHP types (mspirkov) - Bug #311: Support `nikic/php-parser` v5 (mspirkov) diff --git a/composer.json b/composer.json index 0805832..4b8310d 100644 --- a/composer.json +++ b/composer.json @@ -32,8 +32,8 @@ "scrivo/highlight.php": "^9.0" }, "require-dev": { - "phpunit/phpunit": "^9.6", - "spatie/phpunit-snapshot-assertions": "^4.2" + "phpunit/phpunit": "^9.6 || ^10.0", + "spatie/phpunit-snapshot-assertions": "^4.2 || ^5.0" }, "repositories": [ { diff --git a/helpers/MarkdownHighlightTrait.php b/helpers/MarkdownHighlightTrait.php index f2eb93b..26a2ba3 100644 --- a/helpers/MarkdownHighlightTrait.php +++ b/helpers/MarkdownHighlightTrait.php @@ -78,8 +78,14 @@ public static function highlight($code, $language) $text = substr($text, 0, $pos) . substr($text, $pos + 6); } } - // remove \n and tags added by php - $text = substr(trim($text), 36, -16); + + // Remove prefixes and suffixes added by php + if (PHP_VERSION_ID >= 80300) { + // The `highlight_string` result format has changed since PHP8.3 + $text = substr($text, 34, -13); + } else { + $text = substr($text, 36, -16); + } return $text; } diff --git a/phpunit-7x.xml.dist b/phpunit-7x.xml.dist new file mode 100644 index 0000000..57992e2 --- /dev/null +++ b/phpunit-7x.xml.dist @@ -0,0 +1,18 @@ + + + + + ./tests + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a2bff89..a44f811 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,18 @@ - - - - ./tests - - + + + + ./tests + + diff --git a/tests/commands/ApiControllerTest.php b/tests/commands/ApiControllerTest.php index 2c90d6d..97f3352 100644 --- a/tests/commands/ApiControllerTest.php +++ b/tests/commands/ApiControllerTest.php @@ -86,6 +86,12 @@ public function testGenerateBootstrap() $fileContent = preg_replace('/\s+href\s*=\s*(["\'])#[^"\']*\1/i', '', $fileContent); $fileContent = preg_replace('/\s+data-target\s*=\s*(["\'])#[^"\']*\1/i', '', $fileContent); + // The `highlight_string` result format has changed since PHP8.3 + // To prevent test failures, we remove some spaces. + $fileContent = str_replace('> $', '>$', $fileContent); + $fileContent = str_replace('> <', '><', $fileContent); + $fileContent = str_replace('= ', '= ', $fileContent); + $this->assertMatchesHtmlSnapshot($fileContent); $filesCount++; } diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__1.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__1.html index febfd20..339af7d 100644 --- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__1.html +++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__1.html @@ -211,7 +211,7 @@

Property Details

-public integer $age null +publicinteger$age= null
@@ -234,7 +234,7 @@

Property Details

-public integer $birthDate null +publicinteger$birthDate= null
@@ -257,7 +257,7 @@

Property Details

-public string $name null +publicstring$name= null
@@ -279,7 +279,7 @@

Property Details

@@ -301,7 +301,7 @@

Property Details

@@ -333,7 +333,7 @@

Method Details

+publicintegergetAge ( ) @@ -357,7 +357,7 @@

Method Details

-                public function getAge()
+                publicfunctiongetAge()
 {
     return time() - $this->birthDate;
 }
@@ -387,7 +387,7 @@ 

Method Details

-public integer getAge ( )
+publicintegergetSomething ( $test ) @@ -429,7 +429,7 @@

Method Details

-public integer getSomething ( $test )
$test
+publicbooleanisOlder ( $date ) @@ -453,9 +453,9 @@

Method Details

-                public function isOlder($date)
+                publicfunctionisOlder($date)
 {
-    return $this->getAge() > $date;
+    return$this->getAge() > $date;
 }
 
             
@@ -483,7 +483,7 @@

Method Details

-public boolean isOlder ( $date )
$date
+public abstractstringrender ( ) @@ -507,7 +507,7 @@

Method Details

-                abstract public function render();
+                abstractpublicfunctionrender();
 
             
@@ -534,7 +534,7 @@

Method Details

-public abstract string render ( )
+publicselfsetBirthDate ( integer$birthDate ) @@ -557,10 +557,10 @@

Method Details

-                public function setBirthDate(int $birthDate): self
+                publicfunctionsetBirthDate(int $birthDate): self
 {
     $this->birthDate = $birthDate;
-    return $this;
+    return$this;
 }
 
             
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html index d2064fe..6d5c49f 100644 --- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html +++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html @@ -216,7 +216,7 @@

Method Details

-public self setBirthDate ( integer $birthDate )
$birthDate
+publicintegergetAge ( ) @@ -240,7 +240,7 @@

Method Details

-                public function getAge()
+                publicfunctiongetAge()
 {
     return time() - $this->birthDate;
 }
@@ -273,7 +273,7 @@ 

Method Details

-public integer getAge ( )
+publicintegergetSomething ( $test ) @@ -318,7 +318,7 @@

Method Details

-public integer getSomething ( $test )
$test
+publicbooleanisOlder ( $date ) @@ -342,9 +342,9 @@

Method Details

-                public function isOlder($date)
+                publicfunctionisOlder($date)
 {
-    return $this->getAge() > $date;
+    return$this->getAge() > $date;
 }
 
             
@@ -372,7 +372,7 @@

Method Details

-public boolean isOlder ( $date )
$date
+publicmixedmethodWithoutDocAndTypeHints ( )
-public mixed methodWithoutDocAndTypeHints ( )
@@ -387,9 +387,9 @@

Method Details

-                public function methodWithoutDocAndTypeHints()
+                publicfunctionmethodWithoutDocAndTypeHints()
 {
-    return '';
+    return'';
 }
 
             
@@ -417,7 +417,7 @@

Method Details

+publicstringrender ( ) @@ -441,10 +441,10 @@

Method Details

-                public function render()
+                publicfunctionrender()
 {
     // this method has `inheritdoc` tag in brackets
-    return 'This is a cat';
+    return'This is a cat';
 }
 
             
@@ -475,7 +475,7 @@

Method Details

-public string render ( )
+publicselfsetBirthDate ( integer$birthDate ) @@ -498,10 +498,10 @@

Method Details

-                public function setBirthDate(int $birthDate): self
+                publicfunctionsetBirthDate(int $birthDate): self
 {
     $this->birthDate = $birthDate;
-    return $this;
+    return$this;
 }
 
             
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html index d3fa87b..a6d3b7b 100644 --- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html +++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html @@ -211,7 +211,7 @@

Method Details

-public self setBirthDate ( integer $birthDate )
$birthDate
+publicintegergetAge ( ) @@ -235,7 +235,7 @@

Method Details

-                public function getAge()
+                publicfunctiongetAge()
 {
     return time() - $this->birthDate;
 }
@@ -268,7 +268,7 @@ 

Method Details

-public integer getAge ( )
+publicintegergetSomething ( $test ) @@ -313,7 +313,7 @@

Method Details

-public integer getSomething ( $test )
$test
+publicbooleanisOlder ( $date ) @@ -337,9 +337,9 @@

Method Details

-                public function isOlder($date)
+                publicfunctionisOlder($date)
 {
-    return $this->getAge() > $date;
+    return$this->getAge() > $date;
 }
 
             
@@ -367,7 +367,7 @@

Method Details

-public boolean isOlder ( $date )
$date
+publicstringrender ( ) @@ -391,10 +391,10 @@

Method Details

-                public function render()
+                publicfunctionrender()
 {
     // this method has `inheritdoc` tag without brackets
-    return 'This is a dog';
+    return'This is a dog';
 }
 
             
@@ -425,7 +425,7 @@

Method Details

-public string render ( )
+publicselfsetBirthDate ( integer$birthDate ) @@ -448,10 +448,10 @@

Method Details

-                public function setBirthDate(int $birthDate): self
+                publicfunctionsetBirthDate(int $birthDate): self
 {
     $this->birthDate = $birthDate;
-    return $this;
+    return$this;
 }
 
             
-public self setBirthDate ( integer $birthDate )
$birthDate