|
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. |
4 | 4 |
|
5 | 5 | [](https://travis-ci.org/defrag/JsonMatcher)
|
6 | 6 |
|
| 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 | + |
7 | 110 | Example scenario for api in behat using mongo.
|
8 | 111 | ---
|
9 | 112 | ``` cucumber
|
|
0 commit comments