From a8e583eec70a745786217e8a44ae9d89866ca81a Mon Sep 17 00:00:00 2001 From: Tom Kaminski Date: Sun, 25 Jan 2026 19:30:57 -0600 Subject: [PATCH 1/5] Fix test: Remove XML encoding declaration added by Symfony's UTF-8 handling. Handle Html5 parser. --- Tests/HtmlPageCrawlerTest.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Tests/HtmlPageCrawlerTest.php b/Tests/HtmlPageCrawlerTest.php index 4d52ac8..0068e97 100644 --- a/Tests/HtmlPageCrawlerTest.php +++ b/Tests/HtmlPageCrawlerTest.php @@ -230,11 +230,23 @@ public function testClasses() public function testAddContent() { $c = new HtmlPageCrawler(); - $c->addContent('

Title

'); + $c->addContent('

Title

'); + + // The behaviour of Symfony's \Symfony\Component\DomCrawler\Crawler varies based on Symfony version and PHP Version. + // So for this test, we normalize the output. + + $html = $c->saveHTML(); + + // Old parser (PHP < 8.4) or old Symfony: remove added HTML 4.0 DOCTYPE at the beginning of the html + $html = preg_replace('#^\s*\s*#', '', $html); + + // Remove XML encoding declaration added by Symfony's UTF-8 handling (varies by Symfony version) + $html = preg_replace('#^\s*<\?xml encoding="UTF-8">\s*#', '', $html); + $html = $this->_ignoreNewlines($html); + $this->assertEquals( - '' - . "" . '

Title

' . "", - $this->_ignoreNewlines($c->saveHTML()) + '

Title

', + $html ); $c = new HtmlPageCrawler(); @@ -442,7 +454,7 @@ public function testUnwrap() $p->unwrap(); $this->assertEquals('
Before

Absatz 1

After
', $c->saveHTML()); } - + public function testUnwrapInnerOnDOMElementExeption() { $this->expectException(\InvalidArgumentException::class); @@ -565,7 +577,7 @@ public function testAttr() $this->assertNull($c->attr('data-foo')); } - + public function testAttrOnInvalidNodeList() { $this->expectException(\InvalidArgumentException::class); From 5b7e0dfbed47e64685ed44ff4a702636284137d9 Mon Sep 17 00:00:00 2001 From: Tom Kaminski Date: Sun, 25 Jan 2026 19:33:58 -0600 Subject: [PATCH 2/5] Fix deprecation warning in test --- Tests/HtmlPageCrawlerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/HtmlPageCrawlerTest.php b/Tests/HtmlPageCrawlerTest.php index 0068e97..b1ccf19 100644 --- a/Tests/HtmlPageCrawlerTest.php +++ b/Tests/HtmlPageCrawlerTest.php @@ -458,8 +458,8 @@ public function testUnwrap() public function testUnwrapInnerOnDOMElementExeption() { $this->expectException(\InvalidArgumentException::class); - $this->expectErrorMessage('DOMElement does not have a parent DOMElement node.'); - + $this->expectExceptionMessage('DOMElement does not have a parent DOMElement node.'); + $c = HtmlPageCrawler::create('
'); $p = $c->filter('div#content'); $p->unwrapInner(); From ab322f547cd6a0e800091fdbc09b44d4fb5c98de Mon Sep 17 00:00:00 2001 From: Tom Kaminski Date: Sun, 25 Jan 2026 19:39:13 -0600 Subject: [PATCH 3/5] Add php 8.4 and 8.5 to the text matrix --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e77709e..5e10b5f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - php: [8.0, 8.1, 8.2, 8.3] + php: [8.0, 8.1, 8.2, 8.3, 8.4, 8.5] dependency-version: [prefer-lowest, prefer-stable] steps: From 4ba9835555fa25fcc9a285e80ec97fe3d7c7d2e1 Mon Sep 17 00:00:00 2001 From: Tom Kaminski Date: Sun, 25 Jan 2026 21:03:55 -0600 Subject: [PATCH 4/5] Fix spelling error --- Tests/HtmlPageCrawlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/HtmlPageCrawlerTest.php b/Tests/HtmlPageCrawlerTest.php index b1ccf19..39d35de 100644 --- a/Tests/HtmlPageCrawlerTest.php +++ b/Tests/HtmlPageCrawlerTest.php @@ -455,7 +455,7 @@ public function testUnwrap() $this->assertEquals('
Before

Absatz 1

After
', $c->saveHTML()); } - public function testUnwrapInnerOnDOMElementExeption() + public function testUnwrapInnerOnDOMElementException() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('DOMElement does not have a parent DOMElement node.'); From b1c75d664542692312b44a0746c3edc9a6908a2e Mon Sep 17 00:00:00 2001 From: Tom Kaminski Date: Sun, 25 Jan 2026 21:15:15 -0600 Subject: [PATCH 5/5] Add support for Symfony 8 --- README.md | 4 ++-- composer.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4238ea0..e0d7bb1 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ Requirements and Compatibility Version 3.x: - PHP 8.x -- [Symfony\Components\DomCrawler](https://github.com/symfony/DomCrawler) 6.x | 7.x -- [Symfony\Components\CssSelector](https://github.com/symfony/CssSelector) 6.x | 7.x +- [Symfony\Components\DomCrawler](https://github.com/symfony/DomCrawler) 6.x | 7.x | 8.x +- [Symfony\Components\CssSelector](https://github.com/symfony/CssSelector) 6.x | 7.x | 8.x Version 2.x: - PHP ^7.4 | 8.x diff --git a/composer.json b/composer.json index b6a37ae..e980191 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ "ext-dom":"*", "ext-libxml":"*", "symfony/polyfill-mbstring": "~1.0", - "symfony/dom-crawler":"^6.0 || ^7.0", - "symfony/css-selector":"^6.0 || ^7.0" + "symfony/dom-crawler":"^6.0 || ^7.0 || ^8.0", + "symfony/css-selector":"^6.0 || ^7.0 || ^8.0" }, "require-dev": { "phpunit/phpunit": "^9",