From 1ad0a514d893ec281abb2361f2d4f3d2197f4a47 Mon Sep 17 00:00:00 2001 From: Jake Jackson Date: Thu, 26 Nov 2026 11:50:31 +1100 Subject: [PATCH 1/2] Add PHP 8.6 support Backport of #160 to the 4.3 branch: allow ~8.6.0 in composer.json and add 8.6 to the PHPUnit matrix. The test change in #160 is not needed here. testFailWriteXMLReportsWarning, which asserted the exact warning text PHP 8.6 changed, was added on main after 4.2.0. (cherry picked from commit 281a375b85545dfcf14fe3ddb624c7bb0dcaf0d0) Co-Authored-By: Claude Opus 5.5 --- .github/workflows/unit-testing.yml | 2 +- CHANGELOG.md | 2 +- composer.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index b92fc09..ad093d8 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ] + php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6' ] include: - php: '8.3' report: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 46c7f60..87a0c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ QueryPath Changelog # Unreleased changes -- +- Add support for PHP 8.6 # 4.1.0 diff --git a/composer.json b/composer.json index 21438d6..3af5bd1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "gravitypdf/querypath", "type": "library", - "description": "PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP 7.0 to 8.5 support", + "description": "PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP 7.0 to 8.6 support", "homepage": "https://github.com/gravitypdf/querypath", "license": "MIT", "keywords": [ @@ -23,7 +23,7 @@ } ], "require": { - "php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0", + "php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0", "masterminds/html5": "^2.0" }, "autoload": { From 8cdafefc46795f13d754bda7c825963a00b6c1e4 Mon Sep 17 00:00:00 2001 From: gravitypdf-bot Date: Thu, 26 Nov 2026 11:54:33 +1100 Subject: [PATCH 2/2] Fix CI on ubuntu-26.04, whose libxml2 parses HTML as HTML5 Backport of the applicable parts of 7ffe1aa. GitHub's ubuntu-latest is now ubuntu-26.04, whose libxml2 2.15 no longer reports HTML parse errors, so testFailedParseHTMLElement failed on every PHP version. - Skip that test when libxml parses HTML as HTML5, probed at runtime - Run the coverage job on ubuntu-24.04, and only on PHP 8.3 (the old include applied report: true to every job) - Bump actions/checkout to v7 and codecov/codecov-action to v7 (cherry picked from commit 7ffe1aabe0c5c1e67b477ce27e7f2752c56fed22) Co-Authored-By: Claude Opus 5.5 --- .github/workflows/coding-standard.yml | 2 +- .github/workflows/unit-testing.yml | 11 ++++++---- CHANGELOG.md | 1 + tests/QueryPath/DOMQueryTest.php | 2 ++ tests/QueryPath/TestCase.php | 29 +++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.github/workflows/coding-standard.yml b/.github/workflows/coding-standard.yml index 29e2b44..0bc15c3 100644 --- a/.github/workflows/coding-standard.yml +++ b/.github/workflows/coding-standard.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@v7 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index ad093d8..32d57f1 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -4,18 +4,21 @@ on: [ pull_request ] jobs: phpunit: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os || 'ubuntu-latest' }} strategy: matrix: php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6' ] include: - - php: '8.3' + # libxml2 2.14+ (ubuntu-26.04 onwards) parses HTML as HTML5, which skips the tests for + # libxml's older HTML parser, so the coverage job stays on a runner that still has it. + - php-versions: '8.3' + os: ubuntu-24.04 report: true name: PHP ${{ matrix.php-versions }} PHPUnit Test steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@v7 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -41,7 +44,7 @@ jobs: - name: Check Code Coverage if: ${{ matrix.report }} - uses: codecov/codecov-action@v5 + uses: codecov/codecov-action@v7 with: directory: ./coverage/ token: ${{ secrets.CODECOV_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 87a0c57..20c1cb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ QueryPath Changelog # Unreleased changes - Add support for PHP 8.6 +- With libxml2 2.14+, `htmlqp()` parses `` as a comment (``) and no longer throws `QueryPath\ParseException` on malformed HTML. Use `html5qp()` to keep processing instructions # 4.1.0 diff --git a/tests/QueryPath/DOMQueryTest.php b/tests/QueryPath/DOMQueryTest.php index 4e4027f..9a603ab 100644 --- a/tests/QueryPath/DOMQueryTest.php +++ b/tests/QueryPath/DOMQueryTest.php @@ -287,6 +287,8 @@ public function testFailedHTTPLoadWithContext() public function testFailedParseHTMLElement() { + $this->requireLegacyHtmlParser(); + $this->expectException(ParseException::class); try { diff --git a/tests/QueryPath/TestCase.php b/tests/QueryPath/TestCase.php index 4d6d1e3..f305a41 100644 --- a/tests/QueryPath/TestCase.php +++ b/tests/QueryPath/TestCase.php @@ -11,4 +11,33 @@ class TestCase extends \Yoast\PHPUnitPolyfills\TestCases\TestCase { public const DATA_FILE_XML = 'tests/data.xml'; public const DATA_FILE_HTML = 'tests/data.html'; + + /** + * Whether libxml's HTML parser follows HTML5, as it does from 2.14. + * + * Such a parser reads `` as a comment rather than a processing instruction, and reports no + * parse errors. Probed rather than read from LIBXML_VERSION, which is the version PHP was built + * against, not necessarily the one it runs with. + * + * @return bool + */ + protected static function libxmlParsesHtmlAsHtml5(): bool + { + static $html5; + + if ($html5 === null) { + $document = new \DOMDocument(); + @$document->loadHTML('

'); + $html5 = ! $document->getElementsByTagName('p')->item(0)->firstChild instanceof \DOMProcessingInstruction; + } + + return $html5; + } + + protected function requireLegacyHtmlParser() + { + if (self::libxmlParsesHtmlAsHtml5()) { + $this->markTestSkipped('libxml ' . LIBXML_DOTTED_VERSION . ' parses HTML as HTML5.'); + } + } }