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');
}
}