Download the PHP package warmans/http-testcase without Composer
On this page you can find all versions of the php package warmans/http-testcase. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download warmans/http-testcase
More information about warmans/http-testcase
Files in warmans/http-testcase
Package http-testcase
Short Description PHPUnit testcase for e2e testing libraries that talk to web services.
License MIT
Informations about the package http-testcase
HTTP Test Case
PHPUnit test case to assist in behaviour/integration testing HTTP clients libraries. The testcase can start a http server and enqueue a set of responses (a session) which can are replayed for HTTP requests to the server. This is roughly similar to the testcase provided by Guzzle but without any external (NPM) dependencies.
The HTTP server is written in golang. The source is available here: https://github.com/warmans/http-playback
Test Case API
The testcase exposes the following methods:
startServer($port)
Start a server on the given port and return a Server instance.
getServer($port)
Get a Server instance for a server previously started using startServer().
stopServers()
Tell all running servers to exit. Note that shutdown functions are automatically registered for Server instances so omitting a tearDown call to stopServers should not leave servers running.
Server API
Interactions with http playback servers are simplified using the Server instance which is returned from calls to
startServer() and getServer()
start()
Start the server (generally only called by HttpTestCase::startServer()).
stop()
Stop the server (generally only called by HttpTestCase::startServer()).
enqueue($session, $status = 200, $body = "", $headers = array(), $wait = 0)
Add a response to a HTTP session. A session is just a named list of responses held within the server. Using named sessions allows the tester to simulate different endpoints without requiring exact paths. If you don't care about segregated response queues for different pages just always use the same session name.
getReplayUri($session, $path)
If you've enqueued some responses and just want the full playback URI you can use this method. e.g.
getOutput()
Get the logfile output from the server as a string. Note that a server log is created in sys_get_temp_dir().'/http-testcase.log'
isRunning()
Check if the server is currently running.
Examples
A test case will look like this (this one can be run from the project if dev dependencies are installed root using
./vendor/bin/phpunit example)