Download the PHP package app-verk/php-matcher without Composer
On this page you can find all versions of the php package app-verk/php-matcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-matcher
AppVerk 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.
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@enum@
- used for PHP backend enums@tax_number@
- matches tax identification number(only PL format)@regon@
- matches registration number(only PL format)
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]()\"})"}
isOneOf(class)
- work's only withEnumMatcher
, as argument it accepts class name with namespace e.g.@[email protected]('App\Domain\OrderStatus::class')
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 AppVerk\PHPMatcher\PHPUnit\PHPMatcherAssertions
trait,
or extend the AppVerk\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.
All versions of 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 2.1.1
phpunit/phpunit Version ^11.0.0