Skip to content

Commit eea7f3d

Browse files
committed
Merge pull request #4 from norzechowicz/readme
Added examples to readme
2 parents 0cef84a + 95ca116 commit eea7f3d

File tree

1 file changed

+106
-3
lines changed

1 file changed

+106
-3
lines changed

README.md

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,112 @@
1-
JsonMatcher
2-
========
3-
***JsonMatcher*** lets You assert Your json like a gangster in Your test cases.
1+
#Matcher
2+
3+
***Matcher*** lets You assert like a gangster in Your test cases.
44

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

7+
##Example usage
8+
9+
### Scalar matching
10+
11+
```php
12+
match(1, 1);
13+
match('string', 'string')
14+
```
15+
16+
### Type matching
17+
18+
```php
19+
20+
match(1, '@integer@');
21+
match('Norbert', '@string@');
22+
match(array('foo', 'bar'), '@array');
23+
match(12.4, '@double@');
24+
match(true, '@boolean@');
25+
```
26+
27+
### Wildcard
28+
29+
```php
30+
match(1, '@*@');
31+
match(new \stdClass(), '@wildcard@');
32+
```
33+
34+
### Expression matching
35+
36+
```php
37+
match(new \DateTime('2014-04-01'), "expr(value.format('Y-m-d') == '2014-04-01'");
38+
match("Norbert", "expr(value === 'Norbert')");
39+
```
40+
41+
### Array matching
42+
43+
```php
44+
match(
45+
array(
46+
'users' => array(
47+
array(
48+
'id' => 1,
49+
'firstName' => 'Norbert',
50+
'lastName' => 'Orzechowicz',
51+
'roles' => array('ROLE_USER')
52+
),
53+
array(
54+
'id' => 2,
55+
'firstName' => 'Michał',
56+
'lastName' => 'Dąbrowski',
57+
'roles' => array('ROLE_USER')
58+
)
59+
),
60+
true,
61+
6.66
62+
),
63+
array(
64+
'users' => array(
65+
array(
66+
'id' => '@integer',
67+
'firstName' => '@string@',
68+
'lastName' => 'Orzechowicz',
69+
'roles' => '@array@'
70+
),
71+
array(
72+
'id' => '@integer'
73+
'firstName' => '@string@',
74+
'lastName' => 'Dąbrowski',
75+
'roles' => '@array@'
76+
)
77+
),
78+
'@boolean@',
79+
'@double@'
80+
)
81+
)
82+
```
83+
84+
### Json matching
85+
86+
87+
```php
88+
match(
89+
'{
90+
"users":[
91+
{
92+
"firstName": "Norbert",
93+
"lastName": "Orzechowicz",
94+
"roles":["ROLE_USER", "ROLE_DEVELOPER"]}
95+
]
96+
}',
97+
'{
98+
"users":[
99+
{
100+
"firstName": "@string@",
101+
"lastName":" @string@",
102+
"roles": "@array@"
103+
}
104+
]
105+
}'
106+
)
107+
108+
```
109+
7110
Example scenario for api in behat using mongo.
8111
---
9112
``` cucumber

0 commit comments

Comments
 (0)