File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Illuminate \Tests \Support ;
4
4
5
+ use Illuminate \Collections \MultipleItemsFoundException ;
5
6
use Illuminate \Support \LazyCollection ;
6
7
use PHPUnit \Framework \TestCase ;
7
8
use stdClass ;
@@ -979,13 +980,29 @@ public function testSomeIsLazy()
979
980
980
981
public function testSoleIsLazy ()
981
982
{
982
- $ data = $ this ->make ([['a ' => 1 ], ['a ' => 2 ], ['a ' => 3 ]]);
983
+ $ this ->assertEnumerates (2 , function ($ collection ) {
984
+ try {
985
+ $ collection ->sole ();
986
+ } catch (MultipleItemsFoundException $ e ) {
987
+ //
988
+ }
989
+ });
983
990
984
- $ this ->assertEnumeratesCollection ( $ data , 3 , function ($ collection ) {
991
+ $ this ->assertEnumeratesOnce ( function ($ collection ) {
985
992
$ collection ->sole (function ($ item ) {
986
- return $ item[ ' a ' ] === 2 ;
993
+ return $ item === 1 ;
987
994
});
988
995
});
996
+
997
+ $ this ->assertEnumerates (4 , function ($ collection ) {
998
+ try {
999
+ $ collection ->sole (function ($ item ) {
1000
+ return $ item % 2 === 0 ;
1001
+ });
1002
+ } catch (MultipleItemsFoundException $ e ) {
1003
+ //
1004
+ }
1005
+ });
989
1006
}
990
1007
991
1008
public function testSortIsLazy ()
You can’t perform that action at this time.
0 commit comments