Skip to content

Downgrade PHPUnit to ^9.6 for PHP 8.0 compatibility#67

Merged
ivopetkov merged 1 commit intoivopetkov:masterfrom
hirasso:fix-tests-in-ci
Feb 12, 2026
Merged

Downgrade PHPUnit to ^9.6 for PHP 8.0 compatibility#67
ivopetkov merged 1 commit intoivopetkov:masterfrom
hirasso:fix-tests-in-ci

Conversation

@hirasso
Copy link
Copy Markdown
Contributor

@hirasso hirasso commented Feb 10, 2026

As discussed in #66 : Downgrade PHPUnit to ^9.6 for PHP 8.0 compatibility.

  • Tests are now running
  • Test::testFragments is failing in CI. That test passes locally on my machine. I asked claude code about it. It pointed me to this:

$matches = [];
preg_match('/\<html.*?\>/', $source, $matches);
if (isset($matches[0])) { // has html tag
$source = str_replace($matches[0], $matches[0] . '<head>' . $charsetTag . '</head>', $source);
} else {
$source = '<html><head>' . $charsetTag . '</head></html>' . $source;
$removeHtmlTag = true;
}
$removeHeadTag = true;

When the input (<div>text</div>) has no <html> tag, it hits line 153:           
                                                                                                                     
$source = '<html><head>' . $charsetTag . '</head></html>' . $source;                                               
$removeHtmlTag = true;                                             
                                                                                                                   
It prepends <html><head><meta ...></head></html> before the fragment to inject a charset meta tag. Then after      
parsing, it tries to clean up (lines 189–194) by removing the temporary head/html tags.

But the key issue: on CI's libxml2, when this combined source is parsed with LIBXML_HTML_NOIMPLIED, libxml absorbs
the <div> into the <html> element rather than keeping it separate. So after cleanup removes the <head> and meta,
the <html> wrapper remains (with the <div> inside it) because $removeHtmlTag only removes the <html> if
$htmlElement->firstChild === null — which it isn't, since the <div> got folded into it.

So it's not a libxml2 bug per se — it's the library's charset injection interacting differently with
LIBXML_HTML_NOIMPLIED across libxml2 versions.

This is something to tackle in a separate PR. But running the tests in CI is already paying off I guess 🙂

@hirasso hirasso force-pushed the fix-tests-in-ci branch 3 times, most recently from 5d3d633 to 85d5614 Compare February 10, 2026 19:35
@ivopetkov ivopetkov merged commit f25cdf6 into ivopetkov:master Feb 12, 2026
0 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants