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