Download the PHP package oldcodefork/coduo-php-matcher without Composer
On this page you can find all versions of the php package oldcodefork/coduo-php-matcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oldcodefork/coduo-php-matcher
More information about oldcodefork/coduo-php-matcher
Files in oldcodefork/coduo-php-matcher
Package coduo-php-matcher
Short Description PHP Matcher enables you to match values with patterns
License MIT
Informations about the package coduo-php-matcher
PHP Matcher
Library created for testing all kinds of JSON/XML/TXT/Scalar values against patterns.
API:
It was built to simplify API's functional testing.
- - 6.x README PHP >= 7.4 <= 8.1
- - 5.x README PHP >= 7.2 < 8.0
- - 5.0 README PHP >= 7.2 < 8.0
- - 4.0.* README PHP >= 7.2 < 8.0
- - 3.2.* README PHP >= 7.0 < 8.0
- - 3.1.* README PHP >= 7.0 < 8.0
Sandbox
Feel free to play first with Sandbox
Installation
Require new dev dependency using composer:
Basic usage
Direct PHPMatcher usage
PHPUnit extending PHPMatcherTestCase
PHPUnit using PHPMatcherAssertions trait
Available patterns
@string@
@integer@
@number@
@double@
@boolean@
@time@
@date@
@datetime@
@timezone@
||@tz
@array@
@array_previous@
- match next array element using pattern from previous element@array_previous_repeat@
- match all remaining array elements using pattern from previous element@...@
- unbounded array, once used matcher will skip any further array elements@null@
@*@
||@wildcard@
expr(expression)
- optional, requiressymfony/expression-language: ^2.3|^3.0|^4.0|^5.0
to be present@uuid@
@ulid@
@json@
@string@||@integer@
- string OR integer
Available pattern expanders
startsWith($stringBeginning, $ignoreCase = false)
endsWith($stringEnding, $ignoreCase = false)
contains($string, $ignoreCase = false)
notContains($string, $ignoreCase = false)
isDateTime()
isInDateFormat($format)
- example"@[email protected]('Y-m-d H:i:s')
before(string $date)
- example"@[email protected]().before(\"2020-01-01 00:00:00\")"
after(string $date)
- example"@[email protected]().after(\"2020-01-01 00:00:00\")"
isTzOffset()
isTzIdentifier()
isTzAbbreviation()
isEmail()
isUrl()
isIp()
isEmpty()
isNotEmpty()
lowerThan($boundry)
greaterThan($boundry)
inArray($value)
- example"@[email protected](\"ROLE_USER\")"
hasProperty($propertyName)
- example"@[email protected](\"property_name\")"
oneOf(...$expanders)
- example"@[email protected](contains('foo'), contains('bar'), contains('baz'))"
matchRegex($regex)
- example"@[email protected]('/^lorem.+/')"
optional()
- work's only withArrayMatcher
,JsonMatcher
andXmlMatcher
count()
- work's only withArrayMatcher
- example"@[email protected](5)"
repeat($pattern, $isStrict = true)
- example'@[email protected]({"name": "foe"})'
or"@[email protected]('@string@')"
match($pattern)
- example{"image":"@[email protected]({\"url\":\"@[email protected]()\"})"}
Example usage
Scalar matching
String matching
Time matching
Date matching
DateTime matching
TimeZone matching
Integer matching
Number matching
Double matching
Boolean matching
Wildcard matching
Expression matching
UUID matching
ULID matching
Array matching
Array Previous
@array_previous@ can also be used when matching JSON's and XML's
Array Previous Repeat
@array_previous_repeat@ can also be used when matching JSON's and XML's
Json matching
Json matching with unbounded arrays and objects
Xml matching
Optional - requires openlss/lib-array2xml: ^1.0
to be present.
Example scenario for api in behat using mongo.
PHPUnit integration
The assertMatchesPattern()
is a handy assertion that matches values in PHPUnit tests.
To use it either include the Coduo\PHPMatcher\PHPUnit\PHPMatcherAssertions
trait,
or extend the Coduo\PHPMatcher\PHPUnit\PHPMatcherTestCase
:
The matchesPattern()
method can be used in PHPUnit stubs or mocks:
License
This library is distributed under the MIT license. Please see the LICENSE file.
Credits
This lib was inspired by JSON Expressions gem && Behat RestExtension
All versions of coduo-php-matcher with dependencies
ext-filter Version *
ext-json Version *
ext-simplexml Version *
aeon-php/calendar Version ^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0 || ^0.18.0 || ^1.0
coduo/php-to-string Version ^3
doctrine/lexer Version ^1.0||^2.0