1616 */
1717class ResultPagerTest extends \PHPUnit \Framework \TestCase
1818{
19+ public function provideFetchCases ()
20+ {
21+ return [
22+ ['fetchAll ' ],
23+ ['fetchAllLazy ' ],
24+ ];
25+ }
26+
1927 /**
20- * @test
28+ * @test provideFetchCases
2129 *
22- * description fetchAll
30+ * @dataProvider provideFetchCases
2331 */
24- public function shouldGetAllResults ()
32+ public function shouldGetAllResults (string $ fetchMethod )
2533 {
2634 $ amountLoops = 3 ;
2735 $ content = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
@@ -46,7 +54,14 @@ public function shouldGetAllResults()
4654
4755 // Run fetchAll on result paginator
4856 $ 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+ }
5065
5166 $ this ->assertCount ($ amountLoops * count ($ content ), $ result );
5267 }
@@ -92,4 +107,29 @@ public function shouldGetAllSearchResults()
92107
93108 $ this ->assertCount ($ amountLoops * count ($ content ['items ' ]), $ result );
94109 }
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+ }
95135}
0 commit comments