_generated\AcceptanceTesterActions::canSeeResponseMatchesJsonType PHP Method

canSeeResponseMatchesJsonType() public method

Checks that Json matches provided types. In case you don't know the actual values of JSON data returned you can match them by type. Starts check with a root element. If JSON data is array it will check the first element of an array. You can specify the path in the json which should be checked with JsonPath Basic example: php seeResponseMatchesJsonType([ 'user_id' => 'integer', 'name' => 'string|null', 'is_active' => 'boolean' ]); narrow down matching with JsonPath: {"users": [{ "name": "davert"}, {"id": 1}]} $I->seeResponseMatchesJsonType(['name' => 'string'], '$.users[0]'); ?> In this case you can match that record contains fields with data types you expected. The list of possible data types: * string * integer * float * array (json object is array as well) * boolean You can also use nested data type structures: php seeResponseMatchesJsonType([ 'user_id' => 'integer|string', // multiple types 'company' => ['name' => 'string'] ]); ?> You can also apply filters to check values. Filter can be applied with : char after the type declatation. Here is the list of possible filters: * integer:>{val} - checks that integer is greater than {val} (works with float and string types too). * integer:<{val} - checks that integer is lower than {val} (works with float and string types too). * string:url - checks that value is valid url. * string:date - checks that value is date in JavaScript format: https://weblog.west-wind.com/posts/2014/Jan/06/JavaScript-JSON-Date-Parsing-and-real-Dates * string:email - checks that value is a valid email according to http://emailregex.com/ * string:regex({val}) - checks that string matches a regex provided with {val} This is how filters can be used: php '[email protected]'} $I->seeResponseMatchesJsonType([ 'user_id' => 'string:>0:<1000', // multiple filters can be used 'email' => 'string:regex(~\@~)' // we just check that @ char is included ]); {'user_id': '1'} $I->seeResponseMatchesJsonType( 'user_id' => 'string:>0', // works with strings as well } ?> You can also add custom filters y accessing JsonType::addCustomFilter method. See [JsonType reference.
See also: Codeception\Module\REST::seeResponseMatchesJsonType()
public canSeeResponseMatchesJsonType ( array $jsonType, string $jsonPath = null )
$jsonType array
$jsonPath string Conditional Assertion: Test won't be stopped on fail
    public function canSeeResponseMatchesJsonType($jsonType, $jsonPath = null)
    {
        return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseMatchesJsonType', func_get_args()));
    }
AcceptanceTesterActions