Validation Package Testing

- Added More Unit Tests to Validation Classes
- Updated Logic accordingly
This commit is contained in:
japatel
2015-01-09 16:56:38 -06:00
parent 095ab24b62
commit f7cfd0faa9
6 changed files with 170 additions and 9 deletions

View File

@@ -16,18 +16,17 @@ class ArgumentValidator
* @param $argument mixed The object to be validated
* @param $argumentName string|null The name of the argument.
* This will be placed in the exception message for easy reference
* @return bool
*/
public static function validate($argument, $argumentName = null)
{
if (
$argument != null &&
((gettype($argument) == 'string' && $argument == '') || is_array($argument) && empty($argument))
) {
//Throw an Exception for string or array
throw new \InvalidArgumentException("$argumentName cannot be null or empty");
} elseif ($argument === null) {
//Generic Exception
if ($argument === null) {
// Error if Object Null
throw new \InvalidArgumentException("$argumentName cannot be null");
} else if (gettype($argument) == 'string' && trim($argument) == ''){
// Error if String Empty
throw new \InvalidArgumentException("$argumentName string cannot be empty");
}
return true;
}
}

View File

@@ -19,7 +19,7 @@ class JsonValidator
*/
public static function validate($string, $silent = false)
{
json_decode($string);
@json_decode($string);
if (json_last_error() != JSON_ERROR_NONE) {
if ($silent == false) {
//Throw an Exception for string or array

View File

@@ -24,6 +24,10 @@ class ModelAccessorValidator
{
$mode = PayPalConfigManager::getInstance()->get('validation.level');
if ($mode != 'disabled') {
//Check if $attributeName is string
if (gettype($attributeName) !== 'string') {
return false;
}
//If the mode is disabled, bypass the validation
foreach (array('set' . $attributeName, 'get' . $attributeName) as $methodName) {
if (get_class($class) == get_class(new PayPalModel())) {