Skip to content

Merge repeat expanders tests #1

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 4 commits into from
Apr 21, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php

sudo: false

cache:
directories:
- $HOME/.composer/cache
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# PHP Matcher

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

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

It was built to simplify API's functional testing.
It was built to simplify API's functional testing.

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

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


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

use Coduo\PHPMatcher\PHPMatcher;

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

Expand Down Expand Up @@ -214,7 +214,7 @@ $matcher->match(array("bar"), "@wildcard@");
$matcher->match(new \stdClass, "@wildcard@");
```

### Expression matching
### Expression matching

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

### Array matching
### Array matching

```php
<?php
Expand Down Expand Up @@ -296,11 +296,11 @@ $matcher->match(
),
'@boolean@',
'@double@'
)
)
);
```

### Json matching
### Json matching

```php
<?php
Expand Down Expand Up @@ -452,7 +452,7 @@ Feature: Listing user toys
Scenario: Listing toys
Given the following users exist:
| firstName | lastName |
| Chuck | Norris |
| Chuck | Norris |

And the following toys user "Chuck Norris" exist:
| name |
Expand Down Expand Up @@ -483,7 +483,7 @@ Feature: Listing user toys
}
]
"""
```
```

## PHPUnit integration

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

use Coduo\PHPMatcher\PHPUnit\PHPMatcherAssertions;
use PHPUnit\Framework\TestCase;

class PHPMatcherAssertionsTest extends \PHPUnit_Framework_TestCase
class PHPMatcherAssertionsTest extends TestCase
{
use PHPMatcherAssertions;

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

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

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

2 changes: 0 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<testsuites>
<testsuite name="PHP Matcher Test Suite">
<directory>./tests/</directory>
<exclude>tests/PHPUnit/PHPMatcherAssertionsTest.php</exclude>
<file phpVersion="7.0.0" phpVersionOperator=">=">tests/PHPUnit/PHPMatcherAssertionsTest.php</file>
</testsuite>
</testsuites>
<filter>
Expand Down
4 changes: 3 additions & 1 deletion src/PHPUnit/PHPMatcherConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ final class PHPMatcherConstraint extends Constraint

public function __construct(string $pattern)
{
parent::__construct();
if (\method_exists(Constraint::class, '__construct')) {
parent::__construct();
}

$this->pattern = $pattern;
$this->matcher = $this->createMatcher();
Expand Down
13 changes: 13 additions & 0 deletions tests/Matcher/JsonMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public static function negativePatterns()
return [
['@string@'],
['["Norbert", '],
['@[email protected]({"name": "@string@", "value": "@array@"})']
];
}

Expand Down Expand Up @@ -215,6 +216,14 @@ public static function positiveMatches()
[
'[{"name": "Norbert","lastName":"Orzechowicz"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
'[{"name": "Norbert","@*@":"@*@"},@...@]'
],
[
'[{"name": "Norbert"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
'@[email protected]({\"name\": \"@string@\"})'
],
[
'[{"name": "Norbert","lastName":"Orzechowicz"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
'@[email protected]({\"name\": \"@string@\",\"@*@\":\"@*@\"})'
]
];
}
Expand Down Expand Up @@ -242,6 +251,10 @@ public static function negativeMatches()
'{"foo":"foo val","bar":"bar val"}',
'{"foo":"foo val"}'
],
[
'[{"name": "Norbert","lastName":"Orzechowicz"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
'@[email protected]({\"name\": \"@string@\"})'
],
[
[],
'[]'
Expand Down