api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.43k stars 866 forks source link

Update ApiTestCase to be more consistent with WebTestCase #4242

Closed vincentchalamon closed 3 years ago

vincentchalamon commented 3 years ago

The Symfony WebTestCase client uses http://localhost base_uri, but the ApiTestCase uses http://example.com base_uri. In the API Platform distribution, the .env.test file allows the TRUSTED_HOSTS as following, which cannot work with the WebTestCase:

TRUSTED_HOSTS=^example.com$

Both system are different (ApiTestCase uses the http-client, but the WebTestCase uses the BrowserKit), so it's not possible to rely on the WebTestCase configuration.

I propose to have the same configuration, using http://localhost everywhere. This would be a simple change (but a BC break): updating the ApiPlatform\Core\Bridge\Symfony\Bundle\Test::API_OPTIONS_DEFAULTS constant as following:

public const API_OPTIONS_DEFAULTS = [
    // ...
    'base_uri' => 'http://localhost',
];

WDYT @api-platform/core-team?

dunglas commented 3 years ago

LGTM