RestContext::fieldIsOfTypeWithValue PHP Méthode

fieldIsOfTypeWithValue() public méthode

public fieldIsOfTypeWithValue ( string $fieldName, string $type, string $fieldValue ) : void
$fieldName string
$type string
$fieldValue string
Résultat void
    public function fieldIsOfTypeWithValue($fieldName, $type, $fieldValue)
    {
        if ($this->responseIsJson) {
            if (new Step\Given("the response should contain field \"{$fieldName}\"")) {
                switch (strtolower($type)) {
                    case 'int':
                    case 'integer':
                        if (!preg_match('/^(0|[1-9]\\d*)$/', $fieldValue)) {
                            throw new \Exception(sprintf('Field "%s" is not of the correct type: %s!', $fieldName, $type));
                        }
                        // TODO: We didn't check if the value is as expected here.
                        break;
                    default:
                        throw new \Exception('Unsupported data type: ' . $type);
                        break;
                }
            }
        } else {
            return new Step\Then('the response is JSON');
        }
    }