{"id":43422330,"url":"https://github.com/mcustiel/phiremock-codeception-module","last_synced_at":"2026-02-02T18:54:48.414Z","repository":{"id":34238612,"uuid":"172028216","full_name":"mcustiel/phiremock-codeception-module","owner":"mcustiel","description":"Module to mock http request to external services during acceptance testing with Codeception. Allows you to connect to one or more Phiremock Servers and to interact with them in a semantic way.","archived":false,"fork":false,"pushed_at":"2022-07-29T18:39:54.000Z","size":1149,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-14T21:42:14.194Z","etag":null,"topics":["automation","codeception","php","testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcustiel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-22T08:40:53.000Z","updated_at":"2022-05-14T11:11:02.000Z","dependencies_parsed_at":"2022-08-27T00:20:31.119Z","dependency_job_id":null,"html_url":"https://github.com/mcustiel/phiremock-codeception-module","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/mcustiel/phiremock-codeception-module","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphiremock-codeception-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphiremock-codeception-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphiremock-codeception-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphiremock-codeception-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcustiel","download_url":"https://codeload.github.com/mcustiel/phiremock-codeception-module/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcustiel%2Fphiremock-codeception-module/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29017938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T18:51:31.335Z","status":"ssl_error","status_checked_at":"2026-02-02T18:49:20.777Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","codeception","php","testing"],"created_at":"2026-02-02T18:54:48.312Z","updated_at":"2026-02-02T18:54:48.404Z","avatar_url":"https://github.com/mcustiel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phiremock-codeception-module\n\nThis codeception 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.\n\n[![Packagist Version](https://img.shields.io/packagist/v/mcustiel/phiremock-codeception-module)](https://packagist.org/packages/mcustiel/phiremock-codeception-module)\n[![Build Status](https://scrutinizer-ci.com/g/mcustiel/phiremock-codeception-module/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mcustiel/phiremock-codeception-module/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mcustiel/phiremock-codeception-module/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mcustiel/phiremock-codeception-module/?branch=master)\n[![Packagist Downloads](https://img.shields.io/packagist/dm/mcustiel/phiremock-codeception-module)](https://packagist.org/packages/mcustiel/phiremock-codeception-module)\n\n## Installation\n\n### Composer:\n\n```json\n    \"require-dev\": {\n        \"mcustiel/phiremock-codeception-module\": \"^1.0\",\n        \"guzzlehttp/guzzle\": \"^6.0\"\n    }\n```\n\n## Configuration\nYou need to enable Phiremock module in your suite's configuration file:\n\n```yaml\nmodules:\n    enabled:\n        - Phiremock:\n            host: phiremock-myhost.dev # Defaults to localhost\n            port: 18080 # Defaults to 8086\n            reset_before_each_test: false # if set to true, executes `$I-\u003ehaveACleanSetupInRemoteService` before each test. Defaults to false\n            expectations_path: /path/to/my/expectation/json/files # Defaults to codeception_dir/_data/phiremock-expectations\n            client_factory: \\My\\ClientFactory # Defaults to 'default'\n            secure: true # Default: false\n            extra_connections:  [] # Default: empty array\n```\n\n### Options\n\n#### host\nSpecifies the host where phiremock-server is listening for requests.\n\n**Default:** localhost\n\n#### port\nSpecifies the port where phiremock-server is listening for requests.\n\n**Default:** 8086\n\n#### reset_before_each_test\nDetermines whether or not phiremock-server must be reset before each test.\n\n**Default:** false\n\n#### expectations_path\nSpecifies the path where expectation json files are located. The files can then be referenced using annotations and will be loaded automatically.\n\n**Default:** codeception_dir/_data/phiremock-expectations\n\n#### secure\nA boolean specifying if the connection is secure or not. If it's secure, the request is done through https, otherwise it's done through http. \n\n**Default:** false. The requests to phiremock-client are done through http.\n\n#### extra_connections\nAn list of objects specifying the parameters to request other phiremock-servers. \nThis is useful if you want to have 2 phiremock instances, one listening for http connections, and the other listening for https connections.\n\n**Default:** An empty list, meaning that no other phiremock servers are requested.\n\n##### Example\n\n```yaml\nmodules:\n    enabled:\n        - Phiremock:\n            host: phiremock-myhost.dev\n            port: 18080 \n            secure: false \n            extra_connections: \n                secure-host:\n                    host: phiremock-myhost.dev\n                    port: 18081 \n                    secure: true\n```\nThen in the code you can use each connection by name as follows:\n\n```php\n\u003c?php\n$I-\u003etakeConnection('secure-host')-\u003ereset();\n```\n\nThe default connection is called 'default' and you can also take it:\n\n```php\n$I-\u003etakeConnection('default')-\u003ereset();\n```\n\n#### client_factory\nSpecifies the fully qualified class name of a class which overrides default phiremock-client factory. This is useful if you want to avoid using Guzzle HttpClient v6 (the one supported by default in phiremock-client).\n\n**Default:** default\n\n##### Example\n\n```json\n\"require-dev\": {\n    \"mcustiel/phiremock-codeception-module\": \"v1.0\",\n    \"guzzlehttp/guzzle\": \"^7.0\"\n```\n\nThe you can create a factory as follows and provide the fully qualified class name in the module configuration:\n\n```php\n\u003c?php\nnamespace My\\Namespace;\n\nuse Mcustiel\\Phiremock\\Client\\Factory;\nuse GuzzleHttp;\nuse Psr\\Http\\Client\\ClientInterface;\n\nclass FactoryWithGuzzle7 extends Factory\n{\n    public function createRemoteConnection(): ClientInterface\n    {\n        return new GuzzleHttp\\Client(['allow_redirects' =\u003e false]);\n    }\n}\n```\nAny http client implementing psr18 can be provided.\n\n## Usage\nThe module provides the following handy methods to communicate with Phiremock server:\n\n### expectARequestToRemoteServiceWithAResponse\nAllows you to setup an expectation in Phiremock, specifying the expected request and the response the server should give for it:\n\n```php\n    $I-\u003eexpectARequestToRemoteServiceWithAResponse(\n        on(getRequest()-\u003eandUrl(isEqualTo('/some/url')))\n            -\u003ethen(respond(203)-\u003eandBody('I am a response'))\n    );\n```\n\n### haveACleanSetupInRemoteService\nCleans the server of all configured expectations, scenarios and requests history, and reloads expectation files if they are present.\n\n```php\n    $I-\u003ehaveACleanSetupInRemoteService();\n```\n\n### dontExpectRequestsInRemoteService\nCleans all previously configured expectations and requests history.\n\n```php\n    $I-\u003edontExpectRequestsInRemoteService();\n```\n\n### haveCleanScenariosInRemoteService\nCleans the state of all scenarios (sets all of them to inital state).\n\n```php\n    $I-\u003ehaveCleanScenariosInRemoteService();\n```\n\n### seeRemoteServiceReceived\nAllows 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.\n\n```php\n    $I-\u003eseeRemoteServiceReceived(1, getRequest()-\u003eandUrl(isEqualTo('/some/url')));\n```\n\n### didNotReceiveRequestsInRemoteService\nResets the requests counter for the verifier in Phiremock. \n\n```php\n    $I-\u003edidNotReceiveRequestsInRemoteService();\n```\n\n### grabRequestsMadeToRemoteService\nRetrieves all the requests received by Phiremock server matching the one specified.\n\n```php\n    $I-\u003egrabRequestsMadeToRemoteService(getRequest()-\u003eandUrl(isEqualTo('/some/url')));\n```\n\n### setScenarioState\nForces the state of a scenario.\n\n```php\n    $I-\u003esetScenarioState('scenarioName', 'newScenarioState');\n```\n\n### takeConnection\nAllows to use several connections to different phiremock servers.\n\n```php\n    $I-\u003etakeConnection('connectionName');\n```\n\n### @expectation Annotations\n\nAllows you to set up an expectation via a json file\n\n```php\n    /**\n     * @expectation(\"get_client_timeout\")\n     */\n    public function test(FunctionalTester $I)\n    {\n        ...\n    }\n```\n\nThat will load by default the file at `tests/_data/phiremock-expectations/get_client_timeout.json`. The path where to place the expectations is configurable.\n\nYou may use expectations placed in subdirectories\n\n```php\n    /**\n     * @expectation(\"edge_cases/get_client_timeout\")\n     */\n    public function test(FunctionalTester $I)\n    {\n        ...\n    }\n```\n\nMultiple annotation formats are accepted\n\n```\n     * @expectation get_client_timeout\n     * @expectation get_client_timeout.json\n     * @expectation(get_client_timeout.json)\n     * @expectation(get_client_timeout)\n     * @expectation(\"get_client_timeout\")\n```\n\n## See also:\n\n* Phiremock Client: https://github.com/mcustiel/phiremock-client\n* Phiremock Codeception Extension: https://github.com/mcustiel/phiremock-codeception-extension\n* Examples in tests: https://github.com/mcustiel/phiremock-codeception-module/tree/master/tests/acceptance\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcustiel%2Fphiremock-codeception-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcustiel%2Fphiremock-codeception-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcustiel%2Fphiremock-codeception-module/lists"}