diff --git a/tests/Feature/RequestsOptimizationTest.php b/tests/Feature/RequestsOptimizationTest.php index 6c8f2f9..b7d0832 100644 --- a/tests/Feature/RequestsOptimizationTest.php +++ b/tests/Feature/RequestsOptimizationTest.php @@ -10,7 +10,6 @@ ->middleware('log', Middleware::tap(fn() => $log->push('before'), fn() => $log->push('after'))) ->onRequest(fn() => $log->push('onRequest')) ->onResponse(fn() => $log->push('onResponse')) - ->sync() ->totalPages('meta.total_pages') ->collect('data.*'); @@ -49,3 +48,22 @@ expect($log)->sequence('before', 'after', 'onError'); }); + +it('sends HTTP requests asynchronously', function () { + $log = collect(); + + $lazyCollection = LazyJsonPages::from('https://example.com/api/v1/users') + ->onRequest(fn() => $log->push('sending')) + ->onResponse(fn() => $log->push('sent')) + ->async(3) + ->totalPages('meta.total_pages') + ->collect('data.*'); + + expect($lazyCollection)->toLoadItemsViaRequests([ + 'https://example.com/api/v1/users' => 'pagination/page1.json', + 'https://example.com/api/v1/users?page=2' => 'pagination/page2.json', + 'https://example.com/api/v1/users?page=3' => 'pagination/page3.json', + ]); + + expect($log)->sequence('sending', 'sent', 'sending', 'sending', 'sent', 'sent'); +});