1818namespace LINE \Tests \Clients \MessagingApi \Api ;
1919
2020use GuzzleHttp \ClientInterface ;
21+ use GuzzleHttp \Psr7 \Query ;
2122use GuzzleHttp \Psr7 \Request ;
2223use GuzzleHttp \Psr7 \Response ;
2324use LINE \Clients \MessagingApi \Api \MessagingApiApi ;
3031use LINE \Clients \MessagingApi \Model \MessagingApiPagerCouponListResponse ;
3132use Mockery ;
3233use PHPUnit \Framework \TestCase ;
34+ use Psr \Http \Message \UriInterface ;
3335
3436class MessagingApiApiTest extends TestCase
3537{
@@ -38,6 +40,25 @@ protected function setUp(): void
3840 parent ::setUp ();
3941 }
4042
43+ private function assertQueryEquals (array $ expected , UriInterface $ uri ): void
44+ {
45+ $ actual = Query::parse ($ uri ->getQuery ());
46+
47+ $ normalize = function (array &$ arr ): void {
48+ foreach ($ arr as &$ v ) {
49+ if (is_array ($ v )) {
50+ sort ($ v );
51+ }
52+ }
53+ ksort ($ arr );
54+ };
55+
56+ $ normalize ($ expected );
57+ $ normalize ($ actual );
58+
59+ $ this ->assertSame ($ expected , $ actual , 'Query parameters mismatch ' );
60+ }
61+
4162 public function testGetFollowers (): void
4263 {
4364 $ client = Mockery::mock (ClientInterface::class);
@@ -276,6 +297,11 @@ public function testListCoupon(): void
276297 $ start = 'startToken ' ;
277298 $ limit = 10 ;
278299 $ contentType = 'application/json ' ;
300+ $ expectedQuery = [
301+ 'status ' => $ status ,
302+ 'start ' => $ start ,
303+ 'limit ' => (string )$ limit ,
304+ ];
279305 $ expectedRequestBody = <<<JSON
280306 {
281307 "status": ["RUNNING", "CLOSED"],
@@ -296,14 +322,11 @@ public function testListCoupon(): void
296322 $ client = Mockery::mock (ClientInterface::class);
297323 $ client ->shouldReceive ('send ' )
298324 ->with (
299- Mockery::on (function (Request $ request ) use ($ status , $ start , $ limit , $ contentType ) {
325+ Mockery::on (function (Request $ request ) use ($ status , $ start , $ limit , $ contentType, $ expectedQuery ) {
300326 $ this ->assertEquals ('GET ' , $ request ->getMethod ());
301327 $ this ->assertStringContainsString ('https://api.line.me/v2/bot/coupon? ' , (string )$ request ->getUri ());
302328 $ this ->assertEquals ($ contentType , $ request ->getHeaderLine ('Content-Type ' ));
303- $ this ->assertStringContainsString ('status=RUNNING ' , (string )$ request ->getUri ()->getQuery ());
304- $ this ->assertStringContainsString ('status=CLOSED ' , (string )$ request ->getUri ()->getQuery ());
305- $ this ->assertStringContainsString ('start=startToken ' , (string )$ request ->getUri ()->getQuery ());
306- $ this ->assertStringContainsString ('limit=10 ' , (string )$ request ->getUri ()->getQuery ());
329+ $ this ->assertQueryEquals ($ expectedQuery , $ request ->getUri ());
307330 return true ;
308331 }),
309332 []
0 commit comments