44
55use Saloon \Http \Response ;
66use Illuminate \Support \Collection ;
7+ use Saloon \Http \Faking \MockClient ;
8+ use Saloon \Http \Faking \MockResponse ;
79use Saloon \PaginationPlugin \Tests \Fixtures \Connectors \PagedConnector ;
810use Saloon \PaginationPlugin \Tests \Fixtures \Requests \SuperheroPagedRequest ;
911
@@ -29,3 +31,38 @@ function toIds(array $items): array
2931
3032 expect ($ paginator ->getTotalResults ())->toEqual (20 );
3133});
34+
35+ /**
36+ * @see https://github.com/saloonphp/saloon/issues/464
37+ */
38+ test ('multiple collect calls on same LazyCollection do not trigger infinite loop detection ' , function () {
39+ $ singlePageResponse = [
40+ 'data ' => [['id ' => 1 ], ['id ' => 2 ]],
41+ 'next_page_url ' => null ,
42+ ];
43+
44+ $ connector = new PagedConnector ;
45+ $ connector ->withMockClient (new MockClient ([
46+ MockResponse::make ($ singlePageResponse ),
47+ MockResponse::make ($ singlePageResponse ),
48+ MockResponse::make ($ singlePageResponse ),
49+ MockResponse::make ($ singlePageResponse ),
50+ MockResponse::make ($ singlePageResponse ),
51+ MockResponse::make ($ singlePageResponse ),
52+ ]));
53+
54+ $ request = new SuperheroPagedRequest ;
55+ $ lazyCollection = $ connector ->paginate ($ request )->collect ();
56+
57+ $ first = $ lazyCollection ->collect ();
58+ expect ($ first )->toBeInstanceOf (Collection::class);
59+ expect ($ first ->pluck ('id ' )->all ())->toBe ([1 , 2 ]);
60+
61+ $ lazyCollection ->collect ();
62+ $ lazyCollection ->collect ();
63+ $ lazyCollection ->collect ();
64+ $ lazyCollection ->collect ();
65+
66+ $ again = $ lazyCollection ->collect ();
67+ expect ($ again ->pluck ('id ' )->all ())->toBe ([1 , 2 ]);
68+ });
0 commit comments