1818use PHPUnit \Framework \TestCase ;
1919use Psr \Http \Client \ClientExceptionInterface ;
2020use Psr \Http \Message \{RequestInterface , ResponseInterface };
21+
2122use function chillerlan \HTTP \Psr7 \build_http_query ;
23+ use function array_column , implode , in_array , ksort ;
2224
2325class CurlMultiClientTest extends TestCase{
2426
@@ -40,15 +42,18 @@ protected function setUp():void{
4042 protected function getRequests ():array {
4143
4244 $ ids = [
43- [1 ,2 , 6 , 11 ,15 ,23 ,24 ,56 ,57 ,58 ,59 ,60 ,61 ,62 ,63 ,64 ,68 ,69 ,70 ,71 ,72 ,73 ,74 ,75 ,76 ],
44- [77 ,78 ,79 ,80 ,81 ,82 ,83 ,84 ,85 ,86 ,87 ,88 ,89 ,90 ,91 ,92 ,93 ,94 ,95 ,96 ,97 ,98 ,99 ,100 ,101 ],
45+ [1 , 2 , 6 , 11 , 15 , 23 , 24 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 ],
46+ [77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 ],
4547 ];
4648
4749 $ requests = [];
4850
4951 foreach ($ ids as $ chunk ){
5052 foreach (['de ' , 'en ' , 'es ' , 'fr ' , 'zh ' ] as $ lang ){
51- $ requests [] = new Request (Request::METHOD_GET , 'https://api.guildwars2.com/v2/items? ' .build_http_query (['lang ' => $ lang , 'ids ' => implode (', ' , $ chunk )]));
53+ $ requests [] = new Request (
54+ Request::METHOD_GET ,
55+ 'https://api.guildwars2.com/v2/items? ' .build_http_query (['lang ' => $ lang , 'ids ' => implode (', ' , $ chunk )])
56+ );
5257 }
5358 }
5459
@@ -63,7 +68,7 @@ protected function getTestResponseHandler():MultiResponseHandlerInterface{
6368
6469 public function handleResponse (ResponseInterface $ response , RequestInterface $ request , int $ id , array $ curl_info ):?RequestInterface {
6570
66- if (\ in_array ($ response ->getStatusCode (), [200 , 206 ], true )){
71+ if (in_array ($ response ->getStatusCode (), [200 , 206 ], true )){
6772 $ this ->responses [$ id ]['lang ' ] = $ response ->getHeaderLine ('content-language ' );
6873 // ok, so the headers are empty on travis???
6974# \var_dump($response->getHeaders());
@@ -76,7 +81,7 @@ public function handleResponse(ResponseInterface $response, RequestInterface $re
7681 }
7782
7883 public function getResponses ():array {
79- \ ksort ($ this ->responses );
84+ ksort ($ this ->responses );
8085
8186 return $ this ->responses ;
8287 }
@@ -105,7 +110,7 @@ public function testMultiRequest(){
105110
106111 // the responses are ordered
107112 // i'll probably never know why this fails on travis
108- # $this->assertSame(['de','en','es','fr','zh','de','en','es','fr','zh'], \ array_column($responses, 'lang'));
113+ # $this->assertSame(['de', 'en', 'es', 'fr', 'zh', 'de', 'en', 'es', 'fr', 'zh'], array_column($responses, 'lang'));
109114
110115 // cover the destructor
111116 unset($ this ->http );
@@ -119,7 +124,6 @@ public function testEmptyStackException(){
119124 $ this ->http ->process ();
120125 }
121126
122-
123127 public function testNoResponseHandlerException (){
124128 $ this ->expectException (ClientExceptionInterface::class);
125129 $ this ->expectExceptionMessage ('no response handler set ' );
0 commit comments