http-server icon indicating copy to clipboard operation
http-server copied to clipboard

RFC: Add start() and stop() methods to HttpServer interface (v3+)

Open cspray opened this issue 3 years ago • 2 comments

I'm digging into the 3.0 beta and from a testing perspective I appreciate the HttpServer interface. It allows to more easily write unit tests in addition to integration tests. However, this interface does not include methods to start and stop the server, limiting its usefulness from a testing perspective.

Are the maintainers open to including the existing start() and stop() methods on the SocketHttpServer in the HttpServer interface?

cspray avatar Aug 13 '22 23:08 cspray

There's been a reason why we haven't added them to the interface. I guess because these methods should only be called by code that "owns" the HTTP server instance, not by code that gets some HttpServer instance injected.

@trowski What's your opinion on this?

kelunik avatar Aug 15 '22 20:08 kelunik

@kelunik FWIW the code that has the HttpServer injected is also the code that "owns" the instance. I'm wrapping some other events, route autowiring, and middleware setup before the server itself actually starts. In effect, I want you to be able to bootstrap a Container, get my Application class that wraps all that stuff, and then call $app->start().

cspray avatar Aug 15 '22 21:08 cspray

good idea

layerkugou avatar Dec 11 '22 07:12 layerkugou

Closed via https://github.com/amphp/http-server/commit/0c2b6865b95cda1688b5271413cfd2bc40f1e27b.

trowski avatar Dec 20 '22 04:12 trowski