HttpMock extension and module for Codeception.
Switch branches/tags
Clone or download
mcustiel Merge pull request #6 from gdscei/patch-1
Fix spelling Stopping http mock server
Latest commit 224058f Apr 25, 2017


This Codeception Extension allows developers and testers to use HttpMock to mock external services when running codeception tests.

codeception-http-mock runs an instance of http-mock before your tests run so they can mock external services. After the tests are finished it will close the connection and turn http-mock off.

See also


http-mock is a nice application but it is very simple and lacks a lot of functionality. If you need a more complete application to mock and stub remote services, please give Phiremock a try. Phiremock also has a nice codeception extension.



This project is published in packagist, so you just need to add it as a dependency in your composer.json:

    "require": {
        // ...
        "mcustiel/codeception-http-mock": "*"

If you want to access directly to this repo, adding this to your composer.json should be enough:

    "repositories": [
            "type": "vcs",
            "url": ""
    "require": {
        "mcustiel/codeception-http-mock": "dev-master"

Or just download the release and include it in your path.

Configuration Example


# codeception.yml
        - Codeception\Extension\HttpMock
            port: 18080 # defaults to http-mock default port
            host: # defaults to http-mock default host


# acceptance.yml
        - HttpMock

How to use

Prepare your application

First of all, configure your application so when it is being tested it will replace its external services with http-mock. For instance, if you make some requests to a REST service located under, replace that url in configuration with the host yoy set up in http-mock extension configuration.

Write your tests

// YourCest.php
class YourCest extends \Codeception\TestCase\Test
    // tests
    public function tryToTest(\AcceptanceTester $I)
                ->body('mocked body')
        $response = file_get_contents('http://localhost:28080/foo');
        $I->assertEquals('mocked body', $response);