mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Less Reflection on Validator, better tests for AllOf
This commit is contained in:
parent
71b510cd51
commit
b3cc2285fc
|
@ -10,6 +10,11 @@ abstract class AbstractRule implements Validatable
|
|||
|
||||
protected $exception;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function __invoke($input)
|
||||
{
|
||||
return $this->validate($input);
|
||||
|
|
|
@ -107,13 +107,9 @@ class Validator extends AllOf
|
|||
throw new ComponentException(
|
||||
sprintf(static::ERR_INTERFACE, $validatorFqn)
|
||||
);
|
||||
if ($validatorClass->hasMethod('__construct')) {
|
||||
$validatorInstance = $validatorClass->newInstanceArgs(
|
||||
$arguments
|
||||
);
|
||||
} else {
|
||||
$validatorInstance = new $validatorFqn;
|
||||
}
|
||||
$validatorInstance = $validatorClass->newInstanceArgs(
|
||||
$arguments
|
||||
);
|
||||
return $validatorInstance;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class AbstractRelatedTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedException OutOfBoundsException
|
||||
*/
|
||||
public function testAssertHasReference()
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ class AbstractRelatedTest extends \PHPUnit_Framework_TestCase
|
|||
'', null, true, false
|
||||
);
|
||||
//overriding exception cause mocks cant handle createException properly
|
||||
$mock->setException(new \InvalidArgumentException(''));
|
||||
$mock->setException(new \OutOfBoundsException(''));
|
||||
$this->assertFalse($mock->assert('bla'));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,11 +25,11 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedException Respect\Validation\Exceptions\AllOfException
|
||||
*/
|
||||
public function testInvalid()
|
||||
{
|
||||
$valid1 = new Callback(function() {
|
||||
$theInvalidOne = new Callback(function() {
|
||||
return false;
|
||||
});
|
||||
$valid2 = new Callback(function() {
|
||||
|
@ -38,8 +38,35 @@ class AllOfTest extends \PHPUnit_Framework_TestCase
|
|||
$valid3 = new Callback(function() {
|
||||
return true;
|
||||
});
|
||||
$o = new AllOf($valid1, $valid2, $valid3);
|
||||
$o = new AllOf($theInvalidOne, $valid2, $valid3);
|
||||
$this->assertFalse($o->assert('any'));
|
||||
$o = new AllOf($valid2, $theInvalidOne, $valid3);
|
||||
$this->assertFalse($o->assert('any'));
|
||||
$o = new AllOf($valid2, $valid3, $theInvalidOne);
|
||||
$this->assertFalse($o->assert('any'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException OutOfBoundsException
|
||||
*/
|
||||
public function testCheck()
|
||||
{
|
||||
$valid1 = new Callback(function() {
|
||||
return true;
|
||||
});
|
||||
$theInvalidOne = new Callback(function() {
|
||||
return false;
|
||||
});
|
||||
$valid3 = new Callback(function() {
|
||||
return true;
|
||||
});
|
||||
$theInvalidOne->setException(new \OutOfBoundsException(''));
|
||||
$o = new AllOf($valid1, $theInvalidOne, $valid3);
|
||||
$this->assertFalse($o->check('any'));
|
||||
$o = new AllOf($theInvalidOne, $valid3, $valid1);
|
||||
$this->assertFalse($o->check('any'));
|
||||
$o = new AllOf($valid3, $valid1, $theInvalidOne);
|
||||
$this->assertFalse($o->check('any'));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="true"
|
||||
bootstrap="bootstrap.php"
|
||||
|
|
Loading…
Reference in a new issue