2017 © Pedro Peláez
 

project phiremock-codeception-extension

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

image

phiremock/phiremock-codeception-extension

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  • Friday, April 13, 2018
  • by stexaz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 22 Versions
  • 0 % Grown

The README.md

phiremock-codeception-extension

Codeception extension and module to make working with Phiremock even easier. It allows to start a Phiremock server specifically for the acceptance tests to run or to connect to an already running Phiremock server., (*1)

Latest Stable Version Build Status Scrutinizer Code Quality Monthly Downloads, (*2)

Installation

Composer:

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

    "require-dev": {
        "mcustiel/phiremock-codeception-extension": "*"
    },
    "minimum-stability": "dev"

NOTE Phiremock uses a dev-master version of react/http to work. Because of this, until reactphp guys tag a new version you will need to set your project's minimum stability to dev., (*4)

How to use

Extension

The extension provides an easy way to start a Phiremock server with configured host, port, debug mode and logs path., (*5)

Configuration

In codeception.yml you will need to enable Phiremock extension and configure it in a proper way:, (*6)

extensions:
    enabled:
        - \Codeception\Extension\Phiremock
    config:
        \Codeception\Extension\Phiremock:
            listen: 127.0.0.1:18080 # defaults to 0.0.0.0:8086
            bin_path: ../vendor/bin # defaults to codeception_dir/../vendor/bin 
            logs_path: /var/log/my_app/tests/logs # defaults to codeception's tests output dir
            debug: true # defaults to false
            startDelay: 1 # default to 0
            expectations_path: /my/expectations/path

Note: Since Codeception version 2.2.7, extensions configuration can be added directly in the suite configuration file. That will avoid phiremock to be started for every suite., (*7)

Phiremock uses annotations internally. To be able to run the extension, the annotations autoloader must be activated. To do this, you must add the next lines in the bootstrap file where you include your composer autoloader:, (*8)

$loader = require APP_ROOT . '/vendor/autoload.php';
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']);

Parameters

  • listen: Specifies the interface and port where phiremock must listen for requests
  • bin_path: Path where Phiremock "binary" is located
  • logs_path: Path where to write the output
  • debug: Where to write debug data to log files
  • startDelay: Time to wait after Phiremock was started to start running the tests (used to give time to Phiremock to boot)
  • expectations_path: Specifies a directory to search for json files defining expectations to load by default.

Module

The module allows you to connect to a Phiremock server and to interact with it in a semantic way through the codeception actor in your tests., (*9)

Configuration

You need to enable Phiremock module in your suite's configuration file:, (*10)

modules:
    enabled:
        - Phiremock:
            host: 127.0.0.1
            port: 18080
            resetBeforeEachTest: false # if set to true, executes `$I->haveACleanSetupInRemoteService` before each test.

Use

The module provides the following handy methods to communicate with Phiremock server:, (*11)

expectARequestToRemoteServiceWithAResponse

Allows you to setup an expectation in Phiremock, specifying the expected request and the response the server should give for it:, (*12)

    $I->expectARequestToRemoteServiceWithAResponse(
        Phiremock::on(
            A::getRequest()->andUrl(Is::equalTo('/some/url'))
        )->then(
            Respond::withStatusCode(203)->andBody('I am a response')
        )
    );

haveACleanSetupInRemoteService

Cleans the server of all configured expectations, scenarios and requests history, and reloads expectation files., (*13)

    $I->haveACleanSetupInRemoteService();

dontExpectRequestsInRemoteService

Cleans all previously configured expectations and requests history., (*14)

    $I->dontExpectRequestsInRemoteService();

haveCleanScenariosInRemoteService

Cleans the state of all scenarios (sets all of them to inital state)., (*15)

    $I->haveCleanScenariosInRemoteService();

seeRemoteServiceReceived

Allows you to verify that the server received a request a given amount of times. This request could or not be previously set up as an expectation., (*16)

    $I->seeRemoteServiceReceived(1, A::getRequest()->andUrl(Is::equalTo('/some/url')));

didNotReceiveRequestsInRemoteService

Resets the requests counter for the verifier in Phiremock., (*17)

    $I->didNotReceiveRequestsInRemoteService();

Use case

Yii2-Curl

Yii2-Curl uses phiremock-codeception-extension for functional testing. You can see the configuration for the extension and the module, as well as how Phiremock is configured in the tests., (*18)

The Versions

13/04 2018

dev-master

9999999-dev

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0-or-later

The Requires

 

mock extension server http tests external codeception acceptance phiremock

13/04 2018

v1.5.5

1.5.5.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0-or-later

The Requires

 

mock extension server http tests external codeception acceptance phiremock

13/04 2018

v1.5.4

1.5.4.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0-or-later

The Requires

 

mock extension server http tests external codeception acceptance phiremock

24/01 2018

v1.5.3

1.5.3.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

22/01 2018

v1.5.2

1.5.2.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

26/12 2017

v1.5.1

1.5.1.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

26/12 2017

dev-issue/21

dev-issue/21

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

12/10 2017

v1.5.0

1.5.0.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

24/09 2017

v1.4.1

1.4.1.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

19/09 2017

v1.4.0

1.4.0.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

15/09 2017

v1.3.2

1.3.2.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

20/07 2017

v1.3.1

1.3.1.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

13/06 2017

v1.3.0

1.3.0.0

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

07/06 2017

dev-develop

dev-develop

Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.

  Sources   Download

GPL-3.0+

The Requires

 

mock extension server http tests external codeception acceptance phiremock

09/03 2017

v1.2.4

1.2.4.0

  Sources   Download

The Requires

 

mock extension server http tests external codeception acceptance phiremock

04/03 2017

v1.2.3

1.2.3.0

  Sources   Download

The Requires

 

mock extension server http tests external codeception acceptance phiremock

15/12 2016

v1.2.2

1.2.2.0

  Sources   Download

The Requires

 

mock extension server http tests external codeception acceptance phiremock

04/07 2016

v1.2.1

1.2.1.0

  Sources   Download

The Requires

 

mock extension server http tests external codeception acceptance phiremock

04/07 2016

v1.2.0

1.2.0.0

  Sources   Download

The Requires

 

mock extension server http tests external codeception acceptance phiremock

07/04 2016

v1.1.0

1.1.0.0

  Sources   Download

The Requires

 

mock extension server http tests external codeception acceptance phiremock

05/04 2016

v1.0.1

1.0.1.0

  Sources   Download

The Requires

 

mock extension server http tests external codeception acceptance phiremock

16/03 2016

v1.0.0

1.0.0.0

  Sources   Download

The Requires

 

mock extension server http tests external codeception acceptance phiremock