Download the PHP package coduo/php-matcher without Composer
On this page you can find all versions of the php package coduo/php-matcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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 >= 8.1 <= 8.3
- 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
We Stand Against Terror
Stand With Ukraine | Stand With Us |
On Feb. 24, 2022, Russia declared an unprovoked war on Ukraine and launched a full-scale invasion. Russia is currently bombing peaceful Ukrainian cities, including schools and hospitals and attacking civilians who are fleeing conflict zones.
On Oct. 7, 2023, the national holiday of Simchat Torah, Hamas terrorists initiated an attack on Israel in the early hours, targeting civilians. They unleashed violence that resulted in at least 1,400 casualties and abducted at least 200 individuals, not limited to Israelis.
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 php-matcher with dependencies
ext-filter Version *
ext-json Version *
ext-simplexml Version *
aeon-php/calendar Version ^1.0.6
coduo/php-to-string Version ^3
doctrine/lexer Version ^3.0