Skip to content

[RFC] Easy external HTTP functional testing #50830

@ro0NL

Description

@ro0NL

Description

Hi,

Symfony has infrastructure to start a test HTTP server process. With #50814 it can now specify your working directory.

It would be nice if all configured HTTP clients are proxied/routed to this test server 'when at test env' (when@test), thus without changing any request URL or so.

We'd ensure no external traffic occurs by default, unless a client opts-out for reasons. I recently discovered we fetch some external Soap WSDLs lazily (if not cached).

Mocking the endpoint should be effortless: match request => provide response, be done. This can now be achieved by leveraging some designated working directory (tests/Fixtures/Http/), to be fed to TestHttpServer::start(), to be triggered by FrameworkBundle::boot() or so.

In practice it would look like:

when@test:
  http_test_server:
    enabled: true
    port: 1337
    excluded_clients: []
    working_dir: 'tests/Fixtures/Http'

(eg. to be provided in at the recipe level)

The remaining question would be how we arrange tests/Fixtures/Http and write actual fixtures. Perhaps we can benefit from existing response classes to provide a mock.

# tests/Fixtures/Http/domain.com.php

return fn(Request $r): Response {
};

Thoughts?

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureHttpClientRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions