@@ -2693,6 +2693,70 @@ public function testWhenDefault()
2693
2693
$ this ->assertSame (['michael ' , 'tom ' , 'taylor ' ], $ collection ->toArray ());
2694
2694
}
2695
2695
2696
+ public function testWhenEmpty ()
2697
+ {
2698
+ $ collection = new Collection (['michael ' , 'tom ' ]);
2699
+
2700
+ $ collection ->whenEmpty (function ($ collection ) {
2701
+ return $ collection ->push ('adam ' );
2702
+ });
2703
+
2704
+ $ this ->assertSame (['michael ' , 'tom ' ], $ collection ->toArray ());
2705
+
2706
+ $ collection = new Collection ;
2707
+
2708
+ $ collection ->whenEmpty (function ($ collection ) {
2709
+ return $ collection ->push ('adam ' );
2710
+ });
2711
+
2712
+ $ this ->assertSame (['adam ' ], $ collection ->toArray ());
2713
+ }
2714
+
2715
+ public function testWhenEmptyDefault ()
2716
+ {
2717
+ $ collection = new Collection (['michael ' , 'tom ' ]);
2718
+
2719
+ $ collection ->whenEmpty (function ($ collection ) {
2720
+ return $ collection ->push ('adam ' );
2721
+ }, function ($ collection ) {
2722
+ return $ collection ->push ('taylor ' );
2723
+ });
2724
+
2725
+ $ this ->assertSame (['michael ' , 'tom ' , 'taylor ' ], $ collection ->toArray ());
2726
+ }
2727
+
2728
+ public function testWhenNotEmpty ()
2729
+ {
2730
+ $ collection = new Collection (['michael ' , 'tom ' ]);
2731
+
2732
+ $ collection ->whenNotEmpty (function ($ collection ) {
2733
+ return $ collection ->push ('adam ' );
2734
+ });
2735
+
2736
+ $ this ->assertSame (['michael ' , 'tom ' , 'adam ' ], $ collection ->toArray ());
2737
+
2738
+ $ collection = new Collection ;
2739
+
2740
+ $ collection ->whenNotEmpty (function ($ collection ) {
2741
+ return $ collection ->push ('adam ' );
2742
+ });
2743
+
2744
+ $ this ->assertSame ([], $ collection ->toArray ());
2745
+ }
2746
+
2747
+ public function testWhenNotEmptyDefault ()
2748
+ {
2749
+ $ collection = new Collection (['michael ' , 'tom ' ]);
2750
+
2751
+ $ collection ->whenNotEmpty (function ($ collection ) {
2752
+ return $ collection ->push ('adam ' );
2753
+ }, function ($ collection ) {
2754
+ return $ collection ->push ('taylor ' );
2755
+ });
2756
+
2757
+ $ this ->assertSame (['michael ' , 'tom ' , 'adam ' ], $ collection ->toArray ());
2758
+ }
2759
+
2696
2760
public function testUnless ()
2697
2761
{
2698
2762
$ collection = new Collection (['michael ' , 'tom ' ]);
@@ -2725,6 +2789,70 @@ public function testUnlessDefault()
2725
2789
$ this ->assertSame (['michael ' , 'tom ' , 'taylor ' ], $ collection ->toArray ());
2726
2790
}
2727
2791
2792
+ public function testUnlessEmpty ()
2793
+ {
2794
+ $ collection = new Collection (['michael ' , 'tom ' ]);
2795
+
2796
+ $ collection ->unlessEmpty (function ($ collection ) {
2797
+ return $ collection ->push ('adam ' );
2798
+ });
2799
+
2800
+ $ this ->assertSame (['michael ' , 'tom ' , 'adam ' ], $ collection ->toArray ());
2801
+
2802
+ $ collection = new Collection ;
2803
+
2804
+ $ collection ->unlessEmpty (function ($ collection ) {
2805
+ return $ collection ->push ('adam ' );
2806
+ });
2807
+
2808
+ $ this ->assertSame ([], $ collection ->toArray ());
2809
+ }
2810
+
2811
+ public function testUnlessEmptyDefault ()
2812
+ {
2813
+ $ collection = new Collection (['michael ' , 'tom ' ]);
2814
+
2815
+ $ collection ->unlessEmpty (function ($ collection ) {
2816
+ return $ collection ->push ('adam ' );
2817
+ }, function ($ collection ) {
2818
+ return $ collection ->push ('taylor ' );
2819
+ });
2820
+
2821
+ $ this ->assertSame (['michael ' , 'tom ' , 'adam ' ], $ collection ->toArray ());
2822
+ }
2823
+
2824
+ public function testUnlessNotEmpty ()
2825
+ {
2826
+ $ collection = new Collection (['michael ' , 'tom ' ]);
2827
+
2828
+ $ collection ->unlessNotEmpty (function ($ collection ) {
2829
+ return $ collection ->push ('adam ' );
2830
+ });
2831
+
2832
+ $ this ->assertSame (['michael ' , 'tom ' ], $ collection ->toArray ());
2833
+
2834
+ $ collection = new Collection ;
2835
+
2836
+ $ collection ->unlessNotEmpty (function ($ collection ) {
2837
+ return $ collection ->push ('adam ' );
2838
+ });
2839
+
2840
+ $ this ->assertSame (['adam ' ], $ collection ->toArray ());
2841
+ }
2842
+
2843
+ public function testUnlessNotEmptyDefault ()
2844
+ {
2845
+ $ collection = new Collection (['michael ' , 'tom ' ]);
2846
+
2847
+ $ collection ->unlessNotEmpty (function ($ collection ) {
2848
+ return $ collection ->push ('adam ' );
2849
+ }, function ($ collection ) {
2850
+ return $ collection ->push ('taylor ' );
2851
+ });
2852
+
2853
+ $ this ->assertSame (['michael ' , 'tom ' , 'taylor ' ], $ collection ->toArray ());
2854
+ }
2855
+
2728
2856
public function testHasReturnsValidResults ()
2729
2857
{
2730
2858
$ collection = new Collection (['foo ' => 'one ' , 'bar ' => 'two ' , 1 => 'three ' ]);
0 commit comments