Skip to content

Commit

Permalink
Replace laminas/dom with symfony/dom-crawler
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegrunwell committed Nov 16, 2023
1 parent 590e375 commit 8642ed0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"require": {
"php": "^5.6 || ^7.0 || ^8.0",
"laminas/laminas-dom": "~2.7.2 || ^2.8"
"symfony/css-selector": "^3.4|^4.4|^5.4|^6.0",
"symfony/dom-crawler": "^3.4|^4.4|^5.4|^6.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.2 || ^6.2"
Expand Down
16 changes: 6 additions & 10 deletions src/MarkupAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

namespace SteveGrunwell\PHPUnit_Markup_Assertions;

use DOMDocument;
use Laminas\Dom\Document;
use Laminas\Dom\Document\Query;
use PHPUnit\Framework\RiskyTestError;
use Symfony\Component\DomCrawler\Crawler;

trait MarkupAssertionsTrait
{
Expand Down Expand Up @@ -220,15 +218,13 @@ public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $m
* @param string $markup The HTML for the DOMDocument.
* @param string $query The DOM selector query.
*
* @return \Laminas\Dom\Document\NodeList
* @return Crawler
*/
protected function executeDomQuery($markup, $query)
{
return Query::execute(
$query,
new Document('<?xml encoding="UTF-8">' . $markup, Document::DOC_HTML, 'UTF-8'),
Query::TYPE_CSS
);
$dom = new Crawler($markup);

return $dom->filter($query);
}

/**
Expand Down Expand Up @@ -277,7 +273,7 @@ protected function getInnerHtmlOfMatchedElements($markup, $query)

// Loop through results and collect their innerHTML values.
foreach ($results as $result) {
$document = new DOMDocument();
$document = new \DOMDocument();
$document->appendChild($document->importNode($result->firstChild, true));

$contents[] = trim(html_entity_decode($document->saveHTML()));
Expand Down

0 comments on commit 8642ed0

Please sign in to comment.