{"id":13616416,"url":"https://github.com/coduo/php-matcher","last_synced_at":"2025-05-13T19:07:43.200Z","repository":{"id":16055180,"uuid":"18799315","full_name":"coduo/php-matcher","owner":"coduo","description":"The easiest way to match data structures like JSON/PlainText/XML against readable patterns. Sandbox:","archived":false,"fork":false,"pushed_at":"2025-03-01T11:52:52.000Z","size":8202,"stargazers_count":825,"open_issues_count":8,"forks_count":86,"subscribers_count":20,"default_branch":"6.x","last_synced_at":"2025-04-20T02:08:28.578Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://php-matcher.norbert.tech/","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/coduo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2014-04-15T12:33:45.000Z","updated_at":"2025-04-19T14:18:04.000Z","dependencies_parsed_at":"2023-01-14T12:39:32.201Z","dependency_job_id":"1b9804ff-ddbb-4884-b760-9967b2be9565","html_url":"https://github.com/coduo/php-matcher","commit_stats":{"total_commits":455,"total_committers":65,"mean_commits":7.0,"dds":0.6703296703296704,"last_synced_commit":"a82c76ffbff8df8a4a5416f1dce883d6b6a61493"},"previous_names":[],"tags_count":63,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coduo%2Fphp-matcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coduo%2Fphp-matcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coduo%2Fphp-matcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coduo%2Fphp-matcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coduo","download_url":"https://codeload.github.com/coduo/php-matcher/tar.gz/refs/heads/6.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250070779,"owners_count":21369923,"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":[],"created_at":"2024-08-01T20:01:28.254Z","updated_at":"2025-04-25T18:20:55.945Z","avatar_url":"https://github.com/coduo.png","language":"PHP","readme":"# PHP Matcher\n\n[![Type Coverage](https://shepherd.dev/github/coduo/php-matcher/coverage.svg)](https://shepherd.dev/coduo/php-matcher)\n\nLibrary created for testing all kinds of JSON/XML/TXT/Scalar values against patterns.\n\nAPI: \n\n```php\nPHPMatcher::match($value = '{\"foo\": \"bar\"}', $pattern = '{\"foo\": \"@string@\"}') : bool;\nPHPMatcher::backtrace() : Backtrace;\nPHPMatcher::error() : ?string;\n```\n\nIt was built to simplify API's functional testing.\n\n* [![Test Suite](https://github.com/coduo/php-matcher/actions/workflows/test-suite.yml/badge.svg?branch=6.x)](https://github.com/coduo/php-matcher/actions/workflows/test-suite.yml) - [6.x README](https://github.com/coduo/php-matcher/tree/6.x/README.md)  PHP \u003e= 8.1 \u003c= 8.3\n* [5.x README](https://github.com/coduo/php-matcher/tree/5.x/README.md)  PHP \u003e= 7.2 \u003c 8.0\n* [5.0 README](https://github.com/coduo/php-matcher/tree/5.0/README.md)  PHP \u003e= 7.2 \u003c 8.0\n* [4.0.* README](https://github.com/coduo/php-matcher/tree/4.0/README.md)  PHP \u003e= 7.2 \u003c 8.0\n* [3.2.* README](https://github.com/coduo/php-matcher/tree/3.2/README.md) PHP \u003e= 7.0 \u003c 8.0\n* [3.1.* README](https://github.com/coduo/php-matcher/tree/3.1/README.md) PHP \u003e= 7.0 \u003c 8.0\n\n[![Latest Stable Version](https://poser.pugx.org/coduo/php-matcher/v/stable)](https://packagist.org/packages/coduo/php-matcher)\n[![Total Downloads](https://poser.pugx.org/coduo/php-matcher/downloads)](https://packagist.org/packages/coduo/php-matcher)\n[![Latest Unstable Version](https://poser.pugx.org/coduo/php-matcher/v/unstable)](https://packagist.org/packages/coduo/php-matcher)\n[![License](https://poser.pugx.org/coduo/php-matcher/license)](https://packagist.org/packages/coduo/php-matcher)\n\n## Sandbox\n\nFeel free to play first with [Sandbox](https://php-matcher.norbert.tech/)\n\n## Installation\n\nRequire new dev dependency using composer:\n\n```\ncomposer require --dev \"coduo/php-matcher\"\n```\n\n## Basic usage\n\n### Direct PHPMatcher usage\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n$match = $matcher-\u003ematch(\"lorem ipsum dolor\", \"@string@\");\n\nif (!$match) {\n    echo \"Error: \" . $matcher-\u003eerror();\n    echo \"Backtrace: \\n\";\n    echo (string) $matcher-\u003ebacktrace();\n}\n```\n\n### PHPUnit extending PHPMatcherTestCase\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPUnit\\PHPMatcherTestCase;\n\nclass MatcherTest extends PHPMatcherTestCase\n{\n    public function test_matcher_that_value_matches_pattern()\n    {\n        $this-\u003eassertMatchesPattern('{\"name\": \"@string@\"}', '{\"name\": \"Norbert\"}');\n    }\n}\n```\n\n### PHPUnit using PHPMatcherAssertions trait\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPUnit\\PHPMatcherAssertions;\nuse PHPUnit\\Framework\\TestCase;\n\nclass MatcherTest extends TestCase\n{\n    use PHPMatcherAssertions;\n\n    public function test_matcher_that_value_matches_pattern()\n    {\n        $this-\u003eassertMatchesPattern('{\"name\": \"@string@\"}', '{\"name\": \"Norbert\"}');\n    }\n}\n```\n\n### Available patterns\n\n* ``@string@``\n* ``@integer@``\n* ``@number@``\n* ``@double@``\n* ``@boolean@``\n* ``@time@``\n* ``@date@``\n* ``@datetime@``\n* ``@timezone@`` || ``@tz``\n* ``@array@``\n* ``@array_previous@`` - match next array element using pattern from previous element\n* ``@array_previous_repeat@`` - match all remaining array elements using pattern from previous element\n* ``@...@`` - *unbounded array*, once used matcher will skip any further array elements\n* ``@null@``\n* ``@*@`` || ``@wildcard@``\n* ``expr(expression)`` - **optional**, requires `symfony/expression-language: ^2.3|^3.0|^4.0|^5.0` to be present\n* ``@uuid@``\n* ``@ulid@``\n* ``@json@``\n* ``@string@||@integer@`` - string OR integer\n\n### Available pattern expanders\n\n* ``startsWith($stringBeginning, $ignoreCase = false)``\n* ``endsWith($stringEnding, $ignoreCase = false)``\n* ``contains($string, $ignoreCase = false)``\n* ``notContains($string, $ignoreCase = false)``\n* ``isDateTime()``\n* ``isInDateFormat($format)`` - example `\"@datetime@.isInDateFormat('Y-m-d H:i:s')`\n* ``before(string $date)`` - example ``\"@string@.isDateTime().before(\\\"2020-01-01 00:00:00\\\")\"``\n* ``after(string $date)`` - example ``\"@string@.isDateTime().after(\\\"2020-01-01 00:00:00\\\")\"``\n* ``isTzOffset()``\n* ``isTzIdentifier()``\n* ``isTzAbbreviation()``\n* ``isEmail()``\n* ``isUrl()``\n* ``isIp()``\n* ``isEmpty()``\n* ``isNotEmpty()``\n* ``lowerThan($boundry)``\n* ``greaterThan($boundry)``\n* ``inArray($value)`` - example ``\"@array@.inArray(\\\"ROLE_USER\\\")\"`` \n* ``hasProperty($propertyName)`` - example ``\"@json@.hasProperty(\\\"property_name\\\")\"``\n* ``oneOf(...$expanders)`` - example ``\"@string@.oneOf(contains('foo'), contains('bar'), contains('baz'))\"``\n* ``matchRegex($regex)`` - example ``\"@string@.matchRegex('/^lorem.+/')\"``\n* ``optional()`` - work's only with ``ArrayMatcher``, ``JsonMatcher`` and ``XmlMatcher``\n* ``count()`` - work's only with ``ArrayMatcher`` - example ``\"@array@.count(5)\"``\n* ``repeat($pattern, $isStrict = true)`` - example ``'@array@.repeat({\"name\": \"foe\"})'`` or ``\"@array@.repeat('@string@')\"``\n* ``match($pattern)`` - example ``{\"image\":\"@json@.match({\\\"url\\\":\\\"@string@.isUrl()\\\"})\"}``\n\n## Example usage\n\n### Scalar matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(1, 1);\n$matcher-\u003ematch('string', 'string');\n```\n\n### String matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch('Norbert', '@string@');\n$matcher-\u003ematch(\"lorem ipsum dolor\", \"@string@.startsWith('lorem').contains('ipsum').endsWith('dolor')\");\n\n```\n\n### Time matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch('00:00:00', '@time@');\n$matcher-\u003ematch('00:01:00.000000', '@time@');\n$matcher-\u003ematch('00:01:00', '@time@.after(\"00:00:00\")');\n$matcher-\u003ematch('00:00:00', '@time@.before(\"01:00:00\")');\n\n```\n\n### Date matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch('2014-08-19', '@date@');\n$matcher-\u003ematch('2020-01-11', '@date@');\n$matcher-\u003ematch('2014-08-19', '@date@.before(\"2016-08-19\")');\n$matcher-\u003ematch('2014-08-19', '@date@.before(\"today\").after(\"+ 100year\")');\n\n```\n\n### DateTime matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch('2014-08-19', '@datetime@');\n$matcher-\u003ematch('2020-01-11 00:00:00', '@datetime@');\n$matcher-\u003ematch('2014-08-19', '@datetime@.before(\"2016-08-19\")');\n$matcher-\u003ematch('2014-08-19', '@datetime@.before(\"today\").after(\"+ 100year\")');\n\n```\n\n### TimeZone matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch('Europe/Warsaw', '@timezone@');\n$matcher-\u003ematch('Europe/Warsaw', '@tz@');\n$matcher-\u003ematch('GMT', '@tz@');\n$matcher-\u003ematch('01:00', '@tz@');\n$matcher-\u003ematch('01:00', '@tz@.isTzOffset()');\n$matcher-\u003ematch('GMT', '@tz@.isTzAbbreviation()');\n$matcher-\u003ematch('Europe/Warsaw', '@tz@.isTzIdentifier()');\n```\n\n### Integer matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(100, '@integer@');\n$matcher-\u003ematch(100, '@integer@.lowerThan(200).greaterThan(10)');\n\n```\n\n### Number matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(100, '@number@');\n$matcher-\u003ematch('200', '@number@');\n$matcher-\u003ematch(1.25, '@number@');\n$matcher-\u003ematch('1.25', '@number@');\n$matcher-\u003ematch(0b10100111001, '@number@');\n```\n\n### Double matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(10.1, \"@double@\");\n$matcher-\u003ematch(10.1, \"@double@.lowerThan(50.12).greaterThan(10)\");\n```\n\n### Boolean matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(true, \"@boolean@\");\n$matcher-\u003ematch(false, \"@boolean@\");\n```\n\n### Wildcard matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(\"@integer@\", \"@*@\");\n$matcher-\u003ematch(\"foobar\", \"@*@\");\n$matcher-\u003ematch(true, \"@*@\");\n$matcher-\u003ematch(6.66, \"@*@\");\n$matcher-\u003ematch(array(\"bar\"), \"@wildcard@\");\n$matcher-\u003ematch(new \\stdClass, \"@wildcard@\");\n```\n\n### Expression matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(new \\DateTime('2014-04-01'), \"expr(value.format('Y-m-d') == '2014-04-01'\");\n$matcher-\u003ematch(\"Norbert\", \"expr(value === 'Norbert')\");\n```\n\n### UUID matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch('9f4db639-0e87-4367-9beb-d64e3f42ae18', '@uuid@');\n```\n\n### ULID matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch('01BX5ZZKBKACTAV9WEVGEMMVS0', '@ulid@');\n```\n\n### Array matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(\n   array(\n      'users' =\u003e array(\n          array(\n              'id' =\u003e 1,\n              'firstName' =\u003e 'Norbert',\n              'lastName' =\u003e 'Orzechowicz',\n              'roles' =\u003e array('ROLE_USER'),\n              'position' =\u003e 'Developer',\n          ),\n          array(\n              'id' =\u003e 2,\n              'firstName' =\u003e 'Michał',\n              'lastName' =\u003e 'Dąbrowski',\n              'roles' =\u003e array('ROLE_USER')\n          ),\n          array(\n              'id' =\u003e 3,\n              'firstName' =\u003e 'Johnny',\n              'lastName' =\u003e 'DąbrowsBravoki',\n              'roles' =\u003e array('ROLE_HANDSOME_GUY')\n          )\n      ),\n      true,\n      6.66\n  ),\n   array(\n      'users' =\u003e array(\n          array(\n              'id' =\u003e '@integer@.greaterThan(0)',\n              'firstName' =\u003e '@string@',\n              'lastName' =\u003e 'Orzechowicz',\n              'roles' =\u003e '@array@',\n              'position' =\u003e '@string@.optional()'\n          ),\n          array(\n              'id' =\u003e '@integer@',\n              'firstName' =\u003e '@string@',\n              'lastName' =\u003e 'Dąbrowski',\n              'roles' =\u003e '@array@'\n          ),\n          '@...@'\n      ),\n      '@boolean@',\n      '@double@'\n  )\n);\n```\n\n### Array Previous\n\n\u003e @array_previous@ can also be used when matching JSON's and XML's\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(\n   array(\n      'users' =\u003e array(\n          array(\n              'id' =\u003e 1,\n              'firstName' =\u003e 'Norbert',\n              'lastName' =\u003e 'Orzechowicz',\n              'roles' =\u003e array('ROLE_USER'),\n              'position' =\u003e 'Developer',\n          ),\n          array(\n              'id' =\u003e 2,\n              'firstName' =\u003e 'Michał',\n              'lastName' =\u003e 'Dąbrowski',\n              'roles' =\u003e array('ROLE_USER')\n          ),\n          array(\n              'id' =\u003e 3,\n              'firstName' =\u003e 'Johnny',\n              'lastName' =\u003e 'DąbrowsBravoki',\n              'roles' =\u003e array('ROLE_HANDSOME_GUY')\n          )\n      ),\n      true,\n      6.66\n  ),\n   array(\n      'users' =\u003e array(\n          array(\n              'id' =\u003e '@integer@.greaterThan(0)',\n              'firstName' =\u003e '@string@',\n              'lastName' =\u003e 'Orzechowicz',\n              'roles' =\u003e '@array@',\n              'position' =\u003e '@string@.optional()'\n          ),\n          '@array_previous@',\n          '@array_previous@'\n      ),\n      '@boolean@',\n      '@double@'\n  )\n);\n```\n\n### Array Previous Repeat\n\n\u003e @array_previous_repeat@ can also be used when matching JSON's and XML's\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(\n   array(\n      'users' =\u003e array(\n          array(\n              'id' =\u003e 1,\n              'firstName' =\u003e 'Norbert',\n              'lastName' =\u003e 'Orzechowicz',\n              'roles' =\u003e array('ROLE_USER'),\n              'position' =\u003e 'Developer',\n          ),\n          array(\n              'id' =\u003e 2,\n              'firstName' =\u003e 'Michał',\n              'lastName' =\u003e 'Dąbrowski',\n              'roles' =\u003e array('ROLE_USER')\n          ),\n          array(\n              'id' =\u003e 3,\n              'firstName' =\u003e 'Johnny',\n              'lastName' =\u003e 'DąbrowsBravoki',\n              'roles' =\u003e array('ROLE_HANDSOME_GUY')\n          )\n      ),\n      true,\n      6.66\n  ),\n   array(\n      'users' =\u003e array(\n          array(\n              'id' =\u003e '@integer@.greaterThan(0)',\n              'firstName' =\u003e '@string@',\n              'lastName' =\u003e 'Orzechowicz',\n              'roles' =\u003e '@array@',\n              'position' =\u003e '@string@.optional()'\n          ),\n          '@array_previous_repeat@'\n      ),\n      '@boolean@',\n      '@double@'\n  )\n);\n```\n\n### Json matching\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(\n  '{\n    \"users\":[\n      {\n        \"firstName\": \"Norbert\",\n        \"lastName\": \"Orzechowicz\",\n        \"created\": \"2014-01-01\",\n        \"roles\":[\"ROLE_USER\", \"ROLE_DEVELOPER\"]\n      }\n    ]\n  }',\n  '{\n    \"users\":[\n      {\n        \"firstName\": \"@string@\",\n        \"lastName\": \"@string@\",\n        \"created\": \"@string@.isDateTime()\",\n        \"roles\": \"@array@\",\n        \"position\": \"@string@.optional()\"\n      }\n    ]\n  }'\n);\n```\n\n### Json matching with unbounded arrays and objects\n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(\n  '{\n    \"users\":[\n      {\n        \"firstName\": \"Norbert\",\n        \"lastName\": \"Orzechowicz\",\n        \"created\": \"2014-01-01\",\n        \"roles\":[\"ROLE_USER\", \"ROLE_DEVELOPER\"],\n        \"attributes\": {\n          \"isAdmin\": false,\n          \"dateOfBirth\": null,\n          \"hasEmailVerified\": true\n        },\n        \"avatar\": {\n          \"url\": \"http://avatar-image.com/avatar.png\"\n        }\n      },\n      {\n        \"firstName\": \"Michał\",\n        \"lastName\": \"Dąbrowski\",\n        \"created\": \"2014-01-01\",\n        \"roles\":[\"ROLE_USER\", \"ROLE_DEVELOPER\", \"ROLE_ADMIN\"],\n        \"attributes\": {\n          \"isAdmin\": true,\n          \"dateOfBirth\": null,\n          \"hasEmailVerified\": true\n        },\n        \"avatar\": null\n      }\n    ]\n  }',\n  '{\n    \"users\":[\n      {\n        \"firstName\": \"@string@\",\n        \"lastName\": \"@string@\",\n        \"created\": \"@string@.isDateTime()\",\n        \"roles\": [\n            \"ROLE_USER\",\n            \"@...@\"\n        ],\n        \"attributes\": {\n          \"isAdmin\": @boolean@,\n          \"@*@\": \"@*@\"\n        },\n        \"avatar\": \"@json@.match({\\\"url\\\":\\\"@string@.isUrl()\\\"})\"\n      }\n      ,\n      @...@\n    ]\n  }'\n);\n```\n\n### Xml matching\n\n**Optional** - requires `openlss/lib-array2xml: ^1.0` to be present. \n\n```php\n\u003c?php\n\nuse Coduo\\PHPMatcher\\PHPMatcher;\n\n$matcher = new PHPMatcher();\n\n$matcher-\u003ematch(\u003c\u003c\u003cXML\n\u003c?xml version=\"1.0\"?\u003e\n\u003csoap:Envelope\nxmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\"\nsoap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\"\u003e\n\n\u003csoap:Body xmlns:m=\"http://www.example.org/stock\"\u003e\n  \u003cm:GetStockPrice\u003e\n    \u003cm:StockName\u003eIBM\u003c/m:StockName\u003e\n    \u003cm:StockValue\u003eAny Value\u003c/m:StockValue\u003e\n  \u003c/m:GetStockPrice\u003e\n\u003c/soap:Body\u003e\n\n\u003c/soap:Envelope\u003e\nXML\n                ,\n                \u003c\u003c\u003cXML\n\u003c?xml version=\"1.0\"?\u003e\n\u003csoap:Envelope\n    xmlns:soap=\"@string@\"\n            soap:encodingStyle=\"@string@\"\u003e\n\n\u003csoap:Body xmlns:m=\"@string@\"\u003e\n  \u003cm:GetStockPrice\u003e\n    \u003cm:StockName\u003e@string@\u003c/m:StockName\u003e\n    \u003cm:StockValue\u003e@string@\u003c/m:StockValue\u003e\n    \u003cm:StockQty\u003e@integer@.optional()\u003c/m:StockQty\u003e\n  \u003c/m:GetStockPrice\u003e\n\u003c/soap:Body\u003e\n\n\u003c/soap:Envelope\u003e\nXML\n        );\n```\n\nExample scenario for api in behat using mongo.\n---\n``` cucumber\n@profile, @user\nFeature: Listing user toys\n\n  As a user\n  I want to list my toys\n\n  Background:\n    Given I send and accept JSON\n\n  Scenario: Listing toys\n    Given the following users exist:\n      | firstName     | lastName     |\n      | Chuck         | Norris       |\n\n    And the following toys user \"Chuck Norris\" exist:\n      | name            |\n      | Barbie          |\n      | GI Joe          |\n      | Optimus Prime   |\n\n    When I set valid authorization code oauth header for user \"Chuck Norris\"\n    And I send a GET request on \"/api/toys\"\n    Then the response status code should be 200\n    And the JSON response should match:\n    \"\"\"\n      [\n        {\n          \"id\": \"@string@\",\n          \"name\": \"Barbie\",\n          \"_links: \"@*@\"\n        },\n        {\n          \"id\": \"@string@\",\n          \"name\": \"GI Joe\",\n          \"_links\": \"@*@\"\n        },\n        {\n          \"id\": \"@string@\",\n          \"name\": \"Optimus Prime\",\n          \"_links\": \"@*@\"\n        }\n      ]\n    \"\"\"\n```\n\n## PHPUnit integration\n\nThe `assertMatchesPattern()` is a handy assertion that matches values in PHPUnit tests.\nTo use it either include the `Coduo\\PHPMatcher\\PHPUnit\\PHPMatcherAssertions` trait,\nor extend the `Coduo\\PHPMatcher\\PHPUnit\\PHPMatcherTestCase`:\n\n```php\nnamespace Coduo\\PHPMatcher\\Tests\\PHPUnit;\n\nuse Coduo\\PHPMatcher\\PHPUnit\\PHPMatcherAssertions;\nuse PHPUnit\\Framework\\TestCase;\n\nclass PHPMatcherAssertionsTest extends TestCase\n{\n    use PHPMatcherAssertions;\n\n    public function test_it_asserts_if_a_value_matches_the_pattern()\n    {\n        $this-\u003eassertMatchesPattern('@string@', 'foo');\n    }\n}\n```\n\nThe `matchesPattern()` method can be used in PHPUnit stubs or mocks:\n\n```php\n$mock = $this-\u003ecreateMock(Foo::class);\n$mock-\u003emethod('bar')\n    -\u003ewith($this-\u003ematchesPattern('@string@'))\n    -\u003ewillReturn('foo');\n```\n\n## License\n\nThis library is distributed under the MIT license. Please see the LICENSE file.\n\n## Credits\n\nThis lib was inspired by [JSON Expressions gem](https://github.com/chancancode/json_expressions) \u0026\u0026\n[Behat RestExtension ](https://github.com/jakzal/RestExtension)\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoduo%2Fphp-matcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoduo%2Fphp-matcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoduo%2Fphp-matcher/lists"}