|
1 | 1 | # phiremock-codeception-extension |
2 | | -Codeception extension and module to make working with phiremock even easier. |
| 2 | +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. |
| 3 | + |
| 4 | +## Extension |
| 5 | +The extension provides an easy way to start a Phiremock server with configured host, port, debug mode and logs path. |
| 6 | + |
| 7 | +### Configuration |
| 8 | +In codeception.yml you will need to enable Phiremock extension and configure it in a proper way: |
| 9 | + |
| 10 | +```yaml |
| 11 | +extensions: |
| 12 | + enabled: |
| 13 | + - \Codeception\Extension\Phiremock |
| 14 | + config: |
| 15 | + \Codeception\Extension\Phiremock: |
| 16 | + listen: 127.0.0.1:18080 # defaults to 0.0.0.0:8086 |
| 17 | + bin_path: ../vendor/bin # defaults to codeception_dir/../vendor/bin |
| 18 | + logs_path: /var/log/my_app/tests/logs # defaults to codeception's tests output dir |
| 19 | + debug: true # defaults to false |
| 20 | +``` |
| 21 | +
|
| 22 | +## Module |
| 23 | +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. |
| 24 | +
|
| 25 | +### Configuration |
| 26 | +You need to enable Phiremock module in your suite's configuration file: |
| 27 | +
|
| 28 | +```yaml |
| 29 | +modules: |
| 30 | + enabled: |
| 31 | + - Phiremock: |
| 32 | + host: 127.0.0.1 |
| 33 | + port: 18080 |
| 34 | +``` |
| 35 | +
|
| 36 | +### Use |
| 37 | +The module provides the following handy methods to communicate with Phiremock server: |
| 38 | +
|
| 39 | +#### expectARequestToRemoteServiceWithAResponse |
| 40 | +Allows you to setup an expectation in Phiremock, specifying the expected request and the response the server should give for it: |
| 41 | +
|
| 42 | +```php |
| 43 | + $I->expectARequestToRemoteServiceWithAResponse( |
| 44 | + Phiremock::on( |
| 45 | + A::getRequest()->andUrl(Is::equalTo('/some/url')) |
| 46 | + )->then( |
| 47 | + Respond::withStatusCode(203)->andBody('I am a response') |
| 48 | + ) |
| 49 | + ); |
| 50 | +``` |
| 51 | + |
| 52 | +### haveACleanSetupInRemoteService |
| 53 | +Cleans the server of all configured expectations, scenarios and requests history. |
| 54 | + |
| 55 | +```php |
| 56 | + $I->haveACleanSetupInRemoteService(); |
| 57 | +``` |
| 58 | + |
| 59 | +### dontExpectRequestsInRemoteService |
| 60 | +Cleans all previously configured expectations and requests history. |
| 61 | + |
| 62 | +```php |
| 63 | + $I->dontExpectRequestsInRemoteService(); |
| 64 | +``` |
| 65 | + |
| 66 | +### haveCleanScenariosInRemoteService |
| 67 | +Cleans the state of all scenarios (sets all of them to inital state). |
| 68 | + |
| 69 | +```php |
| 70 | + $I->haveCleanScenariosInRemoteService(); |
| 71 | +``` |
| 72 | + |
| 73 | +### seeRemoteServiceReceived |
| 74 | +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. |
| 75 | + |
| 76 | +```php |
| 77 | + $I->seeRemoteServiceReceived(1, A::getRequest()->andUrl(Is::equalTo('/some/url'))); |
| 78 | +``` |
0 commit comments