Skip to content

Commit 8dcbb50

Browse files
authored
Merge pull request #1 from JarJak/patch-4
Merge repeat expanders tests
2 parents f2aef27 + 7b040d5 commit 8dcbb50

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
language: php
22

3-
sudo: false
4-
53
cache:
64
directories:
75
- $HOME/.composer/cache

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# PHP Matcher
22

3-
Library created for testing all kinds of JSON/XML/TXT/Scalar values against patterns.
3+
Library created for testing all kinds of JSON/XML/TXT/Scalar values against patterns.
44

55
```php
66
PHPMatcher::match($value = '{"foo": "bar"}', $pattern = '{"foo": "@string@"}');
77
```
88

9-
It was built to simplify API's functional testing.
9+
It was built to simplify API's functional testing.
1010

1111
* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg)](https://travis-ci.org/coduo/php-matcher) - master (3.2.*)
1212
* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=3.1)](https://travis-ci.org/coduo/php-matcher) - 3.1.*
1313

1414
[Readme for master (3.2) version](https://github.com/coduo/php-matcher/tree/master/README.md)
15-
[Readme for 3.1 version](https://github.com/coduo/php-matcher/tree/3.1/README.md)
15+
[Readme for 3.1 version](https://github.com/coduo/php-matcher/tree/3.1/README.md)
1616

1717

1818
## Installation
@@ -32,7 +32,7 @@ composer require --dev "coduo/php-matcher"
3232

3333
use Coduo\PHPMatcher\PHPMatcher;
3434

35-
if (!PHPMatcher::match("lorem ipsum dolor", "@string@", $error)) {
35+
if (!PHPMatcher::match("lorem ipsum dolor", "@string@", $error)) {
3636
echo $error; // in case of error message is set on $error variable via reference
3737
}
3838

@@ -214,7 +214,7 @@ $matcher->match(array("bar"), "@wildcard@");
214214
$matcher->match(new \stdClass, "@wildcard@");
215215
```
216216

217-
### Expression matching
217+
### Expression matching
218218

219219
```php
220220
<?php
@@ -241,7 +241,7 @@ $matcher = $factory->createMatcher();
241241
$matcher->match('9f4db639-0e87-4367-9beb-d64e3f42ae18', '@uuid@');
242242
```
243243

244-
### Array matching
244+
### Array matching
245245

246246
```php
247247
<?php
@@ -296,11 +296,11 @@ $matcher->match(
296296
),
297297
'@boolean@',
298298
'@double@'
299-
)
299+
)
300300
);
301301
```
302302

303-
### Json matching
303+
### Json matching
304304

305305
```php
306306
<?php
@@ -452,7 +452,7 @@ Feature: Listing user toys
452452
Scenario: Listing toys
453453
Given the following users exist:
454454
| firstName | lastName |
455-
| Chuck | Norris |
455+
| Chuck | Norris |
456456
457457
And the following toys user "Chuck Norris" exist:
458458
| name |
@@ -483,7 +483,7 @@ Feature: Listing user toys
483483
}
484484
]
485485
"""
486-
```
486+
```
487487

488488
## PHPUnit integration
489489

@@ -495,8 +495,9 @@ or extend the `Coduo\PHPMatcher\PHPUnit\PHPMatcherTestCase`:
495495
namespace Coduo\PHPMatcher\Tests\PHPUnit;
496496

497497
use Coduo\PHPMatcher\PHPUnit\PHPMatcherAssertions;
498+
use PHPUnit\Framework\TestCase;
498499

499-
class PHPMatcherAssertionsTest extends \PHPUnit_Framework_TestCase
500+
class PHPMatcherAssertionsTest extends TestCase
500501
{
501502
use PHPMatcherAssertions;
502503

@@ -510,7 +511,7 @@ class PHPMatcherAssertionsTest extends \PHPUnit_Framework_TestCase
510511
The `matchesPattern()` method can be used in PHPUnit stubs or mocks:
511512

512513
```php
513-
$mock = $this->getMock(Foo::class);
514+
$mock = $this->createMock(Foo::class);
514515
$mock->method('bar')
515516
->with($this->matchesPattern('@string@'))
516517
->willReturn('foo');
@@ -524,4 +525,3 @@ This library is distributed under the MIT license. Please see the LICENSE file.
524525

525526
This lib was inspired by [JSON Expressions gem](https://github.com/chancancode/json_expressions) &&
526527
[Behat RestExtension ](https://github.com/jakzal/RestExtension)
527-

phpunit.xml.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<testsuites>
77
<testsuite name="PHP Matcher Test Suite">
88
<directory>./tests/</directory>
9-
<exclude>tests/PHPUnit/PHPMatcherAssertionsTest.php</exclude>
10-
<file phpVersion="7.0.0" phpVersionOperator=">=">tests/PHPUnit/PHPMatcherAssertionsTest.php</file>
119
</testsuite>
1210
</testsuites>
1311
<filter>

src/PHPUnit/PHPMatcherConstraint.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ final class PHPMatcherConstraint extends Constraint
1616

1717
public function __construct(string $pattern)
1818
{
19-
parent::__construct();
19+
if (\method_exists(Constraint::class, '__construct')) {
20+
parent::__construct();
21+
}
2022

2123
$this->pattern = $pattern;
2224
$this->matcher = $this->createMatcher();

tests/Matcher/JsonMatcherTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public static function negativePatterns()
150150
return [
151151
['@string@'],
152152
['["Norbert", '],
153+
['@[email protected]({"name": "@string@", "value": "@array@"})']
153154
];
154155
}
155156

@@ -215,6 +216,14 @@ public static function positiveMatches()
215216
[
216217
'[{"name": "Norbert","lastName":"Orzechowicz"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
217218
'[{"name": "Norbert","@*@":"@*@"},@...@]'
219+
],
220+
[
221+
'[{"name": "Norbert"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
222+
'@[email protected]({\"name\": \"@string@\"})'
223+
],
224+
[
225+
'[{"name": "Norbert","lastName":"Orzechowicz"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
226+
'@[email protected]({\"name\": \"@string@\",\"@*@\":\"@*@\"})'
218227
]
219228
];
220229
}
@@ -242,6 +251,10 @@ public static function negativeMatches()
242251
'{"foo":"foo val","bar":"bar val"}',
243252
'{"foo":"foo val"}'
244253
],
254+
[
255+
'[{"name": "Norbert","lastName":"Orzechowicz"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
256+
'@[email protected]({\"name\": \"@string@\"})'
257+
],
245258
[
246259
[],
247260
'[]'

0 commit comments

Comments
 (0)