diff --git a/hamcrest/Hamcrest/Xml/HasXPath.php b/hamcrest/Hamcrest/Xml/HasXPath.php index 2529f7270..097c8c5ff 100644 --- a/hamcrest/Hamcrest/Xml/HasXPath.php +++ b/hamcrest/Hamcrest/Xml/HasXPath.php @@ -125,13 +125,15 @@ protected function matchesContent(\DOMNodeList $nodes, Description $mismatchDesc return true; } else { foreach ($nodes as $node) { - if ($this->_matcher->matches($node->textContent)) { + if ($node instanceof \DOMNode && $this->_matcher->matches($node->textContent)) { return true; } } $content = array(); foreach ($nodes as $node) { - $content[] = $node->textContent; + if ($node instanceof \DOMNode) { + $content[] = $node->textContent; + } } $mismatchDescription->appendText('XPath returned ') ->appendValue($content);