mirror of
https://github.com/Respect/Validation.git
synced 2024-06-29 10:40:24 +02:00
Update version of PHPUnit package
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
5150428b27
commit
966c510559
|
@ -20,5 +20,8 @@ $userValidator = v::attribute('name', v::stringType()->length(1, 32))
|
||||||
->attribute('birthdate', v::dateTime()->minAge(18));
|
->attribute('birthdate', v::dateTime()->minAge(18));
|
||||||
|
|
||||||
$userValidator->assert($user);
|
$userValidator->assert($user);
|
||||||
|
|
||||||
|
echo 'Nothing to fail';
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
Nothing to fail
|
||||||
|
|
46
tests/integration/rules/allOf.phpt
Normal file
46
tests/integration/rules/allOf.phpt
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
--CREDITS--
|
||||||
|
Edson Lima <dddwebdeveloper@gmail.com>
|
||||||
|
Henrique Moody <henriquemoody@gmail.com>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\AllOfException;
|
||||||
|
use Respect\Validation\Exceptions\ConsonantException;
|
||||||
|
use Respect\Validation\Exceptions\IntTypeException;
|
||||||
|
use Respect\Validation\Validator as v;
|
||||||
|
|
||||||
|
try {
|
||||||
|
v::not(v::allOf(v::intType(), v::positive()))->check(42);
|
||||||
|
} catch (IntTypeException $exception) {
|
||||||
|
echo $exception->getMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
v::allOf(v::stringType(), v::consonant())->check('Luke i\'m your father');
|
||||||
|
} catch (ConsonantException $exception) {
|
||||||
|
echo $exception->getMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
v::allOf(v::stringType(), v::consonant())->assert(42);
|
||||||
|
} catch (AllOfException $exception) {
|
||||||
|
echo $exception->getFullMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
v::not(v::allOf(v::stringType(), v::length(10)))->assert('Frank Zappa is fantastic');
|
||||||
|
} catch (AllOfException $exception) {
|
||||||
|
echo $exception->getFullMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
42 must not be of type integer
|
||||||
|
"Luke i'm your father" must contain only consonants
|
||||||
|
- All of the required rules must pass for 42
|
||||||
|
- 42 must be of type string
|
||||||
|
- 42 must contain only consonants
|
||||||
|
- "Frank Zappa is fantastic" must not be of type string
|
|
@ -1,20 +0,0 @@
|
||||||
--CREDITS--
|
|
||||||
Edson Lima <dddwebdeveloper@gmail.com>
|
|
||||||
Henrique Moody <henriquemoody@gmail.com>
|
|
||||||
--FILE--
|
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use Respect\Validation\Validator as v;
|
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
v::allOf(v::intVal(), v::positive())->assert(42);
|
|
||||||
v::allOf(v::intVal(), v::negative())->check(-42);
|
|
||||||
v::not(v::allOf(v::dateTime(), v::between('2014-12-01', '2014-12-12')))->assert('2012-01-01');
|
|
||||||
v::not(v::allOf(v::stringType(), v::consonant()))->check('I am Jack\'s smirking revenge');
|
|
||||||
?>
|
|
||||||
--EXPECT--
|
|
|
@ -1,21 +0,0 @@
|
||||||
--CREDITS--
|
|
||||||
Edson Lima <dddwebdeveloper@gmail.com>
|
|
||||||
Henrique Moody <henriquemoody@gmail.com>
|
|
||||||
--FILE--
|
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use Respect\Validation\Exceptions\ConsonantException;
|
|
||||||
use Respect\Validation\Validator as v;
|
|
||||||
|
|
||||||
try {
|
|
||||||
v::allOf(v::stringType(), v::consonant())->check('Luke i\'m your father');
|
|
||||||
} catch (ConsonantException $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
--EXPECT--
|
|
||||||
"Luke i'm your father" must contain only consonants
|
|
|
@ -1,23 +0,0 @@
|
||||||
--CREDITS--
|
|
||||||
Edson Lima <dddwebdeveloper@gmail.com>
|
|
||||||
Henrique Moody <henriquemoody@gmail.com>
|
|
||||||
--FILE--
|
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use Respect\Validation\Exceptions\AllOfException;
|
|
||||||
use Respect\Validation\Validator as v;
|
|
||||||
|
|
||||||
try {
|
|
||||||
v::allOf(v::stringType(), v::consonant())->assert(42);
|
|
||||||
} catch (AllOfException $e) {
|
|
||||||
echo $e->getFullMessage();
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
--EXPECT--
|
|
||||||
- All of the required rules must pass for 42
|
|
||||||
- 42 must be of type string
|
|
||||||
- 42 must contain only consonants
|
|
|
@ -1,21 +0,0 @@
|
||||||
--CREDITS--
|
|
||||||
Edson Lima <dddwebdeveloper@gmail.com>
|
|
||||||
Henrique Moody <henriquemoody@gmail.com>
|
|
||||||
--FILE--
|
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use Respect\Validation\Exceptions\IntTypeException;
|
|
||||||
use Respect\Validation\Validator as v;
|
|
||||||
|
|
||||||
try {
|
|
||||||
v::not(v::allOf(v::intType(), v::positive()))->check(42);
|
|
||||||
} catch (IntTypeException $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
--EXPECT--
|
|
||||||
42 must not be of type integer
|
|
|
@ -1,21 +0,0 @@
|
||||||
--CREDITS--
|
|
||||||
Edson Lima <dddwebdeveloper@gmail.com>
|
|
||||||
Henrique Moody <henriquemoody@gmail.com>
|
|
||||||
--FILE--
|
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use Respect\Validation\Exceptions\AllOfException;
|
|
||||||
use Respect\Validation\Validator as v;
|
|
||||||
|
|
||||||
try {
|
|
||||||
v::not(v::allOf(v::stringType(), v::length(10)))->assert('Frank Zappa is fantastic');
|
|
||||||
} catch (AllOfException $e) {
|
|
||||||
echo $e->getFullMessage();
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
--EXPECT--
|
|
||||||
- "Frank Zappa is fantastic" must not be of type string
|
|
|
@ -12,27 +12,31 @@ use Respect\Validation\Exceptions\NestedValidationException;
|
||||||
use Respect\Validation\Validator as v;
|
use Respect\Validation\Validator as v;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
v::greaterThan(12)->check(21);
|
v::greaterThan(21)->check(12);
|
||||||
} catch (GreaterThanException $exception) {
|
} catch (GreaterThanException $exception) {
|
||||||
echo $exception->getMessage() . PHP_EOL;
|
echo $exception->getMessage() . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
v::not(v::greaterThan('today'))->check('yesterday');
|
v::not(v::greaterThan('yesterday'))->check('today');
|
||||||
} catch (GreaterThanException $exception) {
|
} catch (GreaterThanException $exception) {
|
||||||
echo $exception->getMessage() . PHP_EOL;
|
echo $exception->getMessage() . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
v::greaterThan('1988-09-09')->assert('2018-09-09');
|
v::greaterThan('2018-09-09')->assert('1988-09-09');
|
||||||
} catch (NestedValidationException $exception) {
|
} catch (NestedValidationException $exception) {
|
||||||
echo $exception->getFullMessage() . PHP_EOL;
|
echo $exception->getFullMessage() . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
v::not(v::greaterThan('b'))->assert('a');
|
v::not(v::greaterThan('a'))->assert('ba');
|
||||||
} catch (NestedValidationException $exception) {
|
} catch (NestedValidationException $exception) {
|
||||||
echo $exception->getFullMessage() . PHP_EOL;
|
echo $exception->getFullMessage() . PHP_EOL;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
12 must be greater than 21
|
||||||
|
"today" must not be greater than "yesterday"
|
||||||
|
- "1988-09-09" must be greater than "2018-09-09"
|
||||||
|
- "ba" must not be greater than "a"
|
||||||
|
|
|
@ -76,11 +76,6 @@ abstract class RuleTestCase extends TestCase
|
||||||
{
|
{
|
||||||
$validatableMocked = $this->getMockBuilder(Validatable::class)
|
$validatableMocked = $this->getMockBuilder(Validatable::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->setMethods(
|
|
||||||
[
|
|
||||||
'assert', 'check', 'getName', 'reportError', 'setName', 'setTemplate', 'validate',
|
|
||||||
]
|
|
||||||
)
|
|
||||||
->setMockClassName($mockClassName)
|
->setMockClassName($mockClassName)
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -92,12 +87,10 @@ abstract class RuleTestCase extends TestCase
|
||||||
if ($expectedResult) {
|
if ($expectedResult) {
|
||||||
$validatableMocked
|
$validatableMocked
|
||||||
->expects(self::any())
|
->expects(self::any())
|
||||||
->method('check')
|
->method('check');
|
||||||
->willReturn($expectedResult);
|
|
||||||
$validatableMocked
|
$validatableMocked
|
||||||
->expects(self::any())
|
->expects(self::any())
|
||||||
->method('assert')
|
->method('assert');
|
||||||
->willReturn($expectedResult);
|
|
||||||
} else {
|
} else {
|
||||||
$checkException = new ValidationException(
|
$checkException = new ValidationException(
|
||||||
'validatable',
|
'validatable',
|
||||||
|
|
|
@ -46,7 +46,6 @@ final class AbstractCompositeTest extends TestCase
|
||||||
|
|
||||||
$sut = $this
|
$sut = $this
|
||||||
->getMockBuilder(AbstractComposite::class)
|
->getMockBuilder(AbstractComposite::class)
|
||||||
->setMethods(['validate'])
|
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$sut->setName($ruleName);
|
$sut->setName($ruleName);
|
||||||
|
@ -63,26 +62,17 @@ final class AbstractCompositeTest extends TestCase
|
||||||
|
|
||||||
$rule = $this->createMock(Validatable::class);
|
$rule = $this->createMock(Validatable::class);
|
||||||
$rule
|
$rule
|
||||||
->expects(self::at(0))
|
->expects(self::exactly(2))
|
||||||
->method('getName')
|
->method('getName')
|
||||||
->will(self::returnValue(null));
|
->willReturnOnConsecutiveCalls(
|
||||||
$rule
|
null,
|
||||||
->expects(self::at(2))
|
$ruleName1
|
||||||
->method('getName')
|
);
|
||||||
->will(self::returnValue($ruleName1));
|
|
||||||
$rule
|
|
||||||
->expects(self::at(1))
|
|
||||||
->method('setName')
|
|
||||||
->with($ruleName1);
|
|
||||||
$rule
|
|
||||||
->expects(self::at(3))
|
|
||||||
->method('setName')
|
|
||||||
->with($ruleName2);
|
|
||||||
|
|
||||||
$sut = $this
|
$sut = $this
|
||||||
->getMockBuilder(AbstractComposite::class)
|
->getMockBuilder(AbstractComposite::class)
|
||||||
->setMethods(['validate'])
|
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$sut->setName($ruleName1);
|
$sut->setName($ruleName1);
|
||||||
$sut->addRule($rule);
|
$sut->addRule($rule);
|
||||||
$sut->setName($ruleName2);
|
$sut->setName($ruleName2);
|
||||||
|
@ -104,7 +94,6 @@ final class AbstractCompositeTest extends TestCase
|
||||||
|
|
||||||
$sut = $this
|
$sut = $this
|
||||||
->getMockBuilder(AbstractComposite::class)
|
->getMockBuilder(AbstractComposite::class)
|
||||||
->setMethods(['validate'])
|
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
$sut->addRule($rule);
|
$sut->addRule($rule);
|
||||||
$sut->setName('Whatever');
|
$sut->setName('Whatever');
|
||||||
|
@ -129,7 +118,6 @@ final class AbstractCompositeTest extends TestCase
|
||||||
|
|
||||||
$sut = $this
|
$sut = $this
|
||||||
->getMockBuilder(AbstractComposite::class)
|
->getMockBuilder(AbstractComposite::class)
|
||||||
->setMethods(['validate'])
|
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$sut->addRule($rule);
|
$sut->addRule($rule);
|
||||||
|
@ -155,7 +143,6 @@ final class AbstractCompositeTest extends TestCase
|
||||||
|
|
||||||
$sut = $this
|
$sut = $this
|
||||||
->getMockBuilder(AbstractComposite::class)
|
->getMockBuilder(AbstractComposite::class)
|
||||||
->setMethods(['validate'])
|
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$sut->addRule($rule);
|
$sut->addRule($rule);
|
||||||
|
@ -180,7 +167,6 @@ final class AbstractCompositeTest extends TestCase
|
||||||
|
|
||||||
$sut = $this
|
$sut = $this
|
||||||
->getMockBuilder(AbstractComposite::class)
|
->getMockBuilder(AbstractComposite::class)
|
||||||
->setMethods(['validate'])
|
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$sut->addRule($rule);
|
$sut->addRule($rule);
|
||||||
|
|
|
@ -50,7 +50,6 @@ final class AbstractRuleTest extends TestCase
|
||||||
|
|
||||||
$abstractRuleMock = $this
|
$abstractRuleMock = $this
|
||||||
->getMockBuilder(AbstractRule::class)
|
->getMockBuilder(AbstractRule::class)
|
||||||
->setMethods(['validate'])
|
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$abstractRuleMock
|
$abstractRuleMock
|
||||||
|
@ -79,7 +78,7 @@ final class AbstractRuleTest extends TestCase
|
||||||
|
|
||||||
$abstractRuleMock = $this
|
$abstractRuleMock = $this
|
||||||
->getMockBuilder(AbstractRule::class)
|
->getMockBuilder(AbstractRule::class)
|
||||||
->setMethods(['validate', 'reportError'])
|
->onlyMethods(['validate', 'reportError'])
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$abstractRuleMock
|
$abstractRuleMock
|
||||||
|
@ -97,17 +96,22 @@ final class AbstractRuleTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Respect\Validation\Rules\AbstractRule::assert
|
* @covers \Respect\Validation\Rules\AbstractRule::assert
|
||||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function assertInvokesValidateAndReportErrorOnFailure(): void
|
public function assertInvokesValidateAndReportErrorOnFailure(): void
|
||||||
{
|
{
|
||||||
$input = 'something';
|
$input = 'something';
|
||||||
|
$exception = new ValidationException(
|
||||||
|
$input,
|
||||||
|
'abstract',
|
||||||
|
[],
|
||||||
|
new Formatter('strval', new KeepOriginalStringName())
|
||||||
|
);
|
||||||
|
|
||||||
$abstractRuleMock = $this
|
$abstractRuleMock = $this
|
||||||
->getMockBuilder(AbstractRule::class)
|
->getMockBuilder(AbstractRule::class)
|
||||||
->setMethods(['validate', 'reportError'])
|
->onlyMethods(['validate', 'reportError'])
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$abstractRuleMock
|
$abstractRuleMock
|
||||||
|
@ -120,9 +124,9 @@ final class AbstractRuleTest extends TestCase
|
||||||
->expects(self::once())
|
->expects(self::once())
|
||||||
->method('reportError')
|
->method('reportError')
|
||||||
->with($input)
|
->with($input)
|
||||||
->will(self::throwException(
|
->will(self::throwException($exception));
|
||||||
new ValidationException($input, 'abstract', [], new Formatter('strval', new KeepOriginalStringName()))
|
|
||||||
));
|
$this->expectExceptionObject($exception);
|
||||||
|
|
||||||
$abstractRuleMock->assert($input);
|
$abstractRuleMock->assert($input);
|
||||||
}
|
}
|
||||||
|
@ -138,7 +142,7 @@ final class AbstractRuleTest extends TestCase
|
||||||
|
|
||||||
$abstractRuleMock = $this
|
$abstractRuleMock = $this
|
||||||
->getMockBuilder(AbstractRule::class)
|
->getMockBuilder(AbstractRule::class)
|
||||||
->setMethods(['assert'])
|
->onlyMethods(['assert'])
|
||||||
->getMockForAbstractClass();
|
->getMockForAbstractClass();
|
||||||
|
|
||||||
$abstractRuleMock
|
$abstractRuleMock
|
||||||
|
|
|
@ -13,6 +13,9 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\AllOfException;
|
||||||
|
use Respect\Validation\Exceptions\CallbackException;
|
||||||
|
use Respect\Validation\Exceptions\ValidationException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
use Respect\Validation\Validatable;
|
use Respect\Validation\Validatable;
|
||||||
|
|
||||||
|
@ -53,7 +56,6 @@ final class AllOfTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerStaticDummyRules
|
* @dataProvider providerStaticDummyRules
|
||||||
* @expectedException \Respect\Validation\Exceptions\AllOfException
|
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
@ -64,12 +66,13 @@ final class AllOfTest extends TestCase
|
||||||
): void {
|
): void {
|
||||||
$o = new AllOf($rule1, $rule2, $rule3);
|
$o = new AllOf($rule1, $rule2, $rule3);
|
||||||
self::assertFalse($o->__invoke('any'));
|
self::assertFalse($o->__invoke('any'));
|
||||||
|
|
||||||
|
$this->expectException(AllOfException::class);
|
||||||
$o->assert('any');
|
$o->assert('any');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerStaticDummyRules
|
* @dataProvider providerStaticDummyRules
|
||||||
* @expectedException \Respect\Validation\Exceptions\CallbackException
|
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
@ -80,12 +83,14 @@ final class AllOfTest extends TestCase
|
||||||
): void {
|
): void {
|
||||||
$o = new AllOf($rule1, $rule2, $rule3);
|
$o = new AllOf($rule1, $rule2, $rule3);
|
||||||
self::assertFalse($o->__invoke('any'));
|
self::assertFalse($o->__invoke('any'));
|
||||||
|
|
||||||
|
$this->expectException(CallbackException::class);
|
||||||
$o->check('any');
|
$o->check('any');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerStaticDummyRules
|
* @dataProvider providerStaticDummyRules
|
||||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
* @expectedException \Respect\Validation\Exceptions\
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
@ -95,6 +100,8 @@ final class AllOfTest extends TestCase
|
||||||
Validatable $rule3
|
Validatable $rule3
|
||||||
): void {
|
): void {
|
||||||
$o = new AllOf($rule1, $rule2, $rule3);
|
$o = new AllOf($rule1, $rule2, $rule3);
|
||||||
|
|
||||||
|
$this->expectException(ValidationException::class);
|
||||||
$o->check('');
|
$o->check('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\AnyOfException;
|
||||||
|
use Respect\Validation\Exceptions\XdigitException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,8 +49,6 @@ final class AnyOfTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\AnyOfException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalid(): void
|
public function invalid(): void
|
||||||
|
@ -64,18 +64,20 @@ final class AnyOfTest extends TestCase
|
||||||
});
|
});
|
||||||
$o = new AnyOf($valid1, $valid2, $valid3);
|
$o = new AnyOf($valid1, $valid2, $valid3);
|
||||||
self::assertFalse($o->validate('any'));
|
self::assertFalse($o->validate('any'));
|
||||||
|
|
||||||
|
$this->expectException(AnyOfException::class);
|
||||||
$o->assert('any');
|
$o->assert('any');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\XdigitException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalidCheck(): void
|
public function invalidCheck(): void
|
||||||
{
|
{
|
||||||
$o = new AnyOf(new Xdigit(), new Alnum());
|
$o = new AnyOf(new Xdigit(), new Alnum());
|
||||||
self::assertFalse($o->validate(-10));
|
self::assertFalse($o->validate(-10));
|
||||||
|
|
||||||
|
$this->expectException(XdigitException::class);
|
||||||
$o->check(-10);
|
$o->check(-10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ declare(strict_types=1);
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
use Respect\Validation\Test\Stubs\CountableStub;
|
use Respect\Validation\Test\Stubs\CountableStub;
|
||||||
|
|
||||||
|
@ -67,23 +68,21 @@ final class BetweenTest extends RuleTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage Minimum cannot be less than or equals to maximum
|
|
||||||
*/
|
*/
|
||||||
public function minimumValueShouldNotBeGreaterThanMaximumValue(): void
|
public function minimumValueShouldNotBeGreaterThanMaximumValue(): void
|
||||||
{
|
{
|
||||||
|
$this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum'));
|
||||||
|
|
||||||
new Between(10, 5);
|
new Between(10, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage Minimum cannot be less than or equals to maximum
|
|
||||||
*/
|
*/
|
||||||
public function minimumValueShouldNotBeEqualsToMaximumValue(): void
|
public function minimumValueShouldNotBeEqualsToMaximumValue(): void
|
||||||
{
|
{
|
||||||
|
$this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum'));
|
||||||
|
|
||||||
new Between(5, 5);
|
new Between(5, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
|
|
||||||
use function mb_convert_encoding;
|
use function mb_convert_encoding;
|
||||||
|
@ -31,12 +32,12 @@ final class CharsetTest extends RuleTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage Invalid charset
|
|
||||||
*/
|
*/
|
||||||
public function itShouldThrowsExceptionWhenCharsetIsNotValid(): void
|
public function itShouldThrowsExceptionWhenCharsetIsNotValid(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('Invalid charset');
|
||||||
|
|
||||||
new Charset('UTF-8', 'UTF-9');
|
new Charset('UTF-8', 'UTF-9');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,12 +30,14 @@ final class CountryCodeTest extends RuleTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage "whatever" is not a valid set for ISO 3166-1 (Available: alpha-2, alpha-3, numeric)
|
|
||||||
*/
|
*/
|
||||||
public function itShouldThrowsExceptionWhenInvalidFormat(): void
|
public function itShouldThrowsExceptionWhenInvalidFormat(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage(
|
||||||
|
'"whatever" is not a valid set for ISO 3166-1 (Available: alpha-2, alpha-3, numeric)'
|
||||||
|
);
|
||||||
|
|
||||||
new CountryCode('whatever');
|
new CountryCode('whatever');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,19 +73,10 @@ final class EachTest extends RuleTestCase
|
||||||
public function itShouldAssertEachValue(): void
|
public function itShouldAssertEachValue(): void
|
||||||
{
|
{
|
||||||
$validatable = $this->createMock(Validatable::class);
|
$validatable = $this->createMock(Validatable::class);
|
||||||
|
|
||||||
$validatable
|
$validatable
|
||||||
->expects(self::at(0))
|
->expects(self::exactly(3))
|
||||||
->method('assert')
|
->method('assert')
|
||||||
->with(1);
|
->withConsecutive([1], [2], [3]);
|
||||||
$validatable
|
|
||||||
->expects(self::at(1))
|
|
||||||
->method('assert')
|
|
||||||
->with(2);
|
|
||||||
$validatable
|
|
||||||
->expects(self::at(2))
|
|
||||||
->method('assert')
|
|
||||||
->with(3);
|
|
||||||
|
|
||||||
$rule = new Each($validatable);
|
$rule = new Each($validatable);
|
||||||
$rule->assert(range(1, 3));
|
$rule->assert(range(1, 3));
|
||||||
|
@ -97,19 +88,10 @@ final class EachTest extends RuleTestCase
|
||||||
public function itShouldCheckEachValue(): void
|
public function itShouldCheckEachValue(): void
|
||||||
{
|
{
|
||||||
$validatable = $this->createMock(Validatable::class);
|
$validatable = $this->createMock(Validatable::class);
|
||||||
|
|
||||||
$validatable
|
$validatable
|
||||||
->expects(self::at(0))
|
->expects(self::exactly(3))
|
||||||
->method('check')
|
->method('check')
|
||||||
->with(1);
|
->withConsecutive([1], [2], [3]);
|
||||||
$validatable
|
|
||||||
->expects(self::at(1))
|
|
||||||
->method('check')
|
|
||||||
->with(2);
|
|
||||||
$validatable
|
|
||||||
->expects(self::at(2))
|
|
||||||
->method('check')
|
|
||||||
->with(3);
|
|
||||||
|
|
||||||
$rule = new Each($validatable);
|
$rule = new Each($validatable);
|
||||||
$rule->check(range(1, 3));
|
$rule->check(range(1, 3));
|
||||||
|
|
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
|
|
||||||
use const FILTER_FLAG_HOSTNAME;
|
use const FILTER_FLAG_HOSTNAME;
|
||||||
|
@ -38,12 +39,12 @@ final class FilterVarTest extends RuleTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage Cannot accept the given filter
|
|
||||||
*/
|
*/
|
||||||
public function itShouldThrowsExceptionWhenFilterIsNotValid(): void
|
public function itShouldThrowsExceptionWhenFilterIsNotValid(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('Cannot accept the given filter');
|
||||||
|
|
||||||
new FilterVar(FILTER_SANITIZE_EMAIL);
|
new FilterVar(FILTER_SANITIZE_EMAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ declare(strict_types=1);
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
|
use Respect\Validation\Exceptions\KeyNestedException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
use Respect\Validation\Validatable;
|
use Respect\Validation\Validatable;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
@ -124,24 +125,22 @@ final class KeyNestedTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeyNestedException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function emptyInputMustNotAssert(): void
|
public function emptyInputMustNotAssert(): void
|
||||||
{
|
{
|
||||||
$rule = new KeyNested('bar.foo.baz');
|
$rule = new KeyNested('bar.foo.baz');
|
||||||
|
$this->expectException(KeyNestedException::class);
|
||||||
$rule->assert('');
|
$rule->assert('');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeyNestedException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function emptyInputMustNotCheck(): void
|
public function emptyInputMustNotCheck(): void
|
||||||
{
|
{
|
||||||
$rule = new KeyNested('bar.foo.baz');
|
$rule = new KeyNested('bar.foo.baz');
|
||||||
|
$this->expectException(KeyNestedException::class);
|
||||||
$rule->check('');
|
$rule->check('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +156,6 @@ final class KeyNestedTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeyNestedException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function arrayWithAbsentKeyShouldThrowNestedKeyException(): void
|
public function arrayWithAbsentKeyShouldThrowNestedKeyException(): void
|
||||||
|
@ -169,18 +166,18 @@ final class KeyNestedTest extends TestCase
|
||||||
'bar' => 'foo',
|
'bar' => 'foo',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
$this->expectException(KeyNestedException::class);
|
||||||
$validator->assert($object);
|
$validator->assert($object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeyNestedException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function notArrayShouldThrowKeyException(): void
|
public function notArrayShouldThrowKeyException(): void
|
||||||
{
|
{
|
||||||
$validator = new KeyNested('baz.bar');
|
$validator = new KeyNested('baz.bar');
|
||||||
$object = 123;
|
$object = 123;
|
||||||
|
$this->expectException(KeyNestedException::class);
|
||||||
$validator->assert($object);
|
$validator->assert($object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
|
use Respect\Validation\Exceptions\KeySetException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
|
@ -29,9 +31,6 @@ final class KeySetTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage KeySet rule accepts only Key rules
|
|
||||||
*/
|
*/
|
||||||
public function shouldNotAcceptAllOfWithMoreThanOneKeyRule(): void
|
public function shouldNotAcceptAllOfWithMoreThanOneKeyRule(): void
|
||||||
{
|
{
|
||||||
|
@ -39,33 +38,36 @@ final class KeySetTest extends TestCase
|
||||||
$key2 = new Key('bar', new AlwaysValid(), false);
|
$key2 = new Key('bar', new AlwaysValid(), false);
|
||||||
$allOf = new AllOf($key1, $key2);
|
$allOf = new AllOf($key1, $key2);
|
||||||
|
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('KeySet rule accepts only Key rules');
|
||||||
|
|
||||||
new KeySet($allOf);
|
new KeySet($allOf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage KeySet rule accepts only Key rules
|
|
||||||
*/
|
*/
|
||||||
public function shouldNotAcceptAllOfWithNonKeyRule(): void
|
public function shouldNotAcceptAllOfWithNonKeyRule(): void
|
||||||
{
|
{
|
||||||
$alwaysValid = new AlwaysValid();
|
$alwaysValid = new AlwaysValid();
|
||||||
$allOf = new AllOf($alwaysValid);
|
$allOf = new AllOf($alwaysValid);
|
||||||
|
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('KeySet rule accepts only Key rules');
|
||||||
|
|
||||||
new KeySet($allOf);
|
new KeySet($allOf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage KeySet rule accepts only Key rules
|
|
||||||
*/
|
*/
|
||||||
public function shouldNotAcceptNonKeyRule(): void
|
public function shouldNotAcceptNonKeyRule(): void
|
||||||
{
|
{
|
||||||
$alwaysValid = new AlwaysValid();
|
$alwaysValid = new AlwaysValid();
|
||||||
|
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('KeySet rule accepts only Key rules');
|
||||||
|
|
||||||
new KeySet($alwaysValid);
|
new KeySet($alwaysValid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,9 +141,6 @@ final class KeySetTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeySetException
|
|
||||||
* @expectedExceptionMessage Must have keys `{ "foo", "bar" }`
|
|
||||||
*/
|
*/
|
||||||
public function shouldCheckKeys(): void
|
public function shouldCheckKeys(): void
|
||||||
{
|
{
|
||||||
|
@ -151,14 +150,15 @@ final class KeySetTest extends TestCase
|
||||||
$key2 = new Key('bar', new AlwaysValid(), true);
|
$key2 = new Key('bar', new AlwaysValid(), true);
|
||||||
|
|
||||||
$keySet = new KeySet($key1, $key2);
|
$keySet = new KeySet($key1, $key2);
|
||||||
|
|
||||||
|
$this->expectException(KeySetException::class);
|
||||||
|
$this->expectExceptionMessage('Must have keys `{ "foo", "bar" }`');
|
||||||
|
|
||||||
$keySet->check($input);
|
$keySet->check($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*
|
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeySetException
|
|
||||||
* @expectedExceptionMessage Must have keys `{ "foo", "bar" }`
|
|
||||||
*/
|
*/
|
||||||
public function shouldAssertKeys(): void
|
public function shouldAssertKeys(): void
|
||||||
{
|
{
|
||||||
|
@ -168,6 +168,10 @@ final class KeySetTest extends TestCase
|
||||||
$key2 = new Key('bar', new AlwaysValid(), true);
|
$key2 = new Key('bar', new AlwaysValid(), true);
|
||||||
|
|
||||||
$keySet = new KeySet($key1, $key2);
|
$keySet = new KeySet($key1, $key2);
|
||||||
|
|
||||||
|
$this->expectException(KeySetException::class);
|
||||||
|
$this->expectExceptionMessage('Must have keys `{ "foo", "bar" }`');
|
||||||
|
|
||||||
$keySet->assert($input);
|
$keySet->assert($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,14 +180,15 @@ final class KeySetTest extends TestCase
|
||||||
*
|
*
|
||||||
* @dataProvider providerForInvalidArguments
|
* @dataProvider providerForInvalidArguments
|
||||||
*
|
*
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeySetException
|
|
||||||
* @expectedExceptionMessage Must have keys `{ "name" }`
|
|
||||||
*
|
|
||||||
* @param mixed $input
|
* @param mixed $input
|
||||||
*/
|
*/
|
||||||
public function shouldThrowExceptionInCaseArgumentIsAnythingOtherThanArray($input): void
|
public function shouldThrowExceptionInCaseArgumentIsAnythingOtherThanArray($input): void
|
||||||
{
|
{
|
||||||
$keySet = new KeySet(new Key('name'));
|
$keySet = new KeySet(new Key('name'));
|
||||||
|
|
||||||
|
$this->expectException(KeySetException::class);
|
||||||
|
$this->expectExceptionMessage('Must have keys `{ "name" }`');
|
||||||
|
|
||||||
$keySet->assert($input);
|
$keySet->assert($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
|
use Respect\Validation\Exceptions\KeyException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
|
@ -62,24 +64,26 @@ final class KeyTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeyException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function emptyInputMustNotAssert(): void
|
public function emptyInputMustNotAssert(): void
|
||||||
{
|
{
|
||||||
$validator = new Key('someEmptyKey');
|
$validator = new Key('someEmptyKey');
|
||||||
|
|
||||||
|
$this->expectException(KeyException::class);
|
||||||
|
|
||||||
$validator->assert('');
|
$validator->assert('');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeyException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function emptyInputMustNotCheck(): void
|
public function emptyInputMustNotCheck(): void
|
||||||
{
|
{
|
||||||
$validator = new Key('someEmptyKey');
|
$validator = new Key('someEmptyKey');
|
||||||
|
|
||||||
|
$this->expectException(KeyException::class);
|
||||||
|
|
||||||
$validator->check('');
|
$validator->check('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,8 +123,6 @@ final class KeyTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeyException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function arrayWithAbsentKeyShouldThrowKeyException(): void
|
public function arrayWithAbsentKeyShouldThrowKeyException(): void
|
||||||
|
@ -128,28 +130,32 @@ final class KeyTest extends TestCase
|
||||||
$validator = new Key('bar');
|
$validator = new Key('bar');
|
||||||
$someArray = [];
|
$someArray = [];
|
||||||
$someArray['baraaaaaa'] = 'foo';
|
$someArray['baraaaaaa'] = 'foo';
|
||||||
|
|
||||||
|
$this->expectException(KeyException::class);
|
||||||
|
|
||||||
$validator->assert($someArray);
|
$validator->assert($someArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\KeyException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function notArrayShouldThrowKeyException(): void
|
public function notArrayShouldThrowKeyException(): void
|
||||||
{
|
{
|
||||||
$validator = new Key('bar');
|
$validator = new Key('bar');
|
||||||
$someArray = 123;
|
$someArray = 123;
|
||||||
|
|
||||||
|
$this->expectException(KeyException::class);
|
||||||
|
|
||||||
$validator->assert($someArray);
|
$validator->assert($someArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalidConstructorParametersShouldThrowComponentExceptionUponInstantiation(): void
|
public function invalidConstructorParametersShouldThrowComponentExceptionUponInstantiation(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
|
||||||
new Key(['invalid']);
|
new Key(['invalid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ final class MimetypeTest extends RuleTestCase
|
||||||
$fileInfoMock = $this
|
$fileInfoMock = $this
|
||||||
->getMockBuilder(finfo::class)
|
->getMockBuilder(finfo::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->setMethods(['file'])
|
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$fileInfoMock
|
$fileInfoMock
|
||||||
|
|
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\NoneOfException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,8 +48,6 @@ final class NoneOfTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\NoneOfException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalid(): void
|
public function invalid(): void
|
||||||
|
@ -64,6 +63,8 @@ final class NoneOfTest extends TestCase
|
||||||
});
|
});
|
||||||
$o = new NoneOf($valid1, $valid2, $valid3);
|
$o = new NoneOf($valid1, $valid2, $valid3);
|
||||||
self::assertFalse($o->validate('any'));
|
self::assertFalse($o->validate('any'));
|
||||||
|
|
||||||
|
$this->expectException(NoneOfException::class);
|
||||||
$o->assert('any');
|
$o->assert('any');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ValidationException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
use Respect\Validation\Validatable;
|
use Respect\Validation\Validatable;
|
||||||
use Respect\Validation\Validator;
|
use Respect\Validation\Validator;
|
||||||
|
@ -46,7 +47,6 @@ final class NotTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerForInvalidNot
|
* @dataProvider providerForInvalidNot
|
||||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
*
|
*
|
||||||
|
@ -55,6 +55,9 @@ final class NotTest extends TestCase
|
||||||
public function notNotHaha(Validatable $rule, $input): void
|
public function notNotHaha(Validatable $rule, $input): void
|
||||||
{
|
{
|
||||||
$not = new Not($rule);
|
$not = new Not($rule);
|
||||||
|
|
||||||
|
$this->expectException(ValidationException::class);
|
||||||
|
|
||||||
$not->assert($input);
|
$not->assert($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,9 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\CallbackException;
|
||||||
|
use Respect\Validation\Exceptions\OneOfException;
|
||||||
|
use Respect\Validation\Exceptions\XdigitException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,8 +52,6 @@ final class OneOfTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\OneOfException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function emptyChain(): void
|
public function emptyChain(): void
|
||||||
|
@ -58,12 +59,13 @@ final class OneOfTest extends TestCase
|
||||||
$rule = new OneOf();
|
$rule = new OneOf();
|
||||||
|
|
||||||
self::assertFalse($rule->validate('any'));
|
self::assertFalse($rule->validate('any'));
|
||||||
|
|
||||||
|
$this->expectException(OneOfException::class);
|
||||||
|
|
||||||
$rule->check('any');
|
$rule->check('any');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\OneOfException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalid(): void
|
public function invalid(): void
|
||||||
|
@ -79,12 +81,12 @@ final class OneOfTest extends TestCase
|
||||||
});
|
});
|
||||||
$rule = new OneOf($valid1, $valid2, $valid3);
|
$rule = new OneOf($valid1, $valid2, $valid3);
|
||||||
self::assertFalse($rule->validate('any'));
|
self::assertFalse($rule->validate('any'));
|
||||||
|
|
||||||
|
$this->expectException(OneOfException::class);
|
||||||
$rule->assert('any');
|
$rule->assert('any');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\OneOfException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalidMultipleAssert(): void
|
public function invalidMultipleAssert(): void
|
||||||
|
@ -101,12 +103,11 @@ final class OneOfTest extends TestCase
|
||||||
$rule = new OneOf($valid1, $valid2, $valid3);
|
$rule = new OneOf($valid1, $valid2, $valid3);
|
||||||
self::assertFalse($rule->validate('any'));
|
self::assertFalse($rule->validate('any'));
|
||||||
|
|
||||||
|
$this->expectException(OneOfException::class);
|
||||||
$rule->assert('any');
|
$rule->assert('any');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\CallbackException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalidMultipleCheck(): void
|
public function invalidMultipleCheck(): void
|
||||||
|
@ -124,12 +125,11 @@ final class OneOfTest extends TestCase
|
||||||
$rule = new OneOf($valid1, $valid2, $valid3);
|
$rule = new OneOf($valid1, $valid2, $valid3);
|
||||||
self::assertFalse($rule->validate('any'));
|
self::assertFalse($rule->validate('any'));
|
||||||
|
|
||||||
|
$this->expectException(CallbackException::class);
|
||||||
$rule->check('any');
|
$rule->check('any');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\OneOfException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalidMultipleCheckAllValid(): void
|
public function invalidMultipleCheckAllValid(): void
|
||||||
|
@ -147,12 +147,11 @@ final class OneOfTest extends TestCase
|
||||||
$rule = new OneOf($valid1, $valid2, $valid3);
|
$rule = new OneOf($valid1, $valid2, $valid3);
|
||||||
self::assertFalse($rule->validate('any'));
|
self::assertFalse($rule->validate('any'));
|
||||||
|
|
||||||
|
$this->expectException(OneOfException::class);
|
||||||
$rule->check('any');
|
$rule->check('any');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\XdigitException
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function invalidCheck(): void
|
public function invalidCheck(): void
|
||||||
|
@ -160,6 +159,7 @@ final class OneOfTest extends TestCase
|
||||||
$rule = new OneOf(new Xdigit(), new Alnum());
|
$rule = new OneOf(new Xdigit(), new Alnum());
|
||||||
self::assertFalse($rule->validate(-10));
|
self::assertFalse($rule->validate(-10));
|
||||||
|
|
||||||
|
$this->expectException(XdigitException::class);
|
||||||
$rule->check(-10);
|
$rule->check(-10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,13 +49,13 @@ final class PostalCodeTest extends RuleTestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage Cannot validate postal code from "Whatever" country
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function shouldThrowsExceptionWhenCountryCodeIsNotValid(): void
|
public function shouldThrowsExceptionWhenCountryCodeIsNotValid(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('Cannot validate postal code from "Whatever" country');
|
||||||
|
|
||||||
new PostalCode('Whatever');
|
new PostalCode('Whatever');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
use org\bovigo\vfs\content\LargeFileContent;
|
use org\bovigo\vfs\content\LargeFileContent;
|
||||||
use org\bovigo\vfs\vfsStream;
|
use org\bovigo\vfs\vfsStream;
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
use SplFileInfo;
|
use SplFileInfo;
|
||||||
|
|
||||||
|
@ -84,13 +85,13 @@ final class SizeTest extends RuleTestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage "42jb" is not a recognized file size
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function shouldThrowsAnExceptionWhenSizeIsNotValid(): void
|
public function shouldThrowsAnExceptionWhenSizeIsNotValid(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('"42jb" is not a recognized file size');
|
||||||
|
|
||||||
new Size('42jb');
|
new Size('42jb');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
|
use Respect\Validation\Exceptions\SubdivisionCodeException;
|
||||||
use Respect\Validation\Test\TestCase;
|
use Respect\Validation\Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,17 +34,20 @@ final class SubdivisionCodeTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function shouldThrowsExceptionWhenInvalidFormat(): void
|
public function shouldThrowsExceptionWhenInvalidFormat(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('"whatever" is not a supported country code');
|
||||||
|
|
||||||
new SubdivisionCode('whatever');
|
new SubdivisionCode('whatever');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessage "JK" is not a supported country code
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function shouldNotAcceptWrongNamesOnConstructor(): void
|
public function shouldNotAcceptWrongNamesOnConstructor(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessage('"JK" is not a supported country code');
|
||||||
|
|
||||||
new SubdivisionCode('JK');
|
new SubdivisionCode('JK');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,14 +104,15 @@ final class SubdivisionCodeTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\SubdivisionCodeException
|
|
||||||
* @expectedExceptionMessage "CA" must be a subdivision code of "Brazil"
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function shouldThrowsSubdivisionCodeException(): void
|
public function shouldThrowsSubdivisionCodeException(): void
|
||||||
{
|
{
|
||||||
$countrySubdivision = new SubdivisionCode('BR');
|
$countrySubdivision = new SubdivisionCode('BR');
|
||||||
|
|
||||||
|
$this->expectException(SubdivisionCodeException::class);
|
||||||
|
$this->expectExceptionMessage('"CA" must be a subdivision code of "Brazil"');
|
||||||
|
|
||||||
$countrySubdivision->assert('CA');
|
$countrySubdivision->assert('CA');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Respect\Validation\Rules;
|
namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
|
@ -29,13 +30,13 @@ use function tmpfile;
|
||||||
final class TypeTest extends RuleTestCase
|
final class TypeTest extends RuleTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
|
||||||
* @expectedExceptionMessageRegExp /"whatever" is not a valid type \(Available: .+\)/
|
|
||||||
*
|
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function shouldThrowExceptionWhenTypeIsNotValid(): void
|
public function shouldThrowExceptionWhenTypeIsNotValid(): void
|
||||||
{
|
{
|
||||||
|
$this->expectException(ComponentException::class);
|
||||||
|
$this->expectExceptionMessageMatches('/"whatever" is not a valid type \(Available: .+\)/');
|
||||||
|
|
||||||
new Type('whatever');
|
new Type('whatever');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue