diff --git a/CHANGELOG.md b/CHANGELOG.md index 11b1bf2..c0a3746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Helpers/QueryMutators.php b/src/Helpers/QueryMutators.php index dacfc76..c0043c5 100644 --- a/src/Helpers/QueryMutators.php +++ b/src/Helpers/QueryMutators.php @@ -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); diff --git a/tests/QueryPath/DOMQueryTest.php b/tests/QueryPath/DOMQueryTest.php index 9926d31..39c49fd 100644 --- a/tests/QueryPath/DOMQueryTest.php +++ b/tests/QueryPath/DOMQueryTest.php @@ -1034,6 +1034,9 @@ public function testWrapAll() 'li' )->wrapAll('
')->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()