PHPackages                             warmans/http-testcase - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. warmans/http-testcase

ActiveLibrary[Testing &amp; Quality](/categories/testing)

warmans/http-testcase
=====================

PHPUnit testcase for e2e testing libraries that talk to web services.

0.0.6(11y ago)04131MITPHP

Since Feb 16Pushed 11y ago1 watchersCompare

[ Source](https://github.com/warmans/http-testcase)[ Packagist](https://packagist.org/packages/warmans/http-testcase)[ RSS](/packages/warmans-http-testcase/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

HTTP Test Case
==============

[](#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:

#### Test Case API

[](#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

[](#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.

```
$server->enqueue("foo", 200); //setup a session
$server->getReplayUri("foo", "/bar/baz"); // http://localhost:8080/p/foo/bar/baz - will return the configured response

```

**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

[](#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`)

```
    use HttpTestCase\HttpTestCase;

    class Test extends HttpTestCase
    {
        public static function setUpBeforeClass()
        {
            self::startServer('8081');
        }

        public static function tearDownAfterClass()
        {
            self::stopServers();
        }

        /**
         * Just send a HTTP GET request somewhere.
         */
        protected function sendGet($host)
        {
            $ch = curl_init($host);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            return curl_exec($ch);
        }

        /**
         * Enqueue and request a single response.
         */
        public function testHttpServerReturnsConfiguredResponse()
        {
            $server = self::getServer('8081');
            $server->enqueue(1, 200, 'bar');

            $this->assertEquals('bar', $this->sendGet('http://localhost:8081/p/1/'));
        }

        /**
         * Enqueue some responses then send some GET requests to the server and assert they were returned in the
         * expected order.
         */
        public function testHttpServerReturnsMultipleResponses()
        {
            $server = self::getServer('8081');
            $server->enqueue(1, 200, 'bar');
            $server->enqueue(1, 200, 'baz');
            $server->enqueue(1, 200, 'cat');

            $this->assertEquals('bar', $this->sendGet('http://localhost:8081/p/1/'));
            $this->assertEquals('baz', $this->sendGet('http://localhost:8081/p/1/'));
            $this->assertEquals('cat', $this->sendGet('http://localhost:8081/p/1/'));
        }

        /**
         * Enqueue 1000 responses then request them all.
         */
        public function testOneWayLoad()
        {
            $requests = 1000;

            //in
            $server = self::getServer('8081');
            for ($i = 0; $i < $requests; $i++) {
                $server->enqueue(1, 200, "foo", array());
            }

            //out
            for ($i = 0; $i < $requests; $i++) {
                if ('foo' !== ($res = $this->sendGet($server->getReplayUri(1)))) {
                    $this->fail('bad response: '.$res);
                }
            }
        }

        /**
         * Enqueue and request 1000 responses
         */
        public function testAlternatingLoad()
        {
            $requests = 1000;

            $server = self::getServer('8081');
            for ($i = 0; $i < $requests; $i++) {
                //in
                $server->enqueue(1, 200, "foo", array());
                //out
                if ('foo' !== ($res = $this->sendGet($server->getReplayUri(1)))) {
                    $this->fail('bad response: '.$res);
                }
            }
        }
    }
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

4108d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1299401?v=4)[SW](/maintainers/warmans)[@warmans](https://github.com/warmans)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/warmans-http-testcase/health.svg)

```
[![Health](https://phpackages.com/badges/warmans-http-testcase/health.svg)](https://phpackages.com/packages/warmans-http-testcase)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
