Download the PHP package sdobreff/json-response-test without Composer
On this page you can find all versions of the php package sdobreff/json-response-test. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sdobreff/json-response-test
More information about sdobreff/json-response-test
Files in sdobreff/json-response-test
Package json-response-test
Short Description Test JSON response against provided pattern in file
License MIT
Informations about the package json-response-test
json-response-test
JsonApiTest is a PHPUnit TestCase that will make your life as a PHP API developer much easier.
Thanks to PHP-Matcher you can, test you API JSON responses against provided schema.
Sandbox
You can use PHP-Matcher Sandbox, to create your JSON schema.
Installation
Assuming you already have Composer installed globally:
Usage
With this in place, any string under key message will match the pattern. More complicated expected response could look like this:
And will match the following list of products:
Available patterns
@string@
@integer@
@number@
@double@
@boolean@
@array@
@...@ - unbounded array
@null@
@*@ || @wildcard@
expr(expression) - optional, requires symfony/expression-language: ^2.3|^3.0|^4.0|^5.0 to be present
@uuid@
@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()
isEmail()
isUrl()
isIp()
isEmpty()
isNotEmpty()
lowerThan($boundry)
greaterThan($boundry)
inArray($value)
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 with ArrayMatcher, JsonMatcher and XmlMatcher
count() - work's only with ArrayMatcher - 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
Your test class
BaseApiTest for initializing the properties
All versions of json-response-test with dependencies
phpunit/phpunit Version ^7
coduo/php-matcher Version ^5.0
guzzlehttp/guzzle Version 6.*