File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ CHANGELOG
55-----
66
77 * deprecated ` Symfony\Component\Finder\Iterator\FilterIterator `
8+ * added Finder::hasResults() method to check if any results were found
89
9103.3.0
1011-----
Original file line number Diff line number Diff line change @@ -613,6 +613,20 @@ public function append($iterator)
613613 return $ this ;
614614 }
615615
616+ /**
617+ * Check if the any results were found.
618+ *
619+ * @return bool
620+ */
621+ public function hasResults ()
622+ {
623+ foreach ($ this ->getIterator () as $ _ ) {
624+ return true ;
625+ }
626+
627+ return false ;
628+ }
629+
616630 /**
617631 * Counts all the results collected by the iterators.
618632 *
Original file line number Diff line number Diff line change @@ -424,6 +424,20 @@ public function testCountWithoutIn()
424424 count ($ finder );
425425 }
426426
427+ public function testHasResults ()
428+ {
429+ $ finder = $ this ->buildFinder ();
430+ $ finder ->in (__DIR__ );
431+ $ this ->assertTrue ($ finder ->hasResults ());
432+ }
433+
434+ public function testNoResults ()
435+ {
436+ $ finder = $ this ->buildFinder ();
437+ $ finder ->in (__DIR__ )->name ('DoesNotExist ' );
438+ $ this ->assertFalse ($ finder ->hasResults ());
439+ }
440+
427441 /**
428442 * @dataProvider getContainsTestData
429443 */
You can’t perform that action at this time.
0 commit comments