mirror of
https://github.com/Intervention/image.git
synced 2025-08-26 15:24:37 +02:00
added "digit" as argument type
This commit is contained in:
@@ -117,6 +117,11 @@ class Argument
|
|||||||
$fail = ! is_a($value, '\Closure');
|
$fail = ! is_a($value, '\Closure');
|
||||||
$message = sprintf('%s accepts only Closure as argument %d.', $this->getCommandName(), $this->key + 1);
|
$message = sprintf('%s accepts only Closure as argument %d.', $this->getCommandName(), $this->key + 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'digit':
|
||||||
|
$fail = ! $this->isDigit($value);
|
||||||
|
$message = sprintf('%s accepts only digit values as argument %d.', $this->getCommandName(), $this->key + 1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fail) {
|
if ($fail) {
|
||||||
@@ -199,4 +204,9 @@ class Argument
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isDigit($value)
|
||||||
|
{
|
||||||
|
return is_numeric($value) ? intval($value) == $value : false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -69,6 +69,68 @@ class ArgumentTest extends PHPUnit_Framework_TestCase
|
|||||||
$arg->type('integer');
|
$arg->type('integer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTypeDigitPass()
|
||||||
|
{
|
||||||
|
$arg = new Argument($this->getMockedCommand(array()));
|
||||||
|
$arg->type('digit');
|
||||||
|
$this->validateArgument($arg, null);
|
||||||
|
|
||||||
|
$arg = new Argument($this->getMockedCommand(array(0)));
|
||||||
|
$arg->type('digit');
|
||||||
|
$this->validateArgument($arg, 0);
|
||||||
|
|
||||||
|
$arg = new Argument($this->getMockedCommand(array(123)));
|
||||||
|
$arg->type('digit');
|
||||||
|
$this->validateArgument($arg, 123);
|
||||||
|
|
||||||
|
$arg = new Argument($this->getMockedCommand(array(5.0)));
|
||||||
|
$arg->type('digit');
|
||||||
|
$this->validateArgument($arg, 5.0);
|
||||||
|
|
||||||
|
$arg = new Argument($this->getMockedCommand(array(-10)));
|
||||||
|
$arg->type('digit');
|
||||||
|
$this->validateArgument($arg, -10);
|
||||||
|
|
||||||
|
$arg = new Argument($this->getMockedCommand(array(-10.0)));
|
||||||
|
$arg->type('digit');
|
||||||
|
$this->validateArgument($arg, -10.0);
|
||||||
|
|
||||||
|
$arg = new Argument($this->getMockedCommand(array('12')));
|
||||||
|
$arg->type('digit');
|
||||||
|
$this->validateArgument($arg, '12');
|
||||||
|
|
||||||
|
$arg = new Argument($this->getMockedCommand(array('12.0')));
|
||||||
|
$arg->type('digit');
|
||||||
|
$this->validateArgument($arg, '12.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Intervention\Image\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testTypeDigitFailString()
|
||||||
|
{
|
||||||
|
$arg = new Argument($this->getMockedCommand(array('foo')));
|
||||||
|
$arg->type('digit');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Intervention\Image\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testTypeDigitFailFloat()
|
||||||
|
{
|
||||||
|
$arg = new Argument($this->getMockedCommand(array(12.5)));
|
||||||
|
$arg->type('digit');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Intervention\Image\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testTypeDigitFailBool()
|
||||||
|
{
|
||||||
|
$arg = new Argument($this->getMockedCommand(array(true)));
|
||||||
|
$arg->type('digit');
|
||||||
|
}
|
||||||
|
|
||||||
public function testTypeNumericPass()
|
public function testTypeNumericPass()
|
||||||
{
|
{
|
||||||
$arg = new Argument($this->getMockedCommand(array()));
|
$arg = new Argument($this->getMockedCommand(array()));
|
||||||
|
Reference in New Issue
Block a user