Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Open
Description
Symfony version(s) affected
5.x+
Description
Setting'redirect_url' => 'http://www.mysite.test/final/'
as part of the$info
array in a MockResponse results in:
Symfony\Component\HttpClient\Exception\TransportException] The response factory iterator passed to MockHttpClient is empty.
$responses = [newMockResponse('',['http_code' =>301,'redirect_url' =>'http://www.mysite.test/final/','response_headers' => ['HTTP/2 301','location: http://www.mysite.test/final/',],]),];
It seems to be forceinfo['redirect_url']
to nullhere.
How to reproduce
I am using a decorator in my code, but this PHPUnit test should fail regardless:
$responses = [newMockResponse('',['http_code' =>301,'redirect_url' =>'http://www.mysite.test/final/','response_headers' => ['HTTP/2 301','location: http://www.mysite.test/final/',],]),];$this->http_client->setResponseFactory($responses );try {$response =$this->client->request('GET','/redirect/' );$response->getHeaders();$this->fail('A RedirectionException should have been thrown' );}catch (RedirectionExceptionInterface$e ) {$info =$e->getResponse()->getInfo();$this->assertSame('http://www.mysite.test/final/',$info['redirect_url'] );}
Possible Solution
Either allow us to set$info['redirect_url']
on MockResponse, or it should populate it automatically based on the response_headers?
Additional Context
No response