Skip to content

Commit

Permalink
Fix return value of wrapAll() when count() is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejackson1 committed Aug 12, 2024
1 parent ba73464 commit a7bebcb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
QueryPath Changelog
===========================

# 3.2.4
# 4.0.0

- Reverse logic in DomQuery::html5() so that DomQuery::html5() returns the content of the current match, and DomQuery::html5('') replaces the content of the current matches. This matches the existing logic used in DomQuery::html().
- Return DOMQuery object if QueryMutators::wrapAll() has no matches (instead of null). This aligns the method with the Docblock return type.

# 3.2.3

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/QueryMutators.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public function wrap($markup): Query
public function wrapAll($markup)
{
if ($this->matches->count() === 0) {
return;
return $this;
}

$data = $this->prepareInsert($markup);
Expand Down
3 changes: 3 additions & 0 deletions tests/QueryPath/DOMQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,9 @@ public function testWrapAll()
'li'
)->wrapAll('<test class="testWrap"><inside><center/></inside></test>')->get(0)->ownerDocument->saveXML();
$this->assertEquals(5, qp($xml, '.testWrap > inside > center > li')->count());

// verify wrapAll() returns DomQuery object is no matches
$this->assertInstanceOf(DOMQuery::class, qp($file, '#non-existing-selector')->wrapAll(''));
}

public function testWrapInner()
Expand Down

0 comments on commit a7bebcb

Please sign in to comment.