Cannot make request internally to my symfony application served on localhost:8000

29 views Asked by At

I have Symfony application running through docker.

It served on http://localhost:8000/. I'm trying to test my API routes, for example to check if they are available when JWT provided or not, check status code and so on.

Here is sample code that I have:

class SampleTest extends TestCase
{
    private $client;   
    
    public function setUp(): void
    {
        $this->client = (new HttpClient())::create();
    }
    
    public function testSampleTest(): void
    {
        $this->client->request('GET', 'http://localhost:8000/api/test-json');
    }
}

anyway I'm getting this of error:

Symfony\Component\HttpClient\Exception\TransportException: Couldn't connect to server for "http://localhost:8000/api/test-json".

As it's mentioned here Guzzle Cannot make GET request to the localhost (port: 80, 8000, 8080, etc ) it is impossible to make requests to localhost.

But how can I solve it when I have application in docker container? Is there any standard solution for such case in Symfony ecosystem?

0

There are 0 answers