Skip to content

Commit dc05790

Browse files
committed
Throw InvalidSelectorException instead of InvalidArgumentException when selector is empty
1 parent 69ab6a0 commit dc05790

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/DiDom/Query.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,14 @@ protected static function convertContains($string, $caseSensetive = false)
387387
*
388388
* @return array
389389
*
390-
* @throws \InvalidArgumentException if an empty string is passed
391-
* @throws \InvalidSelectorException if the selector is not valid
390+
* @throws \InvalidSelectorException if the selector is empty or not valid
392391
*/
393392
public static function getSegments($selector)
394393
{
395394
$selector = trim($selector);
396395

397396
if ($selector === '') {
398-
throw new InvalidArgumentException('The selector must not be empty');
397+
throw new InvalidSelectorException('The selector must not be empty');
399398
}
400399

401400
$tag = '(?P<tag>[\*|\w|\-]+)?';

tests/DiDom/QueryTest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ public function testBuildXpathWithEmptyArray()
4040
}
4141

4242
/**
43-
* @expectedException InvalidArgumentException
43+
* @expectedException DiDom\Exceptions\InvalidSelectorException
44+
*/
45+
public function testCompileWithEmptySelector()
46+
{
47+
Query::compile('');
48+
}
49+
50+
/**
51+
* @expectedException DiDom\Exceptions\InvalidSelectorException
4452
*/
4553
public function testGetSegmentsWithEmptySelector()
4654
{

0 commit comments

Comments
 (0)