@@ -165,11 +165,23 @@ public function testRequestWithDefaultHeaders(): void
165165 $ this ->requestFactoryMock ->expects ($ this ->once ())->method ('createRequest ' )->with ('POST ' , 'https://example.com/ ' )->willReturn ($ requestMock );
166166 $ this ->streamFactoryMock ->expects ($ this ->once ())->method ('createStream ' )->with ('Hi Doc! ' )->willReturn ($ requestStreamMock );
167167 $ requestMock ->expects ($ this ->once ())->method ('withBody ' )->with ($ requestStreamMock )->willReturn ($ requestMock );
168- $ requestMock ->expects ($ this ->exactly (3 ))->method ('withHeader ' )->withConsecutive (
169- ['X-A-Custom-Header ' , 'Foo ' ],
170- ['X-Another-Custom-Header ' , 'Bar ' ],
171- ['Content-Type ' , 'application/xml ' ]
172- )->willReturn ($ requestMock );
168+ $ matcher = $ this ->exactly (3 );
169+ $ requestMock ->expects ($ matcher )->method ('withHeader ' )->willReturnCallback (function (...$ parameters ) use ($ matcher , $ requestMock ) {
170+ if ($ matcher ->numberOfInvocations () === 1 ) {
171+ $ this ->assertSame ('X-A-Custom-Header ' , $ parameters [0 ]);
172+ $ this ->assertSame ('Foo ' , $ parameters [1 ]);
173+ }
174+ if ($ matcher ->numberOfInvocations () === 2 ) {
175+ $ this ->assertSame ('X-Another-Custom-Header ' , $ parameters [0 ]);
176+ $ this ->assertSame ('Bar ' , $ parameters [1 ]);
177+ }
178+ if ($ matcher ->numberOfInvocations () === 3 ) {
179+ $ this ->assertSame ('Content-Type ' , $ parameters [0 ]);
180+ $ this ->assertSame ('application/xml ' , $ parameters [1 ]);
181+ }
182+
183+ return $ requestMock ;
184+ });
173185 $ this ->httpClientMock ->expects ($ this ->once ())->method ('sendRequest ' )->with ($ requestMock )->willReturn ($ responseMock );
174186 $ responseMock ->expects ($ this ->exactly (2 ))->method ('getStatusCode ' )->willReturn (200 );
175187 $ responseMock ->expects ($ this ->once ())->method ('getHeader ' )->with ('Set-Cookie ' )->willReturn (['JSESSIONID=MartyMcFlySession ' ]);
@@ -199,7 +211,7 @@ public function testRequestWithClientException(): void
199211 }
200212
201213 /** @return iterable<string,array<int>> */
202- public function provideBadResponseCodes (): iterable
214+ public static function provideBadResponseCodes (): iterable
203215 {
204216 foreach (range (100 , 199 ) as $ badCode ) {
205217 yield 'HTTP code ' .$ badCode => [$ badCode ];
0 commit comments