Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 28, 2018
1 parent 60b8afa commit a9a7da4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -1774,13 +1774,8 @@ public static function assertXmlStringNotEqualsXmlString($expectedXml, $actualXm
*/
public static function assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement, bool $checkAttributes = false, string $message = ''): void
{
$tmp = new DOMDocument;
$expectedElement = $tmp->importNode($expectedElement, true);

$tmp = new DOMDocument;
$actualElement = $tmp->importNode($actualElement, true);

unset($tmp);
$expectedElement = Xml::import($expectedElement);
$actualElement = Xml::import($actualElement);

static::assertSame(
$expectedElement->tagName,
Expand All @@ -1801,8 +1796,11 @@ public static function assertEqualXMLStructure(DOMElement $expectedElement, DOME
);

for ($i = 0; $i < $expectedElement->attributes->length; $i++) {
/** @var \DOMAttr $expectedAttribute */
$expectedAttribute = $expectedElement->attributes->item($i);
$actualAttribute = $actualElement->attributes->getNamedItem(

/** @var \DOMAttr $actualAttribute */
$actualAttribute = $actualElement->attributes->getNamedItem(
$expectedAttribute->name
);

Expand Down
7 changes: 7 additions & 0 deletions src/Util/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

final class Xml
{
public static function import(DOMElement $element): DOMElement
{
$document = new DOMDocument;

return $document->importNode($element, true);
}

/**
* Load an $actual document into a DOMDocument. This is called
* from the selector assertions.
Expand Down

0 comments on commit a9a7da4

Please sign in to comment.