Skip to content

Reimplement main aspect of assertEqualXMLStructure #4507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,27 @@
static::assertNotEquals($expected, $actual, $message);
}

public static function assertDOMTreesEqualStructurally(DOMElement $expectedElement, DOMElement $actualElement, bool $keepComments = false, string $message = ''): void

Check warning on line 2254 in src/Framework/Assert.php

View check run for this annotation

Codecov / codecov/patch

src/Framework/Assert.php#L2254

Added line #L2254 was not covered by tests
{
$ed = new DOMDocument();
$ed->appendChild($ed->importNode($expectedElement, true));
$xmlStr = $ed->C14N(false, $keepComments);

Check warning on line 2258 in src/Framework/Assert.php

View check run for this annotation

Codecov / codecov/patch

src/Framework/Assert.php#L2256-L2258

Added lines #L2256 - L2258 were not covered by tests

$ed->preserveWhiteSpace = false;
$ed->loadXML($xmlStr);
$ed->formatOutput = true;

Check warning on line 2262 in src/Framework/Assert.php

View check run for this annotation

Codecov / codecov/patch

src/Framework/Assert.php#L2260-L2262

Added lines #L2260 - L2262 were not covered by tests

$ad = new DOMDocument();
$ad->appendChild($ad->importNode($actualElement, true));
$xmlStr = $ad->C14N(false, $keepComments);

Check warning on line 2266 in src/Framework/Assert.php

View check run for this annotation

Codecov / codecov/patch

src/Framework/Assert.php#L2264-L2266

Added lines #L2264 - L2266 were not covered by tests

$ad->preserveWhiteSpace = false;
$ad->loadXML($xmlStr);
$ad->formatOutput = true;

Check warning on line 2270 in src/Framework/Assert.php

View check run for this annotation

Codecov / codecov/patch

src/Framework/Assert.php#L2268-L2270

Added lines #L2268 - L2270 were not covered by tests

self::assertEquals($ed->documentElement, $ad->documentElement, $message);

Check warning on line 2272 in src/Framework/Assert.php

View check run for this annotation

Codecov / codecov/patch

src/Framework/Assert.php#L2272

Added line #L2272 was not covered by tests
}

/**
* Asserts that a hierarchy of DOMElements matches.
*
Expand Down
17 changes: 17 additions & 0 deletions src/Framework/Assert/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,23 @@ function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, string $mes
}
}

if (!function_exists('PHPUnit\Framework\assertDOMTreesEqualStructurally')) {
/**
* Asserts that two DOM trees are structurally identical.
*
* @throws AssertionFailedError
* @throws ExpectationFailedException
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*
* @see Assert::assertDOMTreesEqualStructurally
*/
function assertDOMTreesEqualStructurally(DOMElement $expectedElement, DOMElement $actualElement, bool $keepComments = false, string $message = ''): void
{
Assert::assertDOMTreesEqualStructurally(...func_get_args());
}
}

if (!function_exists('PHPUnit\Framework\assertEqualXMLStructure')) {
/**
* Asserts that a hierarchy of DOMElements matches.
Expand Down