Skip to content

Commit 4a7ca5d

Browse files
authored
Merge pull request #44 from GravityPDF/wrap-all-return-no-matches
Fix return value of wrapAll() when count() is 0
2 parents ba73464 + a7bebcb commit 4a7ca5d

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
QueryPath Changelog
22
===========================
33

4-
# 3.2.4
4+
# 4.0.0
55

66
- 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().
7+
- Return DOMQuery object if QueryMutators::wrapAll() has no matches (instead of null). This aligns the method with the Docblock return type.
78

89
# 3.2.3
910

src/Helpers/QueryMutators.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public function wrap($markup): Query
453453
public function wrapAll($markup)
454454
{
455455
if ($this->matches->count() === 0) {
456-
return;
456+
return $this;
457457
}
458458

459459
$data = $this->prepareInsert($markup);

tests/QueryPath/DOMQueryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,9 @@ public function testWrapAll()
10341034
'li'
10351035
)->wrapAll('<test class="testWrap"><inside><center/></inside></test>')->get(0)->ownerDocument->saveXML();
10361036
$this->assertEquals(5, qp($xml, '.testWrap > inside > center > li')->count());
1037+
1038+
// verify wrapAll() returns DomQuery object is no matches
1039+
$this->assertInstanceOf(DOMQuery::class, qp($file, '#non-existing-selector')->wrapAll(''));
10371040
}
10381041

10391042
public function testWrapInner()

0 commit comments

Comments
 (0)