{"id":19373676,"url":"https://github.com/neur0toxine/pock","last_synced_at":"2025-04-23T17:32:09.363Z","repository":{"id":57025742,"uuid":"367133810","full_name":"Neur0toxine/pock","owner":"Neur0toxine","description":"Easy to use PSR-18 compatible HTTP mocking library","archived":false,"fork":false,"pushed_at":"2023-10-03T09:46:41.000Z","size":185,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-17T10:40:43.897Z","etag":null,"topics":["api","dto","http","json","mock","network","pock","psr-17","psr-18","psr-7","serializer"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Neur0toxine.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-13T18:05:37.000Z","updated_at":"2023-04-21T18:38:11.000Z","dependencies_parsed_at":"2023-10-03T15:41:04.750Z","dependency_job_id":null,"html_url":"https://github.com/Neur0toxine/pock","commit_stats":{"total_commits":44,"total_committers":1,"mean_commits":44.0,"dds":0.0,"last_synced_commit":"eef38bf466d035a7d535347aafb25a8ea4ced6cd"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neur0toxine%2Fpock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neur0toxine%2Fpock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neur0toxine%2Fpock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neur0toxine%2Fpock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neur0toxine","download_url":"https://codeload.github.com/Neur0toxine/pock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250480585,"owners_count":21437575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["api","dto","http","json","mock","network","pock","psr-17","psr-18","psr-7","serializer"],"created_at":"2024-11-10T08:30:51.799Z","updated_at":"2025-04-23T17:32:09.314Z","avatar_url":"https://github.com/Neur0toxine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build Status](https://img.shields.io/github/actions/workflow/status/Neur0toxine/pock/tests.yml?branch=master\u0026style=flat-square)\n[![Coverage](https://img.shields.io/codecov/c/gh/Neur0toxine/pock/master.svg?logo=codecov\u0026logoColor=white\u0026style=flat-square)](https://codecov.io/gh/Neur0toxine/pock)\n[![Latest stable](https://img.shields.io/packagist/v/neur0toxine/pock.svg?style=flat-square)](https://packagist.org/packages/neur0toxine/pock)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/neur0toxine/pock.svg?logo=php\u0026logoColor=white\u0026style=flat-square)](https://packagist.org/packages/neur0toxine/pock)\n![License](https://img.shields.io/github/license/Neur0toxine/pock?style=flat-square)\n\n# pock\n\nEasy to use HTTP mocking solution, compatible with PSR-18 and HTTPlug.\n\nProject is still in its early development stage. API can change over time, but I'll try to not introduce breaking changes.\nYou can find autogenerated documentation [here](https://neur0toxine.github.io/pock/) or look at the examples. API for the mock building can be found\n[here](https://neur0toxine.github.io/pock/classes/Pock-PockBuilder.html) and API for the response building (returned from `PockBuilder::reply` call) \ncan be found [here](https://neur0toxine.github.io/pock/classes/Pock-PockResponseBuilder.html).\n\n# Examples\n\nMock JSON API route with Basic authorization, reply with JSON.\n\n```php\nuse Pock\\Enum\\RequestMethod;\nuse Pock\\Enum\\RequestScheme;\nuse Pock\\PockBuilder;\n\n$builder = new PockBuilder();\n$builder-\u003ematchMethod(RequestMethod::GET)\n    -\u003ematchScheme(RequestScheme::HTTPS)\n    -\u003ematchHost('example.com')\n    -\u003ematchPath('/api/v1/users')\n    -\u003ematchHeaders([\n        'Content-Type' =\u003e 'application/json',\n        'Authorization' =\u003e 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'\n    ])\n    -\u003ereply(200)\n    -\u003ewithHeader('Content-Type', 'application/json')\n    -\u003ewithJson([\n        [\n            'name' =\u003e 'John Doe',\n            'username' =\u003e 'john',\n            'email' =\u003e 'john@example.com'\n        ],\n        [\n            'name' =\u003e 'Jane Doe',\n            'username' =\u003e 'jane',\n            'email' =\u003e 'jane@example.com'\n        ],\n    ]);\n\n// Pass PSR-18 compatible client to the API client.\n$client = new MysteriousApiClient($builder-\u003egetClient());\n$client-\u003esetCredentials('username', 'password');\n\n// Receive mock response.\n$response = $client-\u003egetUsers();\n```\n\nSame mock, but with models! Also, the code itself is slightly shorter.\n\n```php\nuse Pock\\Enum\\RequestMethod;\nuse Pock\\PockBuilder;\n\n$builder = new PockBuilder();\n$builder-\u003ematchMethod(RequestMethod::GET)\n    -\u003ematchUri('https://example.com/api/v1/users')\n    -\u003ematchHeaders([\n        'Content-Type' =\u003e 'application/json',\n        'Authorization' =\u003e 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'\n    ])\n    -\u003ereply(200)\n    -\u003ewithHeader('Content-Type', 'application/json')\n    -\u003ewithJson([\n        // We're assuming here that MysteriousUser's constructor can receive an initial values.\n        new MysteriousUser('John Doe', 'john', 'john@example.com'),\n        new MysteriousUser('Jane Doe', 'jane', 'jane@example.com'),\n    ]);\n\n// Pass PSR-18 compatible client to the API client.\n$client = new MysteriousApiClient($builder-\u003egetClient());\n$client-\u003esetCredentials('username', 'password');\n\n// Receive mock response.\n$response = $client-\u003egetUsers();\n```\n\nIt is possible to mock a response using DTO's because pock can use third-party serializers under the hood.\n\n# Serializer support\n\npock supports JMS serializer and Symfony serializer out of the box. Available serializer will be instantiated automatically.\nIt will be used to serialize requests and responses in mocks which means you actually can pass an entire DTO\ninto the corresponding methods (for example, `matchJsonBody` as an assertion or `withJsonBody` to generate a response body).\n\nBy default, JMS serializer has more priority than the Symfony serializer. You can use methods below before running tests (`bootstrap.php`)\nif you want to override default behavior.\n\n```php\nuse Pock\\Factory\\JsonSerializerFactory;\nuse Pock\\Factory\\XmlSerializerFactory;\nuse Pock\\Serializer\\SymfonySerializerAdapter;\nuse Symfony\\Component\\Serializer\\Encoder\\JsonEncoder;\nuse Symfony\\Component\\Serializer\\Encoder\\XmlEncoder;\nuse Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer;\nuse Symfony\\Component\\Serializer\\Serializer;\n\n$encoders = [new XmlEncoder(), new JsonEncoder()];\n$normalizers = [new ObjectNormalizer()];\n$serializer = new SymfonySerializerAdapter(new Serializer($normalizers, $encoders));\n\nJsonSerializerFactory::setSerializer($serializer);\nXmlSerializerFactory::setSerializer($serializer);\n```\n\nIn order to use unsupported serializer you should create an adapter which implements `Pock\\Serializer\\SerializerInterface`.\n\n# Roadmap to stable\n\n- [x] `at(N)` - execute mock only at Nth call.  \n- [x] `always()` - always execute this mock (removes mock expiration).  \n- [x] Separate `UniversalMockException` into several exceptions (`PockClientException`, `PockNetworkException`, etc).  \n- [x] Add methods for easier throwing of exceptions listed in previous entry.  \n- [x] `replyWithCallback` - reply using specified callback.  \n- [x] `replyWithFactory` - reply using specified response factory (provide corresponding interface).  \n- [x] Compare XML bodies using `DOMDocument`, fallback to text comparison in case of problems.  \n- [x] Regexp matchers for body, query, URI and path.  \n- [x] Form Data body matcher (partial \u0026 exact)\n- [x] Multipart form body matcher (just like callback matcher but parses the body as a multipart form data)  \n- [x] **BREAKING CHANGE:** Rename serializer decorators to serializer adapters.  \n- [x] Real network response for mocked requests.\n- [ ] `symfony/http-client` support.\n- [ ] Document everything (with examples if it’s feasible).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneur0toxine%2Fpock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneur0toxine%2Fpock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneur0toxine%2Fpock/lists"}