Skip to content

Commit c10611c

Browse files
authored
Feature/phpbench (#221)
* Added phpbenchmark * Added @array_previous@ pattern * Added @array_previous_repeat@ pattern * Fixed github pulls data * Updated README with new patterns * Removed phpbench storage from repo * CS Fixex
1 parent f1834cf commit c10611c

File tree

9 files changed

+20091
-2
lines changed

9 files changed

+20091
-2
lines changed

README.md

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ class MatcherTest extends TestCase
104104
* ``@datetime@``
105105
* ``@timezone@`` || ``@tz``
106106
* ``@array@``
107-
* ``@...@`` - *unbounded array*
107+
* ``@array_previous@`` - match next array element using pattern from previous element
108+
* ``@array_previous_repeat@`` - match all remaining array elements using pattern from previous element
109+
* ``@...@`` - *unbounded array*, once used matcher will skip any further array elements
108110
* ``@null@``
109111
* ``@*@`` || ``@wildcard@``
110112
* ``expr(expression)`` - **optional**, requires `symfony/expression-language: ^2.3|^3.0|^4.0|^5.0` to be present
@@ -391,6 +393,115 @@ $matcher->match(
391393
);
392394
```
393395

396+
### Array Previous
397+
398+
> @array_previous@ can also be used when matching JSON's and XML's
399+
400+
```php
401+
<?php
402+
403+
use Coduo\PHPMatcher\PHPMatcher;
404+
405+
$matcher = new PHPMatcher();
406+
407+
$matcher->match(
408+
array(
409+
'users' => array(
410+
array(
411+
'id' => 1,
412+
'firstName' => 'Norbert',
413+
'lastName' => 'Orzechowicz',
414+
'roles' => array('ROLE_USER'),
415+
'position' => 'Developer',
416+
),
417+
array(
418+
'id' => 2,
419+
'firstName' => 'Michał',
420+
'lastName' => 'Dąbrowski',
421+
'roles' => array('ROLE_USER')
422+
),
423+
array(
424+
'id' => 3,
425+
'firstName' => 'Johnny',
426+
'lastName' => 'DąbrowsBravoki',
427+
'roles' => array('ROLE_HANDSOME_GUY')
428+
)
429+
),
430+
true,
431+
6.66
432+
),
433+
array(
434+
'users' => array(
435+
array(
436+
'id' => '@integer@.greaterThan(0)',
437+
'firstName' => '@string@',
438+
'lastName' => 'Orzechowicz',
439+
'roles' => '@array@',
440+
'position' => '@string@.optional()'
441+
),
442+
'@array_previous@',
443+
'@array_previous@'
444+
),
445+
'@boolean@',
446+
'@double@'
447+
)
448+
);
449+
```
450+
451+
### Array Previous Repeat
452+
453+
> @array_previous_repeat@ can also be used when matching JSON's and XML's
454+
455+
```php
456+
<?php
457+
458+
use Coduo\PHPMatcher\PHPMatcher;
459+
460+
$matcher = new PHPMatcher();
461+
462+
$matcher->match(
463+
array(
464+
'users' => array(
465+
array(
466+
'id' => 1,
467+
'firstName' => 'Norbert',
468+
'lastName' => 'Orzechowicz',
469+
'roles' => array('ROLE_USER'),
470+
'position' => 'Developer',
471+
),
472+
array(
473+
'id' => 2,
474+
'firstName' => 'Michał',
475+
'lastName' => 'Dąbrowski',
476+
'roles' => array('ROLE_USER')
477+
),
478+
array(
479+
'id' => 3,
480+
'firstName' => 'Johnny',
481+
'lastName' => 'DąbrowsBravoki',
482+
'roles' => array('ROLE_HANDSOME_GUY')
483+
)
484+
),
485+
true,
486+
6.66
487+
),
488+
array(
489+
'users' => array(
490+
array(
491+
'id' => '@integer@.greaterThan(0)',
492+
'firstName' => '@string@',
493+
'lastName' => 'Orzechowicz',
494+
'roles' => '@array@',
495+
'position' => '@string@.optional()'
496+
),
497+
'@array_previous_repeat@'
498+
),
499+
'@boolean@',
500+
'@double@'
501+
)
502+
);
503+
```
504+
394505
### Json matching
395506

396507
```php

0 commit comments

Comments
 (0)