GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — codeception.github.com/docs/reference/JsonType.md at master · ProFILE200/codeception.github.com

Expand file tree

/

JsonType.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
111 lines (65 loc) · 2.65 KB
/

JsonType.md

Copy path

File metadata and controls

111 lines (65 loc) · 2.65 KB
Raw
Copy raw file
Download raw file
Edit and raw actions
layout doc
title JsonType - Codeception - Documentation

Codeception\Util\JsonType

JsonType matches JSON structures against templates. You can specify the type of fields in JSON or add additional validation rules.

JsonType is used by REST module in seeResponseMatchesJsonType and dontSeeResponseMatchesJsonType methods.

Usage example:

{% highlight php %}

'davert', 'id' => 1]); $jsonType->matches([ 'name' => 'string:!empty', 'id' => 'integer:>0|string:>0', ]); // => true $jsonType->matches([ 'id' => 'string', ]); // => `id: 1` is not of type string {% endhighlight %} Class JsonType @package Codeception\Util #### __construct() *public* __construct($jsonArray) * `param ` $jsonArray array|JsonArray Creates instance of JsonType Pass an array or `\Codeception\Util\JsonArray` with data. If non-associative array is passed - the very first element of it will be used for matching. [See source](https://github.com/Codeception/module-rest/blob/master/src/Codeception/Util/JsonType.php#L47) #### addCustomFilter() *public static* addCustomFilter($name, callable $callable) * `param string` $name * `param callable` $callable * `return void` Adds custom filter to JsonType list. You should specify a name and parameters of a filter. Example: {% highlight php %} use it as 'string:slug' // add custom function to matcher with `len($val)` syntax // parameter matching patterns should be valid regex and start with `/` char JsonType::addCustomFilter('/len\((.*?)\)/', function($value, $len) { return strlen($value) == $len; }); // use it as 'string:len(5)' {% endhighlight %} [See source](https://github.com/Codeception/module-rest/blob/master/src/Codeception/Util/JsonType.php#L77) #### cleanCustomFilters() *public static* cleanCustomFilters() * `return void` Removes all custom filters [See source](https://github.com/Codeception/module-rest/blob/master/src/Codeception/Util/JsonType.php#L85) #### matches() *public* matches(array $jsonType) * `param array` $jsonType * `return string|bool` Checks data against passed JsonType. If matching fails function returns a string with a message describing failure. On success returns `true`. [See source](https://github.com/Codeception/module-rest/blob/master/src/Codeception/Util/JsonType.php#L95)

 

Reference is taken from the source code. Help us to improve documentation. Edit module reference
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.