16
16
*/
17
17
class ResultPagerTest extends \PHPUnit \Framework \TestCase
18
18
{
19
+ public function provideFetchCases ()
20
+ {
21
+ return [
22
+ ['fetchAll ' ],
23
+ ['fetchAllLazy ' ],
24
+ ];
25
+ }
26
+
19
27
/**
20
- * @test
28
+ * @test provideFetchCases
21
29
*
22
- * description fetchAll
30
+ * @dataProvider provideFetchCases
23
31
*/
24
- public function shouldGetAllResults ()
32
+ public function shouldGetAllResults (string $ fetchMethod )
25
33
{
26
34
$ amountLoops = 3 ;
27
35
$ content = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
@@ -46,7 +54,14 @@ public function shouldGetAllResults()
46
54
47
55
// Run fetchAll on result paginator
48
56
$ paginator = new ResultPager ($ client );
49
- $ result = $ paginator ->fetchAll ($ memberApi , $ method , $ parameters );
57
+
58
+ $ result = $ paginator ->$ fetchMethod ($ memberApi , $ method , $ parameters );
59
+
60
+ if (is_array ($ result )) {
61
+ $ this ->assertSame ('fetchAll ' , $ fetchMethod );
62
+ } else {
63
+ $ result = iterator_to_array ($ result );
64
+ }
50
65
51
66
$ this ->assertCount ($ amountLoops * count ($ content ), $ result );
52
67
}
@@ -92,4 +107,29 @@ public function shouldGetAllSearchResults()
92
107
93
108
$ this ->assertCount ($ amountLoops * count ($ content ['items ' ]), $ result );
94
109
}
110
+
111
+ public function testFetch ()
112
+ {
113
+ $ result = 'foo ' ;
114
+ $ method = 'all ' ;
115
+ $ parameters = ['baz ' ];
116
+ $ api = $ this ->getMockBuilder (Members::class)
117
+ ->disableOriginalConstructor ()
118
+ ->setMethods (['all ' ])
119
+ ->getMock ();
120
+ $ api ->expects ($ this ->once ())
121
+ ->method ('all ' )
122
+ ->with (...$ parameters )
123
+ ->willReturn ($ result );
124
+
125
+ $ paginator = $ this ->getMockBuilder (ResultPager::class)
126
+ ->disableOriginalConstructor ()
127
+ ->setMethods (['postFetch ' ])
128
+ ->getMock ();
129
+
130
+ $ paginator ->expects ($ this ->once ())
131
+ ->method ('postFetch ' );
132
+
133
+ $ this ->assertEquals ($ result , $ paginator ->fetch ($ api , $ method , $ parameters ));
134
+ }
95
135
}
0 commit comments