Skip to content

Refactor serializer tests to shared base with DOM-specific subclasses - #276

Draft
goetas with Copilot wants to merge 2 commits into
masterfrom
copilot/remove-duplicate-tests
Draft

Refactor serializer tests to shared base with DOM-specific subclasses#276
goetas with Copilot wants to merge 2 commits into
masterfrom
copilot/remove-duplicate-tests

Conversation

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

PR #257’s serializer coverage for PHP 8.4 Dom\HTMLDocument duplicated nearly the entire legacy OutputRulesTest suite. This refactor keeps equivalent coverage while centralizing shared assertions and isolating only runtime-specific behavior.

  • Shared test consolidation

    • Introduced AbstractOutputRulesTest with common OutputRules serializer assertions.
    • Moved duplicated setup/helpers and shared test cases into the base class.
  • DOM-specific specialization

    • OutputRulesTest now acts as the legacy DOMDocument subclass.
    • OutputRulesNewDomTest now acts as the PHP 8.4 Dom\HTMLDocument subclass.
    • Kept only behavior deltas in subclasses (e.g., namespace serialization shape, PI creation path, invalid-raw-content skip in new DOM).
  • Compatibility helpers

    • Added overridable node-factory helpers in the base class (createCommentNode, createTextNode, createElementWithText) so each DOM implementation can construct nodes safely without duplicating full test methods.
abstract class AbstractOutputRulesTest extends TestCase
{
    abstract protected function loadHTML($html);

    protected function createElementWithText($dom, $name, $value)
    {
        return $dom->createElement($name, $value); // legacy DOM
    }
}

final class OutputRulesNewDomTest extends AbstractOutputRulesTest
{
    protected function loadHTML($html)
    {
        return HTMLDocument::createFromString($html, $options);
    }

    protected function createElementWithText($dom, $name, $value)
    {
        $el = $dom->createElement($name);
        $el->textContent = $value;
        return $el;
    }
}

Copilot AI and others added 2 commits August 18, 2026 05:51
…classes

Co-authored-by: goetas <776743+goetas@users.noreply.github.com>
Co-authored-by: goetas <776743+goetas@users.noreply.github.com>
@goetas
goetas marked this pull request as ready for review August 18, 2026 05:57
@goetas
goetas marked this pull request as draft August 18, 2026 05:58
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