Giter VIP home page Giter VIP logo

codeception-mountebank's Introduction

codeception-mountebank

Latest Version on Packagist Software License Quality Score Total Downloads

codeception-mountebank provides mountebank integration with Codeception. Module allows to:

  • Configure imposters required for tests run;
  • Use imposters as mocks and verify specific requests were made;
  • Save imposters after run for debugging purposes;

Module uses Juggler to interact with mountebank and it's possible to take complete control on mountebank in your custom helper classes or modules.

Note that only HTTP imposters are currently supported.

Install

Require module via Composer:

$ composer require meare/codeception-mountebank

Configuration

Module should be enabled and configured in suite configuration file

class_name: AcceptanceTester
modules:
    enabled:
        - Mountebank
    config:
        Mountebank:
            # mountebank host
            # Required
            host: 'localhost'

            # Port mountebank listens on
            # 2525 by default
            port: 2525

            # Imposters configuration
            # All previous imposters are deleted before the run
            imposters:

                # Imposter alias
                xyz:

                    # Path to imposter contract
                    # Required
                    contract: '_data/mountebank/xyz/stub.json'

                    # Set this property to save imposter contract after tests run
                    # Property value is path to save contract to
                    save: '_output/mountebank/xyz/stub.json'

                    # Set to true if imposter is used as mock
                    # Mock imposters are restored from original contract after each test
                    # Default: false
                    mock: true

Usage

Mock verification

mountebank should be started with --mock flag to use mocking

» mountebank docs on mocking

Imposters mock property should be set to true in suite configuration. It guarantees that imposter will be restored before each test. Restoring means deleting existing imposter from mountebank and posting contract from configuration. This is done to clean requests imposter recorded.

Module provides 3 methods to verify mock imposter:

seeImposterHasRequests($alias)

Asserts that there was at least 1 request recorded on imposter

seeImposterHasRequestsByCriteria($alias, $criteria)

Asserts that there was at least 1 request that satisfies criteria recorded on imposter.

If $criteria is array then request is considered matching if $criteria is subarray of request, e.g.:

$I->seeImposterHasRequestsByCriteria('xyz', [
  'method' => 'GET',
  'query' => [
    'account_id' => '7'
  ]
])
{
  "protocol": "http",
  "port": 4646,
  "numberOfRequests": 1,
  "name": "xyz",
  "requests": [
    {
      "requestFrom": "::ffff:127.0.0.1:57484",
      "method": "GET",
      "path": "/balance",
      "query": {
        "account_id": "7",
        "currency": "USD",
      },
      "headers": {
        "Host": "localhost",
        "Connection": "close"
      },
      "body": "",
      "timestamp": "2017-01-12T16:03:07.632Z"
    }
  ]
}

More complex criteria could be expressed as callback. Callback signature is:

/**
 * @var string $request decoded request object from contract JSON.
 *
 * @return bool Whether requests matches
 */
function(array $request) {}

Callback will be called for each request imposter has until true is returned.

seeImposterHasNoRequests($alias)

Asserts that there is no requests recorded on imposter.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

codeception-mountebank's People

Contributors

meare avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

codeception-mountebank's Issues

Run test through proxy server

I have problem to run codeception through proxy server.
I got error messages like this
DELETE http://mountebank:2525/imposters resulted in a 503 Service Unavailable.

I am newbie for mountebank. Need someone can help to fix this problem.
Actually It works without proxy, but I need to work on proxy environment.

Please help me :)

Version tag?

Can you tag a version for packagist? This helps with composer configurations in case of stable setting.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.