2
2
3
3
namespace Tests \Modifiers ;
4
4
5
+ use Illuminate \Contracts \Support \Arrayable ;
6
+ use Mockery ;
7
+ use Statamic \Contracts \Query \Builder ;
5
8
use Statamic \Modifiers \Modify ;
6
9
use Tests \TestCase ;
7
10
@@ -19,6 +22,36 @@ public function it_returns_the_numbers_of_items_in_array(): void
19
22
$ this ->assertSame (3 , $ modified );
20
23
}
21
24
25
+ /** @test */
26
+ public function it_returns_the_numbers_of_items_in_collection (): void
27
+ {
28
+ $ arr = collect ([
29
+ 'Taylor Swift ' ,
30
+ 'Left Shark ' ,
31
+ 'Leroy Jenkins ' ,
32
+ ]);
33
+ $ modified = $ this ->modify ($ arr );
34
+ $ this ->assertSame (3 , $ modified );
35
+ }
36
+
37
+ /** @test */
38
+ public function it_returns_the_number_of_items_in_a_query ()
39
+ {
40
+ $ builder = Mockery::mock (Builder::class);
41
+ $ builder ->shouldReceive ('count ' )->once ()->andReturn (3 );
42
+ $ modified = $ this ->modify ($ builder );
43
+ $ this ->assertSame (3 , $ modified );
44
+ }
45
+
46
+ /** @test */
47
+ public function it_returns_the_number_of_items_in_an_arrayable ()
48
+ {
49
+ $ arrayable = Mockery::mock (Arrayable::class)->shouldReceive ('toArray ' )->andReturn (['one ' , 'two ' ])->getMock ();
50
+
51
+ $ modified = $ this ->modify ($ arrayable );
52
+ $ this ->assertSame (2 , $ modified );
53
+ }
54
+
22
55
/** @test */
23
56
public function it_returns_the_numbers_of_chars_in_string (): void
24
57
{
@@ -27,6 +60,17 @@ public function it_returns_the_numbers_of_chars_in_string(): void
27
60
$ this ->assertSame (27 , $ modified );
28
61
}
29
62
63
+ /** @test */
64
+ public function it_counts_a_collection_instead_of_toarraying_it (): void
65
+ {
66
+ $ itemOne = Mockery::mock (Arrayable::class)->shouldNotReceive ('toArray ' )->getMock ();
67
+ $ itemTwo = Mockery::mock (Arrayable::class)->shouldNotReceive ('toArray ' )->getMock ();
68
+
69
+ $ arr = collect ([$ itemOne , $ itemTwo ]);
70
+ $ modified = $ this ->modify ($ arr );
71
+ $ this ->assertSame (2 , $ modified );
72
+ }
73
+
30
74
private function modify ($ value )
31
75
{
32
76
return Modify::value ($ value )->length ()->fetch ();
0 commit comments