Skip to content

Added examples to readme #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 106 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,112 @@
JsonMatcher
========
***JsonMatcher*** lets You assert Your json like a gangster in Your test cases.
#Matcher

***Matcher*** lets You assert like a gangster in Your test cases.

[![Build Status](https://travis-ci.org/defrag/JsonMatcher.svg)](https://travis-ci.org/defrag/JsonMatcher)

##Example usage

### Scalar matching

```php
match(1, 1);
match('string', 'string')
```

### Type matching

```php

match(1, '@integer@');
match('Norbert', '@string@');
match(array('foo', 'bar'), '@array');
match(12.4, '@double@');
match(true, '@boolean@');
```

### Wildcard

```php
match(1, '@*@');
match(new \stdClass(), '@wildcard@');
```

### Expression matching

```php
match(new \DateTime('2014-04-01'), "expr(value.format('Y-m-d') == '2014-04-01'");
match("Norbert", "expr(value === 'Norbert')");
```

### Array matching

```php
match(
array(
'users' => array(
array(
'id' => 1,
'firstName' => 'Norbert',
'lastName' => 'Orzechowicz',
'roles' => array('ROLE_USER')
),
array(
'id' => 2,
'firstName' => 'Michał',
'lastName' => 'Dąbrowski',
'roles' => array('ROLE_USER')
)
),
true,
6.66
),
array(
'users' => array(
array(
'id' => '@integer',
'firstName' => '@string@',
'lastName' => 'Orzechowicz',
'roles' => '@array@'
),
array(
'id' => '@integer'
'firstName' => '@string@',
'lastName' => 'Dąbrowski',
'roles' => '@array@'
)
),
'@boolean@',
'@double@'
)
)
```

### Json matching


```php
match(
'{
"users":[
{
"firstName": "Norbert",
"lastName": "Orzechowicz",
"roles":["ROLE_USER", "ROLE_DEVELOPER"]}
]
}',
'{
"users":[
{
"firstName": "@string@",
"lastName":" @string@",
"roles": "@array@"
}
]
}'
)

```

Example scenario for api in behat using mongo.
---
``` cucumber
Expand Down