mirror of
https://github.com/Respect/Validation.git
synced 2024-06-13 11:12:18 +02:00
Add some code standards for PHPUnit tests
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
f308e7962e
commit
e044e4b16e
11
.php_cs
11
.php_cs
|
@ -15,6 +15,17 @@ return PhpCsFixer\Config::create()
|
|||
'phpdoc_order' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'no_short_echo_tag' => true,
|
||||
'php_unit_construct' => true,
|
||||
'php_unit_dedicate_assert' => true,
|
||||
'php_unit_expectation' => true,
|
||||
'php_unit_mock' => true,
|
||||
'php_unit_namespaced' => true,
|
||||
'php_unit_ordered_covers' => true,
|
||||
'php_unit_set_up_tear_down_visibility' => true,
|
||||
'php_unit_test_annotation' => [
|
||||
'style' => 'annotation',
|
||||
],
|
||||
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
|
||||
])
|
||||
->setCacheFile(
|
||||
sprintf(
|
||||
|
|
|
@ -75,17 +75,17 @@ abstract class RuleTestCase extends TestCase
|
|||
->getMock();
|
||||
|
||||
$validatableMocked
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('validate')
|
||||
->willReturn($expectedResult);
|
||||
|
||||
if ($expectedResult) {
|
||||
$validatableMocked
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('check')
|
||||
->willReturn($expectedResult);
|
||||
$validatableMocked
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('assert')
|
||||
->willReturn($expectedResult);
|
||||
} else {
|
||||
|
@ -97,7 +97,7 @@ abstract class RuleTestCase extends TestCase
|
|||
);
|
||||
$checkException->updateTemplate(sprintf('Exception for %s:check() method', $mockClassName));
|
||||
$validatableMocked
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('check')
|
||||
->willThrowException($checkException);
|
||||
$assertException = new ValidationException(
|
||||
|
@ -108,7 +108,7 @@ abstract class RuleTestCase extends TestCase
|
|||
);
|
||||
$assertException->updateTemplate(sprintf('Exception for %s:assert() method', $mockClassName));
|
||||
$validatableMocked
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('assert')
|
||||
->willThrowException($assertException);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ use function strtotime;
|
|||
/**
|
||||
* @group rule
|
||||
*
|
||||
* @covers \Respect\Validation\Rules\MaxAge
|
||||
* @covers \Respect\Validation\Rules\AbstractAge
|
||||
* @covers \Respect\Validation\Rules\MaxAge
|
||||
*
|
||||
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
|
|
|
@ -52,8 +52,10 @@ class CheckExceptionsTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider provideListOfRuleNames
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testRuleHasAnExceptionWhichHasValidApi($ruleName): void
|
||||
public function ruleHasAnExceptionWhichHasValidApi($ruleName): void
|
||||
{
|
||||
$exceptionClass = 'Respect\\Validation\\Exceptions\\'.$ruleName.'Exception';
|
||||
self::assertTrue(
|
||||
|
|
|
@ -17,23 +17,29 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
class NestedValidationExceptionTest extends TestCase
|
||||
{
|
||||
public function testGetRelatedShouldReturnExceptionAddedByAddRelated(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function getRelatedShouldReturnExceptionAddedByAddRelated(): void
|
||||
{
|
||||
$composite = new AttributeException('input', 'id', [], 'trim');
|
||||
$node = new IntValException('input', 'id', [], 'trim');
|
||||
$composite->addRelated($node);
|
||||
self::assertEquals(1, count($composite->getRelated(true)));
|
||||
self::assertCount(1, $composite->getRelated(true));
|
||||
self::assertContainsOnly($node, $composite->getRelated());
|
||||
}
|
||||
|
||||
public function testAddingTheSameInstanceShouldAddJustASingleReference(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function addingTheSameInstanceShouldAddJustASingleReference(): void
|
||||
{
|
||||
$composite = new AttributeException('input', 'id', [], 'trim');
|
||||
$node = new IntValException('input', 'id', [], 'trim');
|
||||
$composite->addRelated($node);
|
||||
$composite->addRelated($node);
|
||||
$composite->addRelated($node);
|
||||
self::assertEquals(1, count($composite->getRelated(true)));
|
||||
self::assertCount(1, $composite->getRelated(true));
|
||||
self::assertContainsOnly($node, $composite->getRelated());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,17 +18,20 @@ use Respect\Validation\Validatable;
|
|||
|
||||
class AbstractCompositeTest extends TestCase
|
||||
{
|
||||
public function testShouldDefineNameForInternalWhenAppendRuleToCompositeRule(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldDefineNameForInternalWhenAppendRuleToCompositeRule(): void
|
||||
{
|
||||
$ruleName = 'something';
|
||||
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
$simpleRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('getName')
|
||||
->will($this->returnValue(null));
|
||||
->will(self::returnValue(null));
|
||||
$simpleRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('setName')
|
||||
->with($ruleName);
|
||||
|
||||
|
@ -40,26 +43,29 @@ class AbstractCompositeTest extends TestCase
|
|||
$compositeRuleMock->addRule($simpleRuleMock);
|
||||
}
|
||||
|
||||
public function testShouldUpdateInternalRuleNameWhenNameIsUpdated(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldUpdateInternalRuleNameWhenNameIsUpdated(): void
|
||||
{
|
||||
$ruleName1 = 'something';
|
||||
$ruleName2 = 'something else';
|
||||
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
$simpleRuleMock
|
||||
->expects($this->at(0))
|
||||
->expects(self::at(0))
|
||||
->method('getName')
|
||||
->will($this->returnValue(null));
|
||||
->will(self::returnValue(null));
|
||||
$simpleRuleMock
|
||||
->expects($this->at(2))
|
||||
->expects(self::at(2))
|
||||
->method('getName')
|
||||
->will($this->returnValue($ruleName1));
|
||||
->will(self::returnValue($ruleName1));
|
||||
$simpleRuleMock
|
||||
->expects($this->at(1))
|
||||
->expects(self::at(1))
|
||||
->method('setName')
|
||||
->with($ruleName1);
|
||||
$simpleRuleMock
|
||||
->expects($this->at(3))
|
||||
->expects(self::at(3))
|
||||
->method('setName')
|
||||
->with($ruleName2);
|
||||
|
||||
|
@ -72,15 +78,18 @@ class AbstractCompositeTest extends TestCase
|
|||
$compositeRuleMock->setName($ruleName2);
|
||||
}
|
||||
|
||||
public function testShouldNotUpdateInternalRuleAlreadyHasAName(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotUpdateInternalRuleAlreadyHasAName(): void
|
||||
{
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
$simpleRuleMock
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('getName')
|
||||
->will($this->returnValue('something'));
|
||||
->will(self::returnValue('something'));
|
||||
$simpleRuleMock
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('setName');
|
||||
|
||||
$compositeRuleMock = $this
|
||||
|
@ -91,17 +100,20 @@ class AbstractCompositeTest extends TestCase
|
|||
$compositeRuleMock->setName('Whatever');
|
||||
}
|
||||
|
||||
public function testShouldUpdateInternalRuleWhenItsNameIsNull(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldUpdateInternalRuleWhenItsNameIsNull(): void
|
||||
{
|
||||
$ruleName = 'something';
|
||||
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
$simpleRuleMock
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('getName')
|
||||
->will($this->returnValue(null));
|
||||
->will(self::returnValue(null));
|
||||
$simpleRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('setName')
|
||||
->with($ruleName);
|
||||
|
||||
|
@ -113,17 +125,20 @@ class AbstractCompositeTest extends TestCase
|
|||
$compositeRuleMock->setName($ruleName);
|
||||
}
|
||||
|
||||
public function testShouldDefineNameForInternalRulesWhenItHasNotAName(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldDefineNameForInternalRulesWhenItHasNotAName(): void
|
||||
{
|
||||
$ruleName = 'something';
|
||||
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
$simpleRuleMock
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('getName')
|
||||
->will($this->returnValue(null));
|
||||
->will(self::returnValue(null));
|
||||
$simpleRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('setName')
|
||||
->with($ruleName);
|
||||
|
||||
|
@ -135,17 +150,20 @@ class AbstractCompositeTest extends TestCase
|
|||
$compositeRuleMock->setName($ruleName);
|
||||
}
|
||||
|
||||
public function testShouldNotDefineNameForInternalRulesWhenItHasAName(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotDefineNameForInternalRulesWhenItHasAName(): void
|
||||
{
|
||||
$ruleName = 'something';
|
||||
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
$simpleRuleMock
|
||||
->expects($this->any())
|
||||
->expects(self::any())
|
||||
->method('getName')
|
||||
->will($this->returnValue($ruleName));
|
||||
->will(self::returnValue($ruleName));
|
||||
$simpleRuleMock
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('setName');
|
||||
|
||||
$compositeRuleMock = $this
|
||||
|
@ -156,7 +174,10 @@ class AbstractCompositeTest extends TestCase
|
|||
$compositeRuleMock->setName($ruleName);
|
||||
}
|
||||
|
||||
public function testRemoveRulesShouldRemoveAllTheAddedRules(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function removeRulesShouldRemoveAllTheAddedRules(): void
|
||||
{
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
|
||||
|
@ -167,7 +188,10 @@ class AbstractCompositeTest extends TestCase
|
|||
self::assertEmpty($compositeRuleMock->getRules());
|
||||
}
|
||||
|
||||
public function testShouldReturnTheAmountOfAddedRules(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldReturnTheAmountOfAddedRules(): void
|
||||
{
|
||||
$compositeRuleMock = $this->getMockForAbstractClass(AbstractComposite::class);
|
||||
$compositeRuleMock->addRule($this->createMock(Validatable::class));
|
||||
|
@ -177,14 +201,20 @@ class AbstractCompositeTest extends TestCase
|
|||
self::assertCount(3, $compositeRuleMock->getRules());
|
||||
}
|
||||
|
||||
public function testHasRuleShouldReturnFalseWhenThereIsNoRuleAppended(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function hasRuleShouldReturnFalseWhenThereIsNoRuleAppended(): void
|
||||
{
|
||||
$compositeRuleMock = $this->getMockForAbstractClass(AbstractComposite::class);
|
||||
|
||||
self::assertFalse($compositeRuleMock->hasRule(''));
|
||||
}
|
||||
|
||||
public function testHasRuleShouldReturnFalseWhenRuleIsNotFound(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function hasRuleShouldReturnFalseWhenRuleIsNotFound(): void
|
||||
{
|
||||
$oneSimpleRuleMock = $this->createMock(Validatable::class);
|
||||
|
||||
|
@ -196,7 +226,10 @@ class AbstractCompositeTest extends TestCase
|
|||
self::assertFalse($compositeRuleMock->hasRule($anotherSimpleRuleMock));
|
||||
}
|
||||
|
||||
public function testHasRuleShouldReturnFalseWhenRulePassedAsStringIsNotFound(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function hasRuleShouldReturnFalseWhenRulePassedAsStringIsNotFound(): void
|
||||
{
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
|
||||
|
@ -206,7 +239,10 @@ class AbstractCompositeTest extends TestCase
|
|||
self::assertFalse($compositeRuleMock->hasRule('SomeRule'));
|
||||
}
|
||||
|
||||
public function testHasRuleShouldReturnTrueWhenRuleIsFound(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function hasRuleShouldReturnTrueWhenRuleIsFound(): void
|
||||
{
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
|
||||
|
@ -216,7 +252,10 @@ class AbstractCompositeTest extends TestCase
|
|||
self::assertTrue($compositeRuleMock->hasRule($simpleRuleMock));
|
||||
}
|
||||
|
||||
public function testShouldAddRulesByPassingThroughConstructor(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldAddRulesByPassingThroughConstructor(): void
|
||||
{
|
||||
$simpleRuleMock = $this->createMock(Validatable::class);
|
||||
$anotherSimpleRuleMock = $this->createMock(Validatable::class);
|
||||
|
|
|
@ -17,22 +17,28 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
class AbstractCtypeRuleTest extends TestCase
|
||||
{
|
||||
public function testValidateCleanShouldReturnTrueWhenCtypeFunctionReturnsTrue(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validateCleanShouldReturnTrueWhenCtypeFunctionReturnsTrue(): void
|
||||
{
|
||||
$ctypeRuleMock = $this->getMockForAbstractClass(AbstractCtypeRule::class);
|
||||
$ctypeRuleMock->expects($this->once())
|
||||
$ctypeRuleMock->expects(self::once())
|
||||
->method('ctypeFunction')
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
self::assertTrue($ctypeRuleMock->validateClean('anything'));
|
||||
}
|
||||
|
||||
public function testValidateCleanShouldReturnFalseWhenCtypeFunctionReturnsFalse(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validateCleanShouldReturnFalseWhenCtypeFunctionReturnsFalse(): void
|
||||
{
|
||||
$ctypeRuleMock = $this->getMockForAbstractClass(AbstractCtypeRule::class);
|
||||
$ctypeRuleMock->expects($this->once())
|
||||
$ctypeRuleMock->expects(self::once())
|
||||
->method('ctypeFunction')
|
||||
->will($this->returnValue(false));
|
||||
->will(self::returnValue(false));
|
||||
|
||||
self::assertFalse($ctypeRuleMock->validateClean('anything'));
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ final class AbstractEnvelopeTest extends TestCase
|
|||
|
||||
$innerRule = $this->createMock(Validatable::class);
|
||||
$innerRule
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('validate')
|
||||
->with($input)
|
||||
->willReturn(true);
|
||||
|
@ -53,7 +53,7 @@ final class AbstractEnvelopeTest extends TestCase
|
|||
|
||||
$innerRule = $this->createMock(Validatable::class);
|
||||
$innerRule
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('validate')
|
||||
->with($input)
|
||||
->willReturn(false);
|
||||
|
|
|
@ -20,28 +20,36 @@ class AbstractFilterRuleTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage Invalid list of additional characters to be loaded
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testConstructorShouldThrowExceptionIfParamIsNotString(): void
|
||||
public function constructorShouldThrowExceptionIfParamIsNotString(): void
|
||||
{
|
||||
$this->getMockForAbstractClass(AbstractFilterRule::class, [1]);
|
||||
}
|
||||
|
||||
public function testValidateShouldReturnTrueForValidArguments(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validateShouldReturnTrueForValidArguments(): void
|
||||
{
|
||||
$filterRuleMock = $this->getMockForAbstractClass(AbstractFilterRule::class);
|
||||
$filterRuleMock->expects($this->any())
|
||||
$filterRuleMock->expects(self::any())
|
||||
->method('validateClean')
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
self::assertTrue($filterRuleMock->validate('hey'));
|
||||
}
|
||||
|
||||
public function testValidateShouldReturnFalseForInvalidArguments(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validateShouldReturnFalseForInvalidArguments(): void
|
||||
{
|
||||
$filterRuleMock = $this->getMockForAbstractClass(AbstractFilterRule::class);
|
||||
$filterRuleMock->expects($this->any())
|
||||
$filterRuleMock->expects(self::any())
|
||||
->method('validateClean')
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
self::assertFalse($filterRuleMock->validate(''));
|
||||
self::assertFalse($filterRuleMock->validate([]));
|
||||
|
|
|
@ -17,22 +17,28 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
class AbstractRegexRuleTest extends TestCase
|
||||
{
|
||||
public function testValidateCleanShouldReturnOneIfPatternIsFound(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validateCleanShouldReturnOneIfPatternIsFound(): void
|
||||
{
|
||||
$regexRuleMock = $this->getMockForAbstractClass(AbstractRegexRule::class);
|
||||
$regexRuleMock->expects($this->once())
|
||||
$regexRuleMock->expects(self::once())
|
||||
->method('getPregFormat')
|
||||
->will($this->returnValue('/^Respect$/'));
|
||||
->will(self::returnValue('/^Respect$/'));
|
||||
|
||||
self::assertEquals(1, $regexRuleMock->validateClean('Respect'));
|
||||
}
|
||||
|
||||
public function testValidateCleanShouldReturnZeroIfPatternIsNotFound(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validateCleanShouldReturnZeroIfPatternIsNotFound(): void
|
||||
{
|
||||
$regexRuleMock = $this->getMockForAbstractClass(AbstractRegexRule::class);
|
||||
$regexRuleMock->expects($this->once())
|
||||
$regexRuleMock->expects(self::once())
|
||||
->method('getPregFormat')
|
||||
->will($this->returnValue('/^Respect$/'));
|
||||
->will(self::returnValue('/^Respect$/'));
|
||||
|
||||
self::assertEquals(0, $regexRuleMock->validateClean('Validation'));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,10 @@ final class AbstractRelatedTest extends TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testConstructionOfAbstractRelatedClass(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function constructionOfAbstractRelatedClass(): void
|
||||
{
|
||||
$validatableMock = $this->createMock(Validatable::class);
|
||||
$relatedRuleMock = $this->getMockForAbstractClass(AbstractRelated::class, ['foo', $validatableMock]);
|
||||
|
@ -38,33 +41,41 @@ final class AbstractRelatedTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForOperations
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testOperationsShouldReturnTrueWhenReferenceValidatesItsValue($method): void
|
||||
public function operationsShouldReturnTrueWhenReferenceValidatesItsValue($method): void
|
||||
{
|
||||
$validatableMock = $this->createMock(Validatable::class);
|
||||
$validatableMock->expects($this->any())
|
||||
$validatableMock->expects(self::any())
|
||||
->method($method)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$relatedRuleMock = $this->getMockForAbstractClass(AbstractRelated::class, ['foo', $validatableMock]);
|
||||
$relatedRuleMock->expects($this->any())
|
||||
$relatedRuleMock->expects(self::any())
|
||||
->method('hasReference')
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
self::assertTrue($relatedRuleMock->$method('foo'));
|
||||
}
|
||||
|
||||
public function testValidateShouldReturnFalseWhenIsMandatoryAndThereIsNoReference(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validateShouldReturnFalseWhenIsMandatoryAndThereIsNoReference(): void
|
||||
{
|
||||
$relatedRuleMock = $this->getMockForAbstractClass(AbstractRelated::class, ['foo']);
|
||||
$relatedRuleMock->expects($this->any())
|
||||
$relatedRuleMock->expects(self::any())
|
||||
->method('hasReference')
|
||||
->will($this->returnValue(false));
|
||||
->will(self::returnValue(false));
|
||||
|
||||
self::assertFalse($relatedRuleMock->validate('foo'));
|
||||
}
|
||||
|
||||
public function testShouldAcceptReferenceOnConstructor(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldAcceptReferenceOnConstructor(): void
|
||||
{
|
||||
$reference = 'something';
|
||||
|
||||
|
@ -76,7 +87,10 @@ final class AbstractRelatedTest extends TestCase
|
|||
self::assertSame($reference, $abstractMock->reference);
|
||||
}
|
||||
|
||||
public function testShouldBeMandatoryByDefault(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldBeMandatoryByDefault(): void
|
||||
{
|
||||
$abstractMock = $this
|
||||
->getMockBuilder(AbstractRelated::class)
|
||||
|
@ -86,7 +100,10 @@ final class AbstractRelatedTest extends TestCase
|
|||
self::assertTrue($abstractMock->mandatory);
|
||||
}
|
||||
|
||||
public function testShouldAcceptReferenceAndRuleOnConstructor(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldAcceptReferenceAndRuleOnConstructor(): void
|
||||
{
|
||||
$ruleMock = $this->createMock(Validatable::class);
|
||||
|
||||
|
@ -98,17 +115,20 @@ final class AbstractRelatedTest extends TestCase
|
|||
self::assertSame($ruleMock, $abstractMock->validator);
|
||||
}
|
||||
|
||||
public function testShouldDefineRuleNameAsReferenceWhenRuleDoesNotHaveAName(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldDefineRuleNameAsReferenceWhenRuleDoesNotHaveAName(): void
|
||||
{
|
||||
$reference = 'something';
|
||||
|
||||
$ruleMock = $this->createMock(Validatable::class);
|
||||
$ruleMock
|
||||
->expects($this->at(0))
|
||||
->expects(self::at(0))
|
||||
->method('getName')
|
||||
->will($this->returnValue(null));
|
||||
->will(self::returnValue(null));
|
||||
$ruleMock
|
||||
->expects($this->at(1))
|
||||
->expects(self::at(1))
|
||||
->method('setName')
|
||||
->with($reference);
|
||||
|
||||
|
@ -120,17 +140,20 @@ final class AbstractRelatedTest extends TestCase
|
|||
self::assertSame($ruleMock, $abstractMock->validator);
|
||||
}
|
||||
|
||||
public function testShouldNotDefineRuleNameAsReferenceWhenRuleDoesHaveAName(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotDefineRuleNameAsReferenceWhenRuleDoesHaveAName(): void
|
||||
{
|
||||
$reference = 'something';
|
||||
|
||||
$ruleMock = $this->createMock(Validatable::class);
|
||||
$ruleMock
|
||||
->expects($this->at(0))
|
||||
->expects(self::at(0))
|
||||
->method('getName')
|
||||
->will($this->returnValue('something else'));
|
||||
->will(self::returnValue('something else'));
|
||||
$ruleMock
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('setName');
|
||||
|
||||
$abstractMock = $this
|
||||
|
@ -141,7 +164,10 @@ final class AbstractRelatedTest extends TestCase
|
|||
self::assertSame($ruleMock, $abstractMock->validator);
|
||||
}
|
||||
|
||||
public function testShouldAcceptMandatoryFlagOnConstructor(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldAcceptMandatoryFlagOnConstructor(): void
|
||||
{
|
||||
$mandatory = false;
|
||||
|
||||
|
@ -153,18 +179,21 @@ final class AbstractRelatedTest extends TestCase
|
|||
self::assertSame($mandatory, $abstractMock->mandatory);
|
||||
}
|
||||
|
||||
public function testShouldDefineChildNameWhenDefiningTheNameOfTheParent(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldDefineChildNameWhenDefiningTheNameOfTheParent(): void
|
||||
{
|
||||
$name = 'My new name';
|
||||
$reference = 'something';
|
||||
|
||||
$ruleMock = $this->createMock(Validatable::class);
|
||||
$ruleMock
|
||||
->expects($this->at(0))
|
||||
->expects(self::at(0))
|
||||
->method('getName')
|
||||
->will($this->returnValue('something else'));
|
||||
->will(self::returnValue('something else'));
|
||||
$ruleMock
|
||||
->expects($this->at(1))
|
||||
->expects(self::at(1))
|
||||
->method('setName')
|
||||
->with($name);
|
||||
|
||||
|
|
|
@ -29,8 +29,10 @@ class AbstractRuleTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForTrueAndFalse
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::__invoke
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testMagicMethodInvokeCallsValidateWithInput($booleanResult): void
|
||||
public function magicMethodInvokeCallsValidateWithInput($booleanResult): void
|
||||
{
|
||||
$input = 'something';
|
||||
|
||||
|
@ -40,10 +42,10 @@ class AbstractRuleTest extends TestCase
|
|||
->getMockForAbstractClass();
|
||||
|
||||
$abstractRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('validate')
|
||||
->with($input)
|
||||
->will($this->returnValue($booleanResult));
|
||||
->will(self::returnValue($booleanResult));
|
||||
|
||||
self::assertEquals(
|
||||
$booleanResult,
|
||||
|
@ -55,8 +57,10 @@ class AbstractRuleTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::assert
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAssertInvokesValidateOnSuccess(): void
|
||||
public function assertInvokesValidateOnSuccess(): void
|
||||
{
|
||||
$input = 'something';
|
||||
|
||||
|
@ -66,13 +70,13 @@ class AbstractRuleTest extends TestCase
|
|||
->getMockForAbstractClass();
|
||||
|
||||
$abstractRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('validate')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$abstractRuleMock
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('reportError');
|
||||
|
||||
$abstractRuleMock->assert($input);
|
||||
|
@ -81,8 +85,10 @@ class AbstractRuleTest extends TestCase
|
|||
/**
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::assert
|
||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAssertInvokesValidateAndReportErrorOnFailure(): void
|
||||
public function assertInvokesValidateAndReportErrorOnFailure(): void
|
||||
{
|
||||
$input = 'something';
|
||||
|
||||
|
@ -92,24 +98,26 @@ class AbstractRuleTest extends TestCase
|
|||
->getMockForAbstractClass();
|
||||
|
||||
$abstractRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('validate')
|
||||
->with($input)
|
||||
->will($this->returnValue(false));
|
||||
->will(self::returnValue(false));
|
||||
|
||||
$abstractRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('reportError')
|
||||
->with($input)
|
||||
->will($this->throwException(new ValidationException($input, 'abstract', [], 'trim')));
|
||||
->will(self::throwException(new ValidationException($input, 'abstract', [], 'trim')));
|
||||
|
||||
$abstractRuleMock->assert($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::check
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testCheckInvokesAssertToPerformTheValidationByDefault(): void
|
||||
public function checkInvokesAssertToPerformTheValidationByDefault(): void
|
||||
{
|
||||
$input = 'something';
|
||||
|
||||
|
@ -119,7 +127,7 @@ class AbstractRuleTest extends TestCase
|
|||
->getMockForAbstractClass();
|
||||
|
||||
$abstractRuleMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('assert')
|
||||
->with($input);
|
||||
|
||||
|
@ -128,8 +136,10 @@ class AbstractRuleTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::setTemplate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldReturnTheCurrentObjectWhenDefinigTemplate(): void
|
||||
public function shouldReturnTheCurrentObjectWhenDefinigTemplate(): void
|
||||
{
|
||||
$abstractRuleMock = $this
|
||||
->getMockBuilder(AbstractRule::class)
|
||||
|
@ -140,8 +150,10 @@ class AbstractRuleTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::setName
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldReturnTheCurrentObjectWhenDefinigName(): void
|
||||
public function shouldReturnTheCurrentObjectWhenDefinigName(): void
|
||||
{
|
||||
$abstractRuleMock = $this
|
||||
->getMockBuilder(AbstractRule::class)
|
||||
|
@ -151,10 +163,12 @@ class AbstractRuleTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::setName
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::getName
|
||||
* @covers \Respect\Validation\Rules\AbstractRule::setName
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldBeAbleToDefineAndRetrivedRuleName(): void
|
||||
public function shouldBeAbleToDefineAndRetrivedRuleName(): void
|
||||
{
|
||||
$abstractRuleMock = $this
|
||||
->getMockBuilder(AbstractRule::class)
|
||||
|
|
|
@ -34,7 +34,7 @@ final class AbstractSearcherTest extends TestCase
|
|||
|
||||
$rule = $this->getMockForAbstractClass(AbstractSearcher::class);
|
||||
$rule
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('getDataSource')
|
||||
->willReturn(['foo', $input, 'baz']);
|
||||
|
||||
|
@ -50,7 +50,7 @@ final class AbstractSearcherTest extends TestCase
|
|||
|
||||
$rule = $this->getMockForAbstractClass(AbstractSearcher::class);
|
||||
$rule
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('getDataSource')
|
||||
->willReturn([1, (int) $input, 3]);
|
||||
|
||||
|
@ -65,7 +65,7 @@ final class AbstractSearcherTest extends TestCase
|
|||
{
|
||||
$rule = $this->getMockForAbstractClass(AbstractSearcher::class);
|
||||
$rule
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('getDataSource')
|
||||
->willReturn([]);
|
||||
|
||||
|
@ -80,7 +80,7 @@ final class AbstractSearcherTest extends TestCase
|
|||
{
|
||||
$rule = $this->getMockForAbstractClass(AbstractSearcher::class);
|
||||
$rule
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('getDataSource')
|
||||
->willReturn([]);
|
||||
|
||||
|
|
|
@ -46,10 +46,10 @@ final class AbstractWrapperTest extends TestCase
|
|||
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('validate')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$wrapper = $this->getMockForAbstractClass(AbstractWrapper::class, [$validatable]);
|
||||
|
||||
|
@ -65,10 +65,10 @@ final class AbstractWrapperTest extends TestCase
|
|||
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('assert')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$wrapper = $this->getMockForAbstractClass(AbstractWrapper::class, [$validatable]);
|
||||
|
||||
|
@ -84,10 +84,10 @@ final class AbstractWrapperTest extends TestCase
|
|||
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('check')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$wrapper = $this->getMockForAbstractClass(AbstractWrapper::class, [$validatable]);
|
||||
|
||||
|
@ -103,10 +103,10 @@ final class AbstractWrapperTest extends TestCase
|
|||
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('setName')
|
||||
->with($name)
|
||||
->will($this->returnValue($validatable));
|
||||
->will(self::returnValue($validatable));
|
||||
|
||||
$wrapper = $this->getMockForAbstractClass(AbstractWrapper::class, [$validatable]);
|
||||
|
||||
|
|
|
@ -17,19 +17,25 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\AllOf
|
||||
* @covers \Respect\Validation\Exceptions\AllOfException
|
||||
* @covers \Respect\Validation\Rules\AllOf
|
||||
*/
|
||||
class AllOfTest extends TestCase
|
||||
{
|
||||
public function testRemoveRulesShouldRemoveAllRules(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function removeRulesShouldRemoveAllRules(): void
|
||||
{
|
||||
$o = new AllOf(new IntVal(), new Positive());
|
||||
$o->removeRules();
|
||||
self::assertEquals(0, count($o->getRules()));
|
||||
self::assertCount(0, $o->getRules());
|
||||
}
|
||||
|
||||
public function testAddRulesUsingArrayOfRules(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function addRulesUsingArrayOfRules(): void
|
||||
{
|
||||
$o = new AllOf();
|
||||
$o->addRules(
|
||||
|
@ -41,14 +47,20 @@ class AllOfTest extends TestCase
|
|||
self::assertTrue($o->hasRule('Positive'));
|
||||
}
|
||||
|
||||
public function testAddRulesUsingSpecificationArray(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function addRulesUsingSpecificationArray(): void
|
||||
{
|
||||
$o = new AllOf();
|
||||
$o->addRules(['Between' => [1, 2]]);
|
||||
self::assertTrue($o->hasRule('Between'));
|
||||
}
|
||||
|
||||
public function testValidationShouldWorkIfAllRulesReturnTrue(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validationShouldWorkIfAllRulesReturnTrue(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return true;
|
||||
|
@ -71,8 +83,10 @@ class AllOfTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerStaticDummyRules
|
||||
* @expectedException \Respect\Validation\Exceptions\AllOfException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidationAssertShouldFailIfAnyRuleFailsAndReturnAllExceptionsFailed($v1, $v2, $v3): void
|
||||
public function validationAssertShouldFailIfAnyRuleFailsAndReturnAllExceptionsFailed($v1, $v2, $v3): void
|
||||
{
|
||||
$o = new AllOf($v1, $v2, $v3);
|
||||
self::assertFalse($o->__invoke('any'));
|
||||
|
@ -82,8 +96,10 @@ class AllOfTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerStaticDummyRules
|
||||
* @expectedException \Respect\Validation\Exceptions\CallbackException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidationCheckShouldFailIfAnyRuleFailsAndThrowTheFirstExceptionOnly($v1, $v2, $v3): void
|
||||
public function validationCheckShouldFailIfAnyRuleFailsAndThrowTheFirstExceptionOnly($v1, $v2, $v3): void
|
||||
{
|
||||
$o = new AllOf($v1, $v2, $v3);
|
||||
self::assertFalse($o->__invoke('any'));
|
||||
|
@ -93,8 +109,10 @@ class AllOfTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerStaticDummyRules
|
||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidationCheckShouldFailOnEmptyInput($v1, $v2, $v3): void
|
||||
public function validationCheckShouldFailOnEmptyInput($v1, $v2, $v3): void
|
||||
{
|
||||
$o = new AllOf($v1, $v2, $v3);
|
||||
$o->check('');
|
||||
|
@ -102,8 +120,10 @@ class AllOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerStaticDummyRules
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidationShouldFailIfAnyRuleFails($v1, $v2, $v3): void
|
||||
public function validationShouldFailIfAnyRuleFails($v1, $v2, $v3): void
|
||||
{
|
||||
$o = new AllOf($v1, $v2, $v3);
|
||||
self::assertFalse($o->__invoke('any'));
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Alnum
|
||||
* @covers \Respect\Validation\Exceptions\AlnumException
|
||||
* @covers \Respect\Validation\Rules\Alnum
|
||||
*/
|
||||
class AlnumTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidAlnum
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidAlnumCharsShouldReturnTrue($validAlnum, $additional): void
|
||||
public function validAlnumCharsShouldReturnTrue($validAlnum, $additional): void
|
||||
{
|
||||
$validator = new Alnum($additional);
|
||||
self::assertTrue($validator->validate($validAlnum));
|
||||
|
@ -34,8 +36,10 @@ class AlnumTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidAlnum
|
||||
* @expectedException \Respect\Validation\Exceptions\AlnumException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidAlnumCharsShouldThrowAlnumExceptionAndReturnFalse($invalidAlnum, $additional): void
|
||||
public function invalidAlnumCharsShouldThrowAlnumExceptionAndReturnFalse($invalidAlnum, $additional): void
|
||||
{
|
||||
$validator = new Alnum($additional);
|
||||
self::assertFalse($validator->validate($invalidAlnum));
|
||||
|
@ -45,16 +49,20 @@ class AlnumTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
{
|
||||
$validator = new Alnum($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Alnum($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Alpha
|
||||
* @covers \Respect\Validation\Exceptions\AlphaException
|
||||
* @covers \Respect\Validation\Rules\Alpha
|
||||
*/
|
||||
class AlphaTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidAlpha
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidAlphanumericCharsShouldReturnTrue($validAlpha, $additional): void
|
||||
public function validAlphanumericCharsShouldReturnTrue($validAlpha, $additional): void
|
||||
{
|
||||
$validator = new Alpha($additional);
|
||||
self::assertTrue($validator->validate($validAlpha));
|
||||
|
@ -36,8 +38,10 @@ class AlphaTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidAlpha
|
||||
* @expectedException \Respect\Validation\Exceptions\AlphaException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidAlphanumericCharsShouldThrowAlphaException($invalidAlpha, $additional): void
|
||||
public function invalidAlphanumericCharsShouldThrowAlphaException($invalidAlpha, $additional): void
|
||||
{
|
||||
$validator = new Alpha($additional);
|
||||
self::assertFalse($validator->validate($invalidAlpha));
|
||||
|
@ -47,16 +51,20 @@ class AlphaTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentException($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentException($additional): void
|
||||
{
|
||||
$validator = new Alpha($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Alpha($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\AnyOf
|
||||
* @covers \Respect\Validation\Exceptions\AnyOfException
|
||||
* @covers \Respect\Validation\Rules\AnyOf
|
||||
*/
|
||||
class AnyOfTest extends TestCase
|
||||
{
|
||||
public function testValid(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function valid(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
|
@ -41,8 +44,10 @@ class AnyOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\AnyOfException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalid(): void
|
||||
public function invalid(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
|
@ -60,8 +65,10 @@ class AnyOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\XdigitException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidCheck(): void
|
||||
public function invalidCheck(): void
|
||||
{
|
||||
$o = new AnyOf(new Xdigit(), new Alnum());
|
||||
self::assertFalse($o->validate(-10));
|
||||
|
|
|
@ -18,8 +18,8 @@ use Respect\Validation\Validatable;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Attribute
|
||||
* @covers \Respect\Validation\Exceptions\AttributeException
|
||||
* @covers \Respect\Validation\Rules\Attribute
|
||||
*/
|
||||
final class AttributeTest extends RuleTestCase
|
||||
{
|
||||
|
|
|
@ -18,8 +18,8 @@ use Respect\Validation\Validatable;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Call
|
||||
* @covers \Respect\Validation\Exceptions\CallException
|
||||
* @covers \Respect\Validation\Rules\Call
|
||||
*/
|
||||
class CallTest extends TestCase
|
||||
{
|
||||
|
@ -30,11 +30,14 @@ class CallTest extends TestCase
|
|||
return self::CALLBACK_RETURN;
|
||||
}
|
||||
|
||||
public function testCallbackValidatorShouldAcceptEmptyString(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function callbackValidatorShouldAcceptEmptyString(): void
|
||||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('assert')
|
||||
->with(['']);
|
||||
|
||||
|
@ -42,11 +45,14 @@ class CallTest extends TestCase
|
|||
$v->assert('');
|
||||
}
|
||||
|
||||
public function testCallbackValidatorShouldAcceptStringWithFunctionName(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function callbackValidatorShouldAcceptStringWithFunctionName(): void
|
||||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('assert')
|
||||
->with(['t', 'e', 's', 't']);
|
||||
|
||||
|
@ -54,11 +60,14 @@ class CallTest extends TestCase
|
|||
$v->assert('test');
|
||||
}
|
||||
|
||||
public function testCallbackValidatorShouldAcceptArrayCallbackDefinition(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function callbackValidatorShouldAcceptArrayCallbackDefinition(): void
|
||||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('assert')
|
||||
->with(self::CALLBACK_RETURN);
|
||||
|
||||
|
@ -66,13 +75,16 @@ class CallTest extends TestCase
|
|||
$v->assert('test');
|
||||
}
|
||||
|
||||
public function testCallbackValidatorShouldAcceptClosures(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function callbackValidatorShouldAcceptClosures(): void
|
||||
{
|
||||
$return = [];
|
||||
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('assert')
|
||||
->with($return);
|
||||
|
||||
|
@ -87,8 +99,10 @@ class CallTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\CallException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testCallbackFailedShouldThrowCallException(): void
|
||||
public function callbackFailedShouldThrowCallException(): void
|
||||
{
|
||||
$v = new Call('strrev', new ArrayVal());
|
||||
self::assertFalse($v->validate('test'));
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Cntrl
|
||||
* @covers \Respect\Validation\Exceptions\CntrlException
|
||||
* @covers \Respect\Validation\Rules\Cntrl
|
||||
*/
|
||||
class CntrlTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidCntrl
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidDataWithCntrlShouldReturnTrue($validCntrl, $additional = ''): void
|
||||
public function validDataWithCntrlShouldReturnTrue($validCntrl, $additional = ''): void
|
||||
{
|
||||
$validator = new Cntrl($additional);
|
||||
self::assertTrue($validator->validate($validCntrl));
|
||||
|
@ -34,8 +36,10 @@ class CntrlTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidCntrl
|
||||
* @expectedException \Respect\Validation\Exceptions\CntrlException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidCntrlShouldFailAndThrowCntrlException($invalidCntrl, $additional = ''): void
|
||||
public function invalidCntrlShouldFailAndThrowCntrlException($invalidCntrl, $additional = ''): void
|
||||
{
|
||||
$validator = new Cntrl($additional);
|
||||
self::assertFalse($validator->validate($invalidCntrl));
|
||||
|
@ -45,16 +49,20 @@ class CntrlTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
{
|
||||
$validator = new Cntrl($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Cntrl($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Consonant
|
||||
* @covers \Respect\Validation\Exceptions\ConsonantException
|
||||
* @covers \Respect\Validation\Rules\Consonant
|
||||
*/
|
||||
class ConsonantTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidConsonants
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidDataWithConsonantsShouldReturnTrue($validConsonants, $additional = ''): void
|
||||
public function validDataWithConsonantsShouldReturnTrue($validConsonants, $additional = ''): void
|
||||
{
|
||||
$validator = new Consonant($additional);
|
||||
self::assertTrue($validator->validate($validConsonants));
|
||||
|
@ -34,8 +36,10 @@ class ConsonantTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidConsonants
|
||||
* @expectedException \Respect\Validation\Exceptions\ConsonantException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConsonantsShouldFailAndThrowConsonantException($invalidConsonants, $additional = ''): void
|
||||
public function invalidConsonantsShouldFailAndThrowConsonantException($invalidConsonants, $additional = ''): void
|
||||
{
|
||||
$validator = new Consonant($additional);
|
||||
self::assertFalse($validator->validate($invalidConsonants));
|
||||
|
@ -45,16 +49,20 @@ class ConsonantTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
{
|
||||
$validator = new Consonant($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Consonant($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Digit
|
||||
* @covers \Respect\Validation\Exceptions\DigitException
|
||||
* @covers \Respect\Validation\Rules\Digit
|
||||
*/
|
||||
class DigitTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidDigits
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidDataWithDigitsShouldReturnTrue($validDigits, $additional = ''): void
|
||||
public function validDataWithDigitsShouldReturnTrue($validDigits, $additional = ''): void
|
||||
{
|
||||
$validator = new Digit($additional);
|
||||
self::assertTrue($validator->validate($validDigits));
|
||||
|
@ -34,8 +36,10 @@ class DigitTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidDigits
|
||||
* @expectedException \Respect\Validation\Exceptions\DigitException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidDigitsShouldFailAndThrowDigitException($invalidDigits, $additional = ''): void
|
||||
public function invalidDigitsShouldFailAndThrowDigitException($invalidDigits, $additional = ''): void
|
||||
{
|
||||
$validator = new Digit($additional);
|
||||
self::assertFalse($validator->validate($invalidDigits));
|
||||
|
@ -45,16 +49,20 @@ class DigitTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
{
|
||||
$validator = new Digit($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Digit($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -18,8 +18,8 @@ use Respect\Validation\Validator as v;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Domain
|
||||
* @covers \Respect\Validation\Exceptions\DomainException
|
||||
* @covers \Respect\Validation\Rules\Domain
|
||||
*/
|
||||
class DomainTest extends TestCase
|
||||
{
|
||||
|
@ -32,8 +32,10 @@ class DomainTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForDomain
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidDomainsShouldReturnTrue($input, $tldcheck = true): void
|
||||
public function validDomainsShouldReturnTrue($input, $tldcheck = true): void
|
||||
{
|
||||
$this->object->tldCheck($tldcheck);
|
||||
self::assertTrue($this->object->__invoke($input));
|
||||
|
@ -44,8 +46,10 @@ class DomainTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotDomain
|
||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotDomain($input, $tldcheck = true): void
|
||||
public function notDomain($input, $tldcheck = true): void
|
||||
{
|
||||
$this->object->tldCheck($tldcheck);
|
||||
$this->object->check($input);
|
||||
|
@ -54,8 +58,10 @@ class DomainTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotDomain
|
||||
* @expectedException \Respect\Validation\Exceptions\DomainException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotDomainCheck($input, $tldcheck = true): void
|
||||
public function notDomainCheck($input, $tldcheck = true): void
|
||||
{
|
||||
$this->object->tldCheck($tldcheck);
|
||||
$this->object->assert($input);
|
||||
|
@ -93,8 +99,10 @@ class DomainTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForDomain
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testBuilder($validDomain, $checkTLD = true): void
|
||||
public function builder($validDomain, $checkTLD = true): void
|
||||
{
|
||||
self::assertTrue(
|
||||
v::domain($checkTLD)->validate($validDomain),
|
||||
|
|
|
@ -68,15 +68,15 @@ final class EachTest extends RuleTestCase
|
|||
$validatable = $this->createMock(Validatable::class);
|
||||
|
||||
$validatable
|
||||
->expects($this->at(0))
|
||||
->expects(self::at(0))
|
||||
->method('check')
|
||||
->with('A');
|
||||
$validatable
|
||||
->expects($this->at(1))
|
||||
->expects(self::at(1))
|
||||
->method('check')
|
||||
->with('B');
|
||||
$validatable
|
||||
->expects($this->at(2))
|
||||
->expects(self::at(2))
|
||||
->method('check')
|
||||
->with('C');
|
||||
|
||||
|
@ -98,15 +98,15 @@ final class EachTest extends RuleTestCase
|
|||
$validatable = $this->createMock(Validatable::class);
|
||||
|
||||
$validatable
|
||||
->expects($this->at(0))
|
||||
->expects(self::at(0))
|
||||
->method('check')
|
||||
->with(1);
|
||||
$validatable
|
||||
->expects($this->at(1))
|
||||
->expects(self::at(1))
|
||||
->method('check')
|
||||
->with(2);
|
||||
$validatable
|
||||
->expects($this->at(2))
|
||||
->expects(self::at(2))
|
||||
->method('check')
|
||||
->with(3);
|
||||
|
||||
|
|
|
@ -110,10 +110,10 @@ final class EmailTest extends RuleTestCase
|
|||
|
||||
$emailValidator = $this->getEmailValidatorMock();
|
||||
$emailValidator
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('isValid')
|
||||
->with($input, $this->isInstanceOf(RFCValidation::class))
|
||||
->will($this->returnValue(true));
|
||||
->with($input, self::isInstanceOf(RFCValidation::class))
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$rule = new Email($emailValidator);
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ use SplFileInfo;
|
|||
/**
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Extension
|
||||
* @covers \Respect\Validation\Exceptions\ExtensionException
|
||||
* @covers \Respect\Validation\Rules\Extension
|
||||
*/
|
||||
class ExtensionTest extends TestCase
|
||||
{
|
||||
|
@ -36,15 +36,20 @@ class ExtensionTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerValidExtension
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateExtension($filename, $extension): void
|
||||
public function shouldValidateExtension($filename, $extension): void
|
||||
{
|
||||
$rule = new Extension($extension);
|
||||
|
||||
self::assertTrue($rule->validate($filename));
|
||||
}
|
||||
|
||||
public function testShouldAcceptSplFileInfo(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldAcceptSplFileInfo(): void
|
||||
{
|
||||
$fileInfo = new SplFileInfo(__FILE__);
|
||||
|
||||
|
@ -53,7 +58,10 @@ class ExtensionTest extends TestCase
|
|||
self::assertTrue($rule->validate($fileInfo));
|
||||
}
|
||||
|
||||
public function testShouldInvalidWhenNotStringNorSplFileInfo(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldInvalidWhenNotStringNorSplFileInfo(): void
|
||||
{
|
||||
$nonFile = [__FILE__];
|
||||
|
||||
|
@ -65,8 +73,10 @@ class ExtensionTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ExtensionException
|
||||
* @expectedExceptionMessage "filename.jpg" must have "png" extension
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowExtensionExceptionWhenCheckingValue(): void
|
||||
public function shouldThrowExtensionExceptionWhenCheckingValue(): void
|
||||
{
|
||||
$rule = new Extension('png');
|
||||
$rule->check('filename.jpg');
|
||||
|
|
|
@ -20,8 +20,8 @@ use function Respect\Stringifier\stringify;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Factor
|
||||
* @covers \Respect\Validation\Exceptions\FactorException
|
||||
* @covers \Respect\Validation\Rules\Factor
|
||||
*
|
||||
* @author David Meister <thedavidmeister@gmail.com>
|
||||
*/
|
||||
|
@ -29,8 +29,10 @@ class FactorTest extends TestCase
|
|||
{
|
||||
/**
|
||||
* @dataProvider providerForValidFactor
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidFactorShouldReturnTrue($dividend, $input): void
|
||||
public function validFactorShouldReturnTrue($dividend, $input): void
|
||||
{
|
||||
$min = new Factor($dividend);
|
||||
self::assertTrue($min->__invoke($input));
|
||||
|
@ -40,8 +42,10 @@ class FactorTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInvalidFactor
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidFactorShouldThrowFactorException($dividend, $input): void
|
||||
public function invalidFactorShouldThrowFactorException($dividend, $input): void
|
||||
{
|
||||
$this->expectException(
|
||||
FactorException::class,
|
||||
|
@ -55,8 +59,10 @@ class FactorTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInvalidFactorDividend
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidDividentShouldThrowComponentException($dividend, $input): void
|
||||
public function invalidDividentShouldThrowComponentException($dividend, $input): void
|
||||
{
|
||||
$this->expectException(
|
||||
ComponentException::class,
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\FalseVal
|
||||
* @covers \Respect\Validation\Exceptions\FalseValException
|
||||
* @covers \Respect\Validation\Rules\FalseVal
|
||||
*/
|
||||
class FalseValTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider validFalseProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
public function shouldValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
{
|
||||
$rule = new FalseVal();
|
||||
|
||||
|
@ -52,8 +54,10 @@ class FalseValTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider invalidFalseProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
public function shouldNotValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
{
|
||||
$rule = new FalseVal();
|
||||
|
||||
|
|
|
@ -30,15 +30,17 @@ function is_file($file)
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\File
|
||||
* @covers \Respect\Validation\Exceptions\FileException
|
||||
* @covers \Respect\Validation\Rules\File
|
||||
*/
|
||||
class FileTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\File::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidFileShouldReturnTrue(): void
|
||||
public function validFileShouldReturnTrue(): void
|
||||
{
|
||||
$GLOBALS['is_file'] = true;
|
||||
|
||||
|
@ -49,8 +51,10 @@ class FileTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\File::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidFileShouldReturnFalse(): void
|
||||
public function invalidFileShouldReturnFalse(): void
|
||||
{
|
||||
$GLOBALS['is_file'] = false;
|
||||
|
||||
|
@ -61,14 +65,16 @@ class FileTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\File::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateObjects(): void
|
||||
public function shouldValidateObjects(): void
|
||||
{
|
||||
$rule = new File();
|
||||
$object = $this->createMock('SplFileInfo', ['isFile'], ['somefile.txt']);
|
||||
$object->expects($this->once())
|
||||
$object->expects(self::once())
|
||||
->method('isFile')
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
self::assertTrue($rule->validate($object));
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Finite
|
||||
* @covers \Respect\Validation\Exceptions\FiniteException
|
||||
* @covers \Respect\Validation\Rules\Finite
|
||||
*/
|
||||
class FiniteTest extends TestCase
|
||||
{
|
||||
|
@ -31,16 +31,20 @@ class FiniteTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForFinite
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateFiniteNumbers($input): void
|
||||
public function shouldValidateFiniteNumbers($input): void
|
||||
{
|
||||
self::assertTrue($this->rule->validate($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForNonFinite
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidateNonFiniteNumbers($input): void
|
||||
public function shouldNotValidateNonFiniteNumbers($input): void
|
||||
{
|
||||
self::assertFalse($this->rule->validate($input));
|
||||
}
|
||||
|
@ -48,8 +52,10 @@ class FiniteTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\FiniteException
|
||||
* @expectedExceptionMessage `INF` must be a finite number
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowFiniteExceptionWhenChecking(): void
|
||||
public function shouldThrowFiniteExceptionWhenChecking(): void
|
||||
{
|
||||
$this->rule->check(INF);
|
||||
}
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Graph
|
||||
* @covers \Respect\Validation\Exceptions\GraphException
|
||||
* @covers \Respect\Validation\Rules\Graph
|
||||
*/
|
||||
class GraphTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidGraph
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidDataWithGraphCharsShouldReturnTrue($validGraph, $additional = ''): void
|
||||
public function validDataWithGraphCharsShouldReturnTrue($validGraph, $additional = ''): void
|
||||
{
|
||||
$validator = new Graph($additional);
|
||||
self::assertTrue($validator->validate($validGraph));
|
||||
|
@ -34,8 +36,10 @@ class GraphTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidGraph
|
||||
* @expectedException \Respect\Validation\Exceptions\GraphException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidGraphShouldFailAndThrowGraphException($invalidGraph, $additional = ''): void
|
||||
public function invalidGraphShouldFailAndThrowGraphException($invalidGraph, $additional = ''): void
|
||||
{
|
||||
$validator = new Graph($additional);
|
||||
self::assertFalse($validator->validate($invalidGraph));
|
||||
|
@ -45,16 +49,20 @@ class GraphTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
{
|
||||
$validator = new Graph($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Graph($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\HexRgbColor
|
||||
* @covers \Respect\Validation\Exceptions\HexRgbColorException
|
||||
* @covers \Respect\Validation\Rules\HexRgbColor
|
||||
*/
|
||||
class HexRgbColorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidHexRgbColor
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testHexRgbColorValuesONLYShouldReturnTrue($validHexRgbColor): void
|
||||
public function hexRgbColorValuesONLYShouldReturnTrue($validHexRgbColor): void
|
||||
{
|
||||
$validator = new HexRgbColor();
|
||||
|
||||
|
@ -34,8 +36,10 @@ class HexRgbColorTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInvalidHexRgbColor
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidHexRgbColorValuesShouldReturnFalse($invalidHexRgbColor): void
|
||||
public function invalidHexRgbColorValuesShouldReturnFalse($invalidHexRgbColor): void
|
||||
{
|
||||
$validator = new HexRgbColor();
|
||||
|
||||
|
|
|
@ -24,7 +24,10 @@ use SplFileObject;
|
|||
*/
|
||||
class ImageTest extends RuleTestCase
|
||||
{
|
||||
public function testShouldAcceptAnInstanceOfFinfoOnConstructor(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldAcceptAnInstanceOfFinfoOnConstructor(): void
|
||||
{
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$rule = new Image($finfo);
|
||||
|
@ -32,7 +35,10 @@ class ImageTest extends RuleTestCase
|
|||
self::assertSame($rule->fileInfo, $finfo);
|
||||
}
|
||||
|
||||
public function testShouldHaveAnInstanceOfFinfoByDefault(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldHaveAnInstanceOfFinfoByDefault(): void
|
||||
{
|
||||
$rule = new Image();
|
||||
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\In
|
||||
* @covers \Respect\Validation\Exceptions\InException
|
||||
* @covers \Respect\Validation\Rules\In
|
||||
*/
|
||||
class InTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForIn
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testSuccessInValidatorCases($input, $options = null): void
|
||||
public function successInValidatorCases($input, $options = null): void
|
||||
{
|
||||
$v = new In($options);
|
||||
self::assertTrue($v->__invoke($input));
|
||||
|
@ -36,8 +38,10 @@ class InTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotIn
|
||||
* @expectedException \Respect\Validation\Exceptions\InException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidInChecksShouldThrowInException($input, $options, $strict = false): void
|
||||
public function invalidInChecksShouldThrowInException($input, $options, $strict = false): void
|
||||
{
|
||||
$v = new In($options, $strict);
|
||||
self::assertFalse($v->__invoke($input));
|
||||
|
@ -47,8 +51,10 @@ class InTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\InException
|
||||
* @expectedExceptionMessage "x" must be in `{ "foo", "bar" }`
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInCheckExceptionMessageWithArray(): void
|
||||
public function inCheckExceptionMessageWithArray(): void
|
||||
{
|
||||
$v = new In(['foo', 'bar']);
|
||||
$v->assert('x');
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Infinite
|
||||
* @covers \Respect\Validation\Exceptions\InfiniteException
|
||||
* @covers \Respect\Validation\Rules\Infinite
|
||||
*/
|
||||
class InfiniteTest extends TestCase
|
||||
{
|
||||
|
@ -31,16 +31,20 @@ class InfiniteTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInfinite
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateInfiniteNumbers($input): void
|
||||
public function shouldValidateInfiniteNumbers($input): void
|
||||
{
|
||||
self::assertTrue($this->rule->validate($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForNonInfinite
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidateNonInfiniteNumbers($input): void
|
||||
public function shouldNotValidateNonInfiniteNumbers($input): void
|
||||
{
|
||||
self::assertFalse($this->rule->validate($input));
|
||||
}
|
||||
|
@ -48,8 +52,10 @@ class InfiniteTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\InfiniteException
|
||||
* @expectedExceptionMessage 123456 must be an infinite number
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowInfiniteExceptionWhenChecking(): void
|
||||
public function shouldThrowInfiniteExceptionWhenChecking(): void
|
||||
{
|
||||
$this->rule->check(123456);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Instance
|
||||
* @covers \Respect\Validation\Exceptions\InstanceException
|
||||
* @covers \Respect\Validation\Rules\Instance
|
||||
*/
|
||||
class InstanceTest extends TestCase
|
||||
{
|
||||
|
@ -29,28 +29,38 @@ class InstanceTest extends TestCase
|
|||
$this->instanceValidator = new Instance('ArrayObject');
|
||||
}
|
||||
|
||||
public function testInstanceValidationShouldReturnFalseForEmpty(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function instanceValidationShouldReturnFalseForEmpty(): void
|
||||
{
|
||||
self::assertFalse($this->instanceValidator->__invoke(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\InstanceException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInstanceValidationShouldNotAssertEmpty(): void
|
||||
public function instanceValidationShouldNotAssertEmpty(): void
|
||||
{
|
||||
$this->instanceValidator->assert('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\InstanceException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInstanceValidationShouldNotCheckEmpty(): void
|
||||
public function instanceValidationShouldNotCheckEmpty(): void
|
||||
{
|
||||
$this->instanceValidator->check('');
|
||||
}
|
||||
|
||||
public function testInstanceValidationShouldReturnTrueForValidInstances(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function instanceValidationShouldReturnTrueForValidInstances(): void
|
||||
{
|
||||
self::assertTrue($this->instanceValidator->__invoke(new \ArrayObject()));
|
||||
$this->instanceValidator->assert(new \ArrayObject());
|
||||
|
@ -59,8 +69,10 @@ class InstanceTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\InstanceException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidInstancesShouldThrowInstanceException(): void
|
||||
public function invalidInstancesShouldThrowInstanceException(): void
|
||||
{
|
||||
self::assertFalse($this->instanceValidator->validate(new \stdClass()));
|
||||
$this->instanceValidator->assert(new \stdClass());
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Ip
|
||||
* @covers \Respect\Validation\Exceptions\IpException
|
||||
* @covers \Respect\Validation\Rules\Ip
|
||||
*/
|
||||
class IpTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForIp
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidIpsShouldReturnTrue($input, $options = null): void
|
||||
public function validIpsShouldReturnTrue($input, $options = null): void
|
||||
{
|
||||
$ipValidator = new Ip($options);
|
||||
self::assertTrue($ipValidator->__invoke($input));
|
||||
|
@ -35,8 +37,10 @@ class IpTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForIpBetweenRange
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testIpsBetweenRangeShouldReturnTrue($input, $networkRange): void
|
||||
public function ipsBetweenRangeShouldReturnTrue($input, $networkRange): void
|
||||
{
|
||||
$ipValidator = new Ip($networkRange);
|
||||
self::assertTrue($ipValidator->__invoke($input));
|
||||
|
@ -47,8 +51,10 @@ class IpTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotIp
|
||||
* @expectedException \Respect\Validation\Exceptions\IpException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidIpsShouldThrowIpException($input, $options = null): void
|
||||
public function invalidIpsShouldThrowIpException($input, $options = null): void
|
||||
{
|
||||
$ipValidator = new Ip($options);
|
||||
self::assertFalse($ipValidator->__invoke($input));
|
||||
|
@ -58,8 +64,10 @@ class IpTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForIpOutsideRange
|
||||
* @expectedException \Respect\Validation\Exceptions\IpException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testIpsOutsideRangeShouldReturnFalse($input, $networkRange): void
|
||||
public function ipsOutsideRangeShouldReturnFalse($input, $networkRange): void
|
||||
{
|
||||
$ipValidator = new Ip($networkRange);
|
||||
self::assertFalse($ipValidator->__invoke($input));
|
||||
|
@ -126,8 +134,10 @@ class IpTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidRanges
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidRangeShouldRaiseException($range): void
|
||||
public function invalidRangeShouldRaiseException($range): void
|
||||
{
|
||||
$o = new Ip($range);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Json
|
||||
* @covers \Respect\Validation\Exceptions\JsonException
|
||||
* @covers \Respect\Validation\Rules\Json
|
||||
*/
|
||||
class JsonTest extends RuleTestCase
|
||||
{
|
||||
|
|
|
@ -19,12 +19,15 @@ use Respect\Validation\Validatable;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\KeyNested
|
||||
* @covers \Respect\Validation\Exceptions\KeyNestedException
|
||||
* @covers \Respect\Validation\Rules\KeyNested
|
||||
*/
|
||||
class KeyNestedTest extends TestCase
|
||||
{
|
||||
public function testArrayWithPresentKeysWillReturnTrueForFullPathValidator(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function arrayWithPresentKeysWillReturnTrueForFullPathValidator(): void
|
||||
{
|
||||
$array = [
|
||||
'bar' => [
|
||||
|
@ -42,7 +45,10 @@ class KeyNestedTest extends TestCase
|
|||
self::assertTrue($rule->validate($array));
|
||||
}
|
||||
|
||||
public function testArrayWithNumericKeysWillReturnTrueForFullPathValidator(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function arrayWithNumericKeysWillReturnTrueForFullPathValidator(): void
|
||||
{
|
||||
$array = [
|
||||
0 => 'Zero, the hero!',
|
||||
|
@ -50,7 +56,7 @@ class KeyNestedTest extends TestCase
|
|||
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('check')
|
||||
->with($array[0]);
|
||||
|
||||
|
@ -58,7 +64,10 @@ class KeyNestedTest extends TestCase
|
|||
$rule->check($array);
|
||||
}
|
||||
|
||||
public function testArrayWithPresentKeysWillReturnTrueForHalfPathValidator(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function arrayWithPresentKeysWillReturnTrueForHalfPathValidator(): void
|
||||
{
|
||||
$array = [
|
||||
'bar' => [
|
||||
|
@ -76,7 +85,10 @@ class KeyNestedTest extends TestCase
|
|||
self::assertTrue($rule->validate($array));
|
||||
}
|
||||
|
||||
public function testObjectWithPresentPropertiesWillReturnTrueForDirtyPathValidator(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function objectWithPresentPropertiesWillReturnTrueForDirtyPathValidator(): void
|
||||
{
|
||||
$object = (object) [
|
||||
'bar' => (object) [
|
||||
|
@ -94,7 +106,10 @@ class KeyNestedTest extends TestCase
|
|||
self::assertTrue($rule->validate($object));
|
||||
}
|
||||
|
||||
public function testEmptyInputMustReturnFalse(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function emptyInputMustReturnFalse(): void
|
||||
{
|
||||
$rule = new KeyNested('bar.foo.baz');
|
||||
|
||||
|
@ -103,8 +118,10 @@ class KeyNestedTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyNestedException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testEmptyInputMustNotAssert(): void
|
||||
public function emptyInputMustNotAssert(): void
|
||||
{
|
||||
$rule = new KeyNested('bar.foo.baz');
|
||||
$rule->assert('');
|
||||
|
@ -112,14 +129,19 @@ class KeyNestedTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyNestedException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testEmptyInputMustNotCheck(): void
|
||||
public function emptyInputMustNotCheck(): void
|
||||
{
|
||||
$rule = new KeyNested('bar.foo.baz');
|
||||
$rule->check('');
|
||||
}
|
||||
|
||||
public function testArrayWithEmptyKeyShouldReturnTrue(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function arrayWithEmptyKeyShouldReturnTrue(): void
|
||||
{
|
||||
$rule = new KeyNested('emptyKey');
|
||||
$input = ['emptyKey' => ''];
|
||||
|
@ -129,8 +151,10 @@ class KeyNestedTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyNestedException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testArrayWithAbsentKeyShouldThrowNestedKeyException(): void
|
||||
public function arrayWithAbsentKeyShouldThrowNestedKeyException(): void
|
||||
{
|
||||
$validator = new KeyNested('bar.bar');
|
||||
$object = [
|
||||
|
@ -143,8 +167,10 @@ class KeyNestedTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyNestedException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotArrayShouldThrowKeyException(): void
|
||||
public function notArrayShouldThrowKeyException(): void
|
||||
{
|
||||
$validator = new KeyNested('baz.bar');
|
||||
$object = 123;
|
||||
|
@ -153,8 +179,10 @@ class KeyNestedTest extends TestCase
|
|||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testExtraValidatorShouldValidateKey(): void
|
||||
public function extraValidatorShouldValidateKey(): void
|
||||
{
|
||||
$subValidator = new Length(3, 7);
|
||||
$validator = new KeyNested('bar.foo.baz', $subValidator);
|
||||
|
@ -168,7 +196,10 @@ class KeyNestedTest extends TestCase
|
|||
$validator->assert($object);
|
||||
}
|
||||
|
||||
public function testNotMandatoryExtraValidatorShouldPassWithAbsentKey(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function notMandatoryExtraValidatorShouldPassWithAbsentKey(): void
|
||||
{
|
||||
$subValidator = new Length(1, 3);
|
||||
$validator = new KeyNested('bar.rab', $subValidator, false);
|
||||
|
@ -176,7 +207,10 @@ class KeyNestedTest extends TestCase
|
|||
self::assertTrue($validator->validate($object));
|
||||
}
|
||||
|
||||
public function testArrayAccessWithPresentKeysWillReturnTrue(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function arrayAccessWithPresentKeysWillReturnTrue(): void
|
||||
{
|
||||
$arrayAccess = new ArrayObject([
|
||||
'bar' => [
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Key
|
||||
* @covers \Respect\Validation\Exceptions\KeyException
|
||||
* @covers \Respect\Validation\Rules\Key
|
||||
*/
|
||||
class KeyTest extends TestCase
|
||||
{
|
||||
public function testArrayWithPresentKeyShouldReturnTrue(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function arrayWithPresentKeyShouldReturnTrue(): void
|
||||
{
|
||||
$validator = new Key('bar');
|
||||
$someArray = [];
|
||||
|
@ -30,7 +33,10 @@ class KeyTest extends TestCase
|
|||
self::assertTrue($validator->validate($someArray));
|
||||
}
|
||||
|
||||
public function testArrayWithNumericKeyShouldReturnTrue(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function arrayWithNumericKeyShouldReturnTrue(): void
|
||||
{
|
||||
$validator = new Key(0);
|
||||
$someArray = [];
|
||||
|
@ -38,7 +44,10 @@ class KeyTest extends TestCase
|
|||
self::assertTrue($validator->validate($someArray));
|
||||
}
|
||||
|
||||
public function testEmptyInputMustReturnFalse(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function emptyInputMustReturnFalse(): void
|
||||
{
|
||||
$validator = new Key('someEmptyKey');
|
||||
$input = '';
|
||||
|
@ -48,8 +57,10 @@ class KeyTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testEmptyInputMustNotAssert(): void
|
||||
public function emptyInputMustNotAssert(): void
|
||||
{
|
||||
$validator = new Key('someEmptyKey');
|
||||
$validator->assert('');
|
||||
|
@ -57,14 +68,19 @@ class KeyTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testEmptyInputMustNotCheck(): void
|
||||
public function emptyInputMustNotCheck(): void
|
||||
{
|
||||
$validator = new Key('someEmptyKey');
|
||||
$validator->check('');
|
||||
}
|
||||
|
||||
public function testArrayWithEmptyKeyShouldReturnTrue(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function arrayWithEmptyKeyShouldReturnTrue(): void
|
||||
{
|
||||
$validator = new Key('someEmptyKey');
|
||||
$input = [];
|
||||
|
@ -73,20 +89,23 @@ class KeyTest extends TestCase
|
|||
self::assertTrue($validator->validate($input));
|
||||
}
|
||||
|
||||
public function testShouldHaveTheSameReturnValueForAllValidators(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldHaveTheSameReturnValueForAllValidators(): void
|
||||
{
|
||||
$rule = new Key('key', new NotEmpty());
|
||||
$input = ['key' => ''];
|
||||
|
||||
try {
|
||||
$rule->assert($input);
|
||||
$this->fail('`assert()` must throws exception');
|
||||
self::fail('`assert()` must throws exception');
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
$rule->check($input);
|
||||
$this->fail('`check()` must throws exception');
|
||||
self::fail('`check()` must throws exception');
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
|
@ -95,8 +114,10 @@ class KeyTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testArrayWithAbsentKeyShouldThrowKeyException(): void
|
||||
public function arrayWithAbsentKeyShouldThrowKeyException(): void
|
||||
{
|
||||
$validator = new Key('bar');
|
||||
$someArray = [];
|
||||
|
@ -106,8 +127,10 @@ class KeyTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotArrayShouldThrowKeyException(): void
|
||||
public function notArrayShouldThrowKeyException(): void
|
||||
{
|
||||
$validator = new Key('bar');
|
||||
$someArray = 123;
|
||||
|
@ -116,16 +139,20 @@ class KeyTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParametersShouldThrowComponentExceptionUponInstantiation(): void
|
||||
public function invalidConstructorParametersShouldThrowComponentExceptionUponInstantiation(): void
|
||||
{
|
||||
new Key(['invalid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testExtraValidatorShouldValidateKey(): void
|
||||
public function extraValidatorShouldValidateKey(): void
|
||||
{
|
||||
$subValidator = new Length(1, 3);
|
||||
$validator = new Key('bar', $subValidator);
|
||||
|
@ -134,7 +161,10 @@ class KeyTest extends TestCase
|
|||
$validator->assert($someArray);
|
||||
}
|
||||
|
||||
public function testNotMandatoryExtraValidatorShouldPassWithAbsentKey(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function notMandatoryExtraValidatorShouldPassWithAbsentKey(): void
|
||||
{
|
||||
$subValidator = new Length(1, 3);
|
||||
$validator = new Key('bar', $subValidator, false);
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\KeyValue
|
||||
* @covers \Respect\Validation\Exceptions\KeyValueException
|
||||
* @covers \Respect\Validation\Rules\KeyValue
|
||||
*/
|
||||
class KeyValueTest extends TestCase
|
||||
{
|
||||
public function testShouldDefineValuesOnConstructor(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldDefineValuesOnConstructor(): void
|
||||
{
|
||||
$comparedKey = 'foo';
|
||||
$ruleName = 'equals';
|
||||
|
@ -35,35 +38,50 @@ class KeyValueTest extends TestCase
|
|||
self::assertSame($baseKey, $rule->baseKey);
|
||||
}
|
||||
|
||||
public function testShouldNotValidateWhenComparedKeyDoesNotExist(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotValidateWhenComparedKeyDoesNotExist(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'equals', 'bar');
|
||||
|
||||
self::assertFalse($rule->validate(['bar' => 42]));
|
||||
}
|
||||
|
||||
public function testShouldNotValidateWhenBaseKeyDoesNotExist(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotValidateWhenBaseKeyDoesNotExist(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'equals', 'bar');
|
||||
|
||||
self::assertFalse($rule->validate(['foo' => true]));
|
||||
}
|
||||
|
||||
public function testShouldNotValidateRuleIsNotValid(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotValidateRuleIsNotValid(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'probably_not_a_rule', 'bar');
|
||||
|
||||
self::assertFalse($rule->validate(['foo' => true, 'bar' => false]));
|
||||
}
|
||||
|
||||
public function testShouldValidateWhenDefinedValuesMatch(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldValidateWhenDefinedValuesMatch(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'equals', 'bar');
|
||||
|
||||
self::assertTrue($rule->validate(['foo' => 42, 'bar' => 42]));
|
||||
}
|
||||
|
||||
public function testShouldValidateWhenDefinedValuesDoesNotMatch(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldValidateWhenDefinedValuesDoesNotMatch(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'equals', 'bar');
|
||||
|
||||
|
@ -72,8 +90,10 @@ class KeyValueTest extends TestCase
|
|||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldAssertWhenDefinedValuesMatch(): void
|
||||
public function shouldAssertWhenDefinedValuesMatch(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'equals', 'bar');
|
||||
$rule->assert(['foo' => 42, 'bar' => 42]);
|
||||
|
@ -82,8 +102,10 @@ class KeyValueTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\AllOfException
|
||||
* @expectedExceptionMessage All of the required rules must pass for foo
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldAssertWhenDefinedValuesDoesNotMatch(): void
|
||||
public function shouldAssertWhenDefinedValuesDoesNotMatch(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'equals', 'bar');
|
||||
$rule->assert(['foo' => 43, 'bar' => 42]);
|
||||
|
@ -92,8 +114,10 @@ class KeyValueTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\KeyValueException
|
||||
* @expectedExceptionMessage "bar" must be valid to validate "foo"
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotAssertWhenRuleIsNotValid(): void
|
||||
public function shouldNotAssertWhenRuleIsNotValid(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'probably_not_a_rule', 'bar');
|
||||
$rule->assert(['foo' => 43, 'bar' => 42]);
|
||||
|
@ -101,8 +125,10 @@ class KeyValueTest extends TestCase
|
|||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldCheckWhenDefinedValuesMatch(): void
|
||||
public function shouldCheckWhenDefinedValuesMatch(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'equals', 'bar');
|
||||
$rule->check(['foo' => 42, 'bar' => 42]);
|
||||
|
@ -111,8 +137,10 @@ class KeyValueTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\EqualsException
|
||||
* @expectedExceptionMessage foo must equal "bar"
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldCheckWhenDefinedValuesDoesNotMatch(): void
|
||||
public function shouldCheckWhenDefinedValuesDoesNotMatch(): void
|
||||
{
|
||||
$rule = new KeyValue('foo', 'equals', 'bar');
|
||||
$rule->check(['foo' => 43, 'bar' => 42]);
|
||||
|
|
|
@ -18,8 +18,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\LeapDate
|
||||
* @covers \Respect\Validation\Exceptions\LeapDateException
|
||||
* @covers \Respect\Validation\Rules\LeapDate
|
||||
*/
|
||||
class LeapDateTest extends TestCase
|
||||
{
|
||||
|
@ -30,29 +30,44 @@ class LeapDateTest extends TestCase
|
|||
$this->leapDateValidator = new LeapDate('Y-m-d');
|
||||
}
|
||||
|
||||
public function testValidLeapDate_with_string(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validLeapDate_with_string(): void
|
||||
{
|
||||
self::assertTrue($this->leapDateValidator->validate('1988-02-29'));
|
||||
}
|
||||
|
||||
public function testValidLeapDate_with_date_time(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validLeapDate_with_date_time(): void
|
||||
{
|
||||
self::assertTrue($this->leapDateValidator->validate(
|
||||
new DateTime('1988-02-29')));
|
||||
}
|
||||
|
||||
public function testInvalidLeapDate_with_string(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function invalidLeapDate_with_string(): void
|
||||
{
|
||||
self::assertFalse($this->leapDateValidator->validate('1989-02-29'));
|
||||
}
|
||||
|
||||
public function testInvalidLeapDate_with_date_time(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function invalidLeapDate_with_date_time(): void
|
||||
{
|
||||
self::assertFalse($this->leapDateValidator->validate(
|
||||
new DateTime('1989-02-29')));
|
||||
}
|
||||
|
||||
public function testInvalidLeapDate_input(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function invalidLeapDate_input(): void
|
||||
{
|
||||
self::assertFalse($this->leapDateValidator->validate([]));
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\LeapYear
|
||||
* @covers \Respect\Validation\Exceptions\LeapYearException
|
||||
* @covers \Respect\Validation\Rules\LeapYear
|
||||
*/
|
||||
class LeapYearTest extends TestCase
|
||||
{
|
||||
|
@ -30,7 +30,10 @@ class LeapYearTest extends TestCase
|
|||
$this->leapYearValidator = new LeapYear();
|
||||
}
|
||||
|
||||
public function testValidLeapDate(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validLeapDate(): void
|
||||
{
|
||||
self::assertTrue($this->leapYearValidator->__invoke('2008'));
|
||||
self::assertTrue($this->leapYearValidator->__invoke('2008-02-29'));
|
||||
|
@ -39,7 +42,10 @@ class LeapYearTest extends TestCase
|
|||
new DateTime('2008-02-29')));
|
||||
}
|
||||
|
||||
public function testInvalidLeapDate(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function invalidLeapDate(): void
|
||||
{
|
||||
self::assertFalse($this->leapYearValidator->__invoke(''));
|
||||
self::assertFalse($this->leapYearValidator->__invoke('2009'));
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Length
|
||||
* @covers \Respect\Validation\Exceptions\LengthException
|
||||
* @covers \Respect\Validation\Rules\Length
|
||||
*/
|
||||
class LengthTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidLengthInclusive
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testLengthInsideBoundsForInclusiveCasesReturnTrue($string, $min, $max): void
|
||||
public function lengthInsideBoundsForInclusiveCasesReturnTrue($string, $min, $max): void
|
||||
{
|
||||
$validator = new Length($min, $max, true);
|
||||
self::assertTrue($validator->validate($string));
|
||||
|
@ -33,8 +35,10 @@ class LengthTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForValidLengthNonInclusive
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testLengthInsideBoundsForNonInclusiveCasesShouldReturnTrue($string, $min, $max): void
|
||||
public function lengthInsideBoundsForNonInclusiveCasesShouldReturnTrue($string, $min, $max): void
|
||||
{
|
||||
$validator = new Length($min, $max, false);
|
||||
self::assertTrue($validator->validate($string));
|
||||
|
@ -42,8 +46,10 @@ class LengthTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInvalidLengthInclusive
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testLengthOutsideBoundsForInclusiveCasesReturnFalse($string, $min, $max): void
|
||||
public function lengthOutsideBoundsForInclusiveCasesReturnFalse($string, $min, $max): void
|
||||
{
|
||||
$validator = new Length($min, $max, true);
|
||||
self::assertfalse($validator->validate($string));
|
||||
|
@ -51,8 +57,10 @@ class LengthTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInvalidLengthNonInclusive
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testLengthOutsideBoundsForNonInclusiveCasesReturnFalse($string, $min, $max): void
|
||||
public function lengthOutsideBoundsForNonInclusiveCasesReturnFalse($string, $min, $max): void
|
||||
{
|
||||
$validator = new Length($min, $max, false);
|
||||
self::assertfalse($validator->validate($string));
|
||||
|
@ -61,8 +69,10 @@ class LengthTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForComponentException
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testComponentExceptionsForInvalidParameters($min, $max): void
|
||||
public function componentExceptionsForInvalidParameters($min, $max): void
|
||||
{
|
||||
$buggyValidator = new Length($min, $max);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\MacAddress
|
||||
* @covers \Respect\Validation\Exceptions\MacAddressException
|
||||
* @covers \Respect\Validation\Rules\MacAddress
|
||||
*/
|
||||
class MacAddressTest extends TestCase
|
||||
{
|
||||
|
@ -31,8 +31,10 @@ class MacAddressTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForMacAddress
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidMacaddressesShouldReturnTrue($input): void
|
||||
public function validMacaddressesShouldReturnTrue($input): void
|
||||
{
|
||||
self::assertTrue($this->macaddressValidator->__invoke($input));
|
||||
$this->macaddressValidator->assert($input);
|
||||
|
@ -42,8 +44,10 @@ class MacAddressTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotMacAddress
|
||||
* @expectedException \Respect\Validation\Exceptions\MacAddressException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidMacaddressShouldThrowMacAddressException($input): void
|
||||
public function invalidMacaddressShouldThrowMacAddressException($input): void
|
||||
{
|
||||
self::assertFalse($this->macaddressValidator->__invoke($input));
|
||||
$this->macaddressValidator->assert($input);
|
||||
|
|
|
@ -19,8 +19,8 @@ use SplFileInfo;
|
|||
/**
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Mimetype
|
||||
* @covers \Respect\Validation\Exceptions\MimetypeException
|
||||
* @covers \Respect\Validation\Rules\Mimetype
|
||||
*/
|
||||
class MimetypeTest extends TestCase
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ class MimetypeTest extends TestCase
|
|||
protected function setUp()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
return $this->markTestSkipped('If you are a HHVM user, and you are in the mood, please fix it');
|
||||
return self::markTestSkipped('If you are a HHVM user, and you are in the mood, please fix it');
|
||||
}
|
||||
|
||||
$this->filename = sprintf('%s/validation.txt', sys_get_temp_dir());
|
||||
|
@ -42,7 +42,10 @@ class MimetypeTest extends TestCase
|
|||
unlink($this->filename);
|
||||
}
|
||||
|
||||
public function testShouldValidateMimetype(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldValidateMimetype(): void
|
||||
{
|
||||
$mimetype = 'plain/text';
|
||||
|
||||
|
@ -53,17 +56,20 @@ class MimetypeTest extends TestCase
|
|||
->getMock();
|
||||
|
||||
$fileInfoMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('file')
|
||||
->with($this->filename)
|
||||
->will($this->returnValue($mimetype));
|
||||
->will(self::returnValue($mimetype));
|
||||
|
||||
$rule = new Mimetype($mimetype, $fileInfoMock);
|
||||
|
||||
$rule->validate($this->filename);
|
||||
}
|
||||
|
||||
public function testShouldValidateSplFileInfoMimetype(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldValidateSplFileInfoMimetype(): void
|
||||
{
|
||||
$fileInfo = new SplFileInfo($this->filename);
|
||||
$mimetype = 'plain/text';
|
||||
|
@ -75,24 +81,30 @@ class MimetypeTest extends TestCase
|
|||
->getMock();
|
||||
|
||||
$fileInfoMock
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('file')
|
||||
->with($fileInfo->getPathname())
|
||||
->will($this->returnValue($mimetype));
|
||||
->will(self::returnValue($mimetype));
|
||||
|
||||
$rule = new Mimetype($mimetype, $fileInfoMock);
|
||||
|
||||
self::assertTrue($rule->validate($fileInfo));
|
||||
}
|
||||
|
||||
public function testShouldInvalidateWhenNotStringNorSplFileInfo(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldInvalidateWhenNotStringNorSplFileInfo(): void
|
||||
{
|
||||
$rule = new Mimetype('application/octet-stream');
|
||||
|
||||
self::assertFalse($rule->validate([__FILE__]));
|
||||
}
|
||||
|
||||
public function testShouldInvalidateWhenItIsNotAValidFile(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldInvalidateWhenItIsNotAValidFile(): void
|
||||
{
|
||||
$rule = new Mimetype('application/octet-stream');
|
||||
|
||||
|
@ -102,8 +114,10 @@ class MimetypeTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\MimetypeException
|
||||
* @expectedExceptionMessageRegExp #".+MimetypeTest.php" must have "application.?/json" mimetype#
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowMimetypeExceptionWhenCheckingValue(): void
|
||||
public function shouldThrowMimetypeExceptionWhenCheckingValue(): void
|
||||
{
|
||||
$rule = new Mimetype('application/json');
|
||||
$rule->check(__FILE__);
|
||||
|
|
|
@ -23,8 +23,8 @@ use function strtotime;
|
|||
/**
|
||||
* @group rule
|
||||
*
|
||||
* @covers \Respect\Validation\Rules\MinAge
|
||||
* @covers \Respect\Validation\Rules\AbstractAge
|
||||
* @covers \Respect\Validation\Rules\MinAge
|
||||
*
|
||||
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\NfeAccessKey
|
||||
* @covers \Respect\Validation\Exceptions\NfeAccessKeyException
|
||||
* @covers \Respect\Validation\Rules\NfeAccessKey
|
||||
*/
|
||||
class NfeAccessKeyTest extends TestCase
|
||||
{
|
||||
|
@ -31,8 +31,10 @@ class NfeAccessKeyTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider validAccessKeyProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidAccessKey($aK): void
|
||||
public function validAccessKey($aK): void
|
||||
{
|
||||
$this->nfeValidator->assert($aK);
|
||||
self::assertTrue($this->nfeValidator->__invoke($aK));
|
||||
|
@ -42,8 +44,10 @@ class NfeAccessKeyTest extends TestCase
|
|||
/**
|
||||
* @dataProvider invalidAccessKeyProvider
|
||||
* @expectedException \Respect\Validation\Exceptions\NfeAccessKeyException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidAccessKey($aK): void
|
||||
public function invalidAccessKey($aK): void
|
||||
{
|
||||
$this->nfeValidator->assert($aK);
|
||||
}
|
||||
|
@ -51,8 +55,10 @@ class NfeAccessKeyTest extends TestCase
|
|||
/**
|
||||
* @dataProvider invalidAccessKeyLengthProvider
|
||||
* @expectedException \Respect\Validation\Exceptions\NfeAccessKeyException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidLengthCnh($aK): void
|
||||
public function invalidLengthCnh($aK): void
|
||||
{
|
||||
$this->nfeValidator->assert($aK);
|
||||
}
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\No
|
||||
* @covers \Respect\Validation\Exceptions\NoException
|
||||
* @covers \Respect\Validation\Rules\No
|
||||
*/
|
||||
class NoTest extends TestCase
|
||||
{
|
||||
public function testShouldUseDefaultPattern(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldUseDefaultPattern(): void
|
||||
{
|
||||
$rule = new No();
|
||||
|
||||
|
@ -32,10 +35,13 @@ class NoTest extends TestCase
|
|||
self::assertEquals($expectedPattern, $actualPattern);
|
||||
}
|
||||
|
||||
public function testShouldUseLocalPatternForNoExpressionWhenDefined(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldUseLocalPatternForNoExpressionWhenDefined(): void
|
||||
{
|
||||
if (!defined('NOEXPR')) {
|
||||
$this->markTestSkipped('Constant NOEXPR is not defined');
|
||||
self::markTestSkipped('Constant NOEXPR is not defined');
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -50,8 +56,10 @@ class NoTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider validNoProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
public function shouldValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
{
|
||||
$rule = new No();
|
||||
|
||||
|
@ -72,8 +80,10 @@ class NoTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider invalidNoProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
public function shouldNotValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
{
|
||||
$rule = new No();
|
||||
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\NoneOf
|
||||
* @covers \Respect\Validation\Exceptions\NoneOfException
|
||||
* @covers \Respect\Validation\Rules\NoneOf
|
||||
*/
|
||||
class NoneOfTest extends TestCase
|
||||
{
|
||||
public function testValid(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function valid(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
|
@ -41,8 +44,10 @@ class NoneOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\NoneOfException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalid(): void
|
||||
public function invalid(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
|
|
|
@ -18,15 +18,17 @@ use stdClass;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\NotBlank
|
||||
* @covers \Respect\Validation\Exceptions\NotBlankException
|
||||
* @covers \Respect\Validation\Rules\NotBlank
|
||||
*/
|
||||
class NotBlankTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForNotBlank
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateWhenNotBlank($input): void
|
||||
public function shouldValidateWhenNotBlank($input): void
|
||||
{
|
||||
$rule = new NotBlank();
|
||||
|
||||
|
@ -35,8 +37,10 @@ class NotBlankTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForBlank
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidateWhenBlank($input): void
|
||||
public function shouldNotValidateWhenBlank($input): void
|
||||
{
|
||||
$rule = new NotBlank();
|
||||
|
||||
|
@ -46,8 +50,10 @@ class NotBlankTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\NotBlankException
|
||||
* @expectedExceptionMessage The value must not be blank
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowExceptionWhenFailure(): void
|
||||
public function shouldThrowExceptionWhenFailure(): void
|
||||
{
|
||||
$rule = new NotBlank();
|
||||
$rule->check(0);
|
||||
|
@ -56,8 +62,10 @@ class NotBlankTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\NotBlankException
|
||||
* @expectedExceptionMessage whatever must not be blank
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowExceptionWhenFailureAndDoesHaveAName(): void
|
||||
public function shouldThrowExceptionWhenFailureAndDoesHaveAName(): void
|
||||
{
|
||||
$rule = new NotBlank();
|
||||
$rule->setName('whatever');
|
||||
|
|
|
@ -24,8 +24,10 @@ class NotOptionalTest extends TestCase
|
|||
{
|
||||
/**
|
||||
* @dataProvider providerForNotOptional
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateWhenNotOptional($input): void
|
||||
public function shouldValidateWhenNotOptional($input): void
|
||||
{
|
||||
$rule = new NotOptional();
|
||||
|
||||
|
@ -34,8 +36,10 @@ class NotOptionalTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForOptional
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidateWhenOptional($input): void
|
||||
public function shouldNotValidateWhenOptional($input): void
|
||||
{
|
||||
$rule = new NotOptional();
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ use Respect\Validation\Validator;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Not
|
||||
* @covers \Respect\Validation\Exceptions\NotException
|
||||
* @covers \Respect\Validation\Rules\Not
|
||||
*/
|
||||
class NotTest extends TestCase
|
||||
{
|
||||
|
@ -27,8 +27,10 @@ class NotTest extends TestCase
|
|||
* @doesNotPerformAssertions
|
||||
*
|
||||
* @dataProvider providerForValidNot
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNot($v, $input): void
|
||||
public function not($v, $input): void
|
||||
{
|
||||
$not = new Not($v);
|
||||
$not->assert($input);
|
||||
|
@ -37,8 +39,10 @@ class NotTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidNot
|
||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotNotHaha($v, $input): void
|
||||
public function notNotHaha($v, $input): void
|
||||
{
|
||||
$not = new Not($v);
|
||||
$not->assert($input);
|
||||
|
@ -46,8 +50,10 @@ class NotTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForSetName
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotSetName($v): void
|
||||
public function notSetName($v): void
|
||||
{
|
||||
$not = new Not($v);
|
||||
$not->setName('Foo');
|
||||
|
|
|
@ -60,12 +60,12 @@ final class NullableTest extends TestCase
|
|||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('validate');
|
||||
|
||||
$rule = new Nullable($validatable);
|
||||
|
||||
$this->assertTrue($rule->validate(null));
|
||||
self::assertTrue($rule->validate(null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,14 +79,14 @@ final class NullableTest extends TestCase
|
|||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('validate')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$rule = new Nullable($validatable);
|
||||
|
||||
$this->assertTrue($rule->validate($input));
|
||||
self::assertTrue($rule->validate($input));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,7 +96,7 @@ final class NullableTest extends TestCase
|
|||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('assert');
|
||||
|
||||
$rule = new Nullable($validatable);
|
||||
|
@ -114,10 +114,10 @@ final class NullableTest extends TestCase
|
|||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('assert')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$rule = new Nullable($validatable);
|
||||
$rule->assert($input);
|
||||
|
@ -130,7 +130,7 @@ final class NullableTest extends TestCase
|
|||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('check');
|
||||
|
||||
$rule = new Nullable($validatable);
|
||||
|
@ -148,10 +148,10 @@ final class NullableTest extends TestCase
|
|||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('check')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$rule = new Nullable($validatable);
|
||||
$rule->check($input);
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\NumericVal
|
||||
* @covers \Respect\Validation\Exceptions\NumericValException
|
||||
* @covers \Respect\Validation\Rules\NumericVal
|
||||
*/
|
||||
class NumericValTest extends TestCase
|
||||
{
|
||||
|
@ -31,8 +31,10 @@ class NumericValTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNumeric
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNumeric($input): void
|
||||
public function numeric($input): void
|
||||
{
|
||||
self::assertTrue($this->object->__invoke($input));
|
||||
$this->object->check($input);
|
||||
|
@ -42,8 +44,10 @@ class NumericValTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotNumeric
|
||||
* @expectedException \Respect\Validation\Exceptions\NumericValException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotNumeric($input): void
|
||||
public function notNumeric($input): void
|
||||
{
|
||||
self::assertFalse($this->object->__invoke($input));
|
||||
$this->object->assert($input);
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\OneOf
|
||||
* @covers \Respect\Validation\Exceptions\OneOfException
|
||||
* @covers \Respect\Validation\Rules\OneOf
|
||||
*/
|
||||
class OneOfTest extends TestCase
|
||||
{
|
||||
public function testValid(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function valid(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
|
@ -43,8 +46,10 @@ class OneOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\OneOfException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testEmptyChain(): void
|
||||
public function emptyChain(): void
|
||||
{
|
||||
$rule = new OneOf();
|
||||
|
||||
|
@ -54,8 +59,10 @@ class OneOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\OneOfException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalid(): void
|
||||
public function invalid(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return false;
|
||||
|
@ -73,8 +80,10 @@ class OneOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\OneOfException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidMultipleAssert(): void
|
||||
public function invalidMultipleAssert(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return true;
|
||||
|
@ -93,8 +102,10 @@ class OneOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\CallbackException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidMultipleCheck(): void
|
||||
public function invalidMultipleCheck(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return true;
|
||||
|
@ -114,8 +125,10 @@ class OneOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\OneOfException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidMultipleCheckAllValid(): void
|
||||
public function invalidMultipleCheckAllValid(): void
|
||||
{
|
||||
$valid1 = new Callback(function () {
|
||||
return true;
|
||||
|
@ -135,8 +148,10 @@ class OneOfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\XdigitException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidCheck(): void
|
||||
public function invalidCheck(): void
|
||||
{
|
||||
$rule = new OneOf(new Xdigit(), new Alnum());
|
||||
self::assertFalse($rule->validate(-10));
|
||||
|
|
|
@ -54,12 +54,14 @@ class OptionalTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForOptional
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidateRuleWhenInputIsOptional($input): void
|
||||
public function shouldNotValidateRuleWhenInputIsOptional($input): void
|
||||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('validate');
|
||||
|
||||
$rule = new Optional($validatable);
|
||||
|
@ -69,26 +71,31 @@ class OptionalTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForNotOptional
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateRuleWhenInputIsNotOptional($input): void
|
||||
public function shouldValidateRuleWhenInputIsNotOptional($input): void
|
||||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('validate')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$rule = new Optional($validatable);
|
||||
|
||||
self::assertTrue($rule->validate($input));
|
||||
}
|
||||
|
||||
public function testShouldNotAssertRuleWhenInputIsOptional(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotAssertRuleWhenInputIsOptional(): void
|
||||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('assert');
|
||||
|
||||
$rule = new Optional($validatable);
|
||||
|
@ -96,27 +103,33 @@ class OptionalTest extends TestCase
|
|||
$rule->assert('');
|
||||
}
|
||||
|
||||
public function testShouldAssertRuleWhenInputIsNotOptional(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldAssertRuleWhenInputIsNotOptional(): void
|
||||
{
|
||||
$input = 'foo';
|
||||
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('assert')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$rule = new Optional($validatable);
|
||||
|
||||
$rule->assert($input);
|
||||
}
|
||||
|
||||
public function testShouldNotCheckRuleWhenInputIsOptional(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotCheckRuleWhenInputIsOptional(): void
|
||||
{
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->never())
|
||||
->expects(self::never())
|
||||
->method('check');
|
||||
|
||||
$rule = new Optional($validatable);
|
||||
|
@ -124,16 +137,19 @@ class OptionalTest extends TestCase
|
|||
$rule->check('');
|
||||
}
|
||||
|
||||
public function testShouldCheckRuleWhenInputIsNotOptional(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldCheckRuleWhenInputIsNotOptional(): void
|
||||
{
|
||||
$input = 'foo';
|
||||
|
||||
$validatable = $this->createMock(Validatable::class);
|
||||
$validatable
|
||||
->expects($this->once())
|
||||
->expects(self::once())
|
||||
->method('check')
|
||||
->with($input)
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
$rule = new Optional($validatable);
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Phone
|
||||
* @covers \Respect\Validation\Exceptions\PhoneException
|
||||
* @covers \Respect\Validation\Rules\Phone
|
||||
*/
|
||||
class PhoneTest extends TestCase
|
||||
{
|
||||
|
@ -31,8 +31,10 @@ class PhoneTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForPhone
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidPhoneShouldReturnTrue($input): void
|
||||
public function validPhoneShouldReturnTrue($input): void
|
||||
{
|
||||
self::assertTrue($this->phoneValidator->__invoke($input));
|
||||
$this->phoneValidator->assert($input);
|
||||
|
@ -42,8 +44,10 @@ class PhoneTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotPhone
|
||||
* @expectedException \Respect\Validation\Exceptions\PhoneException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidPhoneShouldThrowPhoneException($input): void
|
||||
public function invalidPhoneShouldThrowPhoneException($input): void
|
||||
{
|
||||
self::assertFalse($this->phoneValidator->__invoke($input));
|
||||
$this->phoneValidator->assert($input);
|
||||
|
|
|
@ -17,8 +17,8 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\PhpLabel
|
||||
* @covers \Respect\Validation\Exceptions\PhpLabelException
|
||||
* @covers \Respect\Validation\Rules\PhpLabel
|
||||
*/
|
||||
class PhpLabelTest extends RuleTestCase
|
||||
{
|
||||
|
|
|
@ -18,8 +18,8 @@ use stdClass;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Pis
|
||||
* @covers \Respect\Validation\Exceptions\PisException
|
||||
* @covers \Respect\Validation\Rules\Pis
|
||||
*
|
||||
* @author Bruno Koga <brunokoga187@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\PostalCode
|
||||
* @covers \Respect\Validation\Exceptions\PostalCodeException
|
||||
* @covers \Respect\Validation\Rules\PostalCode
|
||||
*/
|
||||
class PostalCodeTest extends TestCase
|
||||
{
|
||||
public function testShouldUsePatternAccordingToCountryCode(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldUsePatternAccordingToCountryCode(): void
|
||||
{
|
||||
$countryCode = 'BR';
|
||||
|
||||
|
@ -34,7 +37,10 @@ class PostalCodeTest extends TestCase
|
|||
self::assertEquals($expectedPattern, $actualPattern);
|
||||
}
|
||||
|
||||
public function testShouldUseDefaultPatternWhenCountryCodeDoesNotHavePostalCode(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldUseDefaultPatternWhenCountryCodeDoesNotHavePostalCode(): void
|
||||
{
|
||||
$rule = new PostalCode('ZW');
|
||||
|
||||
|
@ -44,14 +50,20 @@ class PostalCodeTest extends TestCase
|
|||
self::assertEquals($expectedPattern, $actualPattern);
|
||||
}
|
||||
|
||||
public function testShouldValidateEmptyStringsWhenUsingDefaultPattern(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldValidateEmptyStringsWhenUsingDefaultPattern(): void
|
||||
{
|
||||
$rule = new PostalCode('ZW');
|
||||
|
||||
self::assertTrue($rule->validate(''));
|
||||
}
|
||||
|
||||
public function testShouldNotValidateNonEmptyStringsWhenUsingDefaultPattern(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldNotValidateNonEmptyStringsWhenUsingDefaultPattern(): void
|
||||
{
|
||||
$rule = new PostalCode('ZW');
|
||||
|
||||
|
@ -61,16 +73,20 @@ class PostalCodeTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage Cannot validate postal code from "Whatever" country
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowsExceptionWhenCountryCodeIsNotValid(): void
|
||||
public function shouldThrowsExceptionWhenCountryCodeIsNotValid(): void
|
||||
{
|
||||
new PostalCode('Whatever');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validPostalCodesProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidatePatternAccordingToTheDefinedCountryCode($countryCode, $postalCode): void
|
||||
public function shouldValidatePatternAccordingToTheDefinedCountryCode($countryCode, $postalCode): void
|
||||
{
|
||||
$rule = new PostalCode($countryCode);
|
||||
|
||||
|
@ -92,8 +108,10 @@ class PostalCodeTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPostalCodesProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidatePatternAccordingToTheDefinedCountryCode($countryCode, $postalCode): void
|
||||
public function shouldNotValidatePatternAccordingToTheDefinedCountryCode($countryCode, $postalCode): void
|
||||
{
|
||||
$rule = new PostalCode($countryCode);
|
||||
|
||||
|
@ -103,8 +121,10 @@ class PostalCodeTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\PostalCodeException
|
||||
* @expectedExceptionMessage "02179-000" must be a valid postal code on "US"
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowsPostalCodeExceptionWhenValidationFails(): void
|
||||
public function shouldThrowsPostalCodeExceptionWhenValidationFails(): void
|
||||
{
|
||||
$rule = new PostalCode('US');
|
||||
$rule->check('02179-000');
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Punct
|
||||
* @covers \Respect\Validation\Exceptions\PunctException
|
||||
* @covers \Respect\Validation\Rules\Punct
|
||||
*/
|
||||
class PunctTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidPunct
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidDataWithPunctShouldReturnTrue($validPunct, $additional = ''): void
|
||||
public function validDataWithPunctShouldReturnTrue($validPunct, $additional = ''): void
|
||||
{
|
||||
$validator = new Punct($additional);
|
||||
self::assertTrue($validator->validate($validPunct));
|
||||
|
@ -34,8 +36,10 @@ class PunctTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidPunct
|
||||
* @expectedException \Respect\Validation\Exceptions\PunctException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidPunctShouldFailAndThrowPunctException($invalidPunct, $additional = ''): void
|
||||
public function invalidPunctShouldFailAndThrowPunctException($invalidPunct, $additional = ''): void
|
||||
{
|
||||
$validator = new Punct($additional);
|
||||
self::assertFalse($validator->validate($invalidPunct));
|
||||
|
@ -45,16 +49,20 @@ class PunctTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
{
|
||||
$validator = new Punct($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Punct($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -30,15 +30,17 @@ function is_readable($readable)
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Readable
|
||||
* @covers \Respect\Validation\Exceptions\ReadableException
|
||||
* @covers \Respect\Validation\Rules\Readable
|
||||
*/
|
||||
class ReadableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\Readable::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidReadableFileShouldReturnTrue(): void
|
||||
public function validReadableFileShouldReturnTrue(): void
|
||||
{
|
||||
$GLOBALS['is_readable'] = true;
|
||||
|
||||
|
@ -49,8 +51,10 @@ class ReadableTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\Readable::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidReadableFileShouldReturnFalse(): void
|
||||
public function invalidReadableFileShouldReturnFalse(): void
|
||||
{
|
||||
$GLOBALS['is_readable'] = false;
|
||||
|
||||
|
@ -61,14 +65,16 @@ class ReadableTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\Readable::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateObjects(): void
|
||||
public function shouldValidateObjects(): void
|
||||
{
|
||||
$rule = new Readable();
|
||||
$object = $this->createMock('SplFileInfo', ['isReadable'], ['somefile.txt']);
|
||||
$object->expects($this->once())
|
||||
$object->expects(self::once())
|
||||
->method('isReadable')
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
self::assertTrue($rule->validate($object));
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Roman
|
||||
* @covers \Respect\Validation\Exceptions\RomanException
|
||||
* @covers \Respect\Validation\Rules\Roman
|
||||
*/
|
||||
class RomanTest extends TestCase
|
||||
{
|
||||
|
@ -31,8 +31,10 @@ class RomanTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForRoman
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidRomansShouldReturnTrue($input): void
|
||||
public function validRomansShouldReturnTrue($input): void
|
||||
{
|
||||
self::assertTrue($this->romanValidator->__invoke($input));
|
||||
$this->romanValidator->assert($input);
|
||||
|
@ -42,8 +44,10 @@ class RomanTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotRoman
|
||||
* @expectedException \Respect\Validation\Exceptions\RomanException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidRomansShouldThrowRomanException($input): void
|
||||
public function invalidRomansShouldThrowRomanException($input): void
|
||||
{
|
||||
self::assertFalse($this->romanValidator->__invoke($input));
|
||||
$this->romanValidator->assert($input);
|
||||
|
|
|
@ -19,12 +19,15 @@ use Respect\Validation\Validator as v;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Sf
|
||||
* @covers \Respect\Validation\Exceptions\SfException
|
||||
* @covers \Respect\Validation\Rules\Sf
|
||||
*/
|
||||
class SfTest extends TestCase
|
||||
{
|
||||
public function testValidationWithAnExistingValidationConstraint(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validationWithAnExistingValidationConstraint(): void
|
||||
{
|
||||
$constraintName = 'Time';
|
||||
$validConstraintValue = '04:20:00';
|
||||
|
@ -42,9 +45,11 @@ class SfTest extends TestCase
|
|||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*
|
||||
* @depends testValidationWithAnExistingValidationConstraint
|
||||
* @depends validationWithAnExistingValidationConstraint
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAssertionWithAnExistingValidationConstraint(): void
|
||||
public function assertionWithAnExistingValidationConstraint(): void
|
||||
{
|
||||
$constraintName = 'Time';
|
||||
$validConstraintValue = '04:20:00';
|
||||
|
@ -52,9 +57,11 @@ class SfTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @depends testAssertionWithAnExistingValidationConstraint
|
||||
* @depends assertionWithAnExistingValidationConstraint
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAssertionMessageWithAnExistingValidationConstraint()
|
||||
public function assertionMessageWithAnExistingValidationConstraint()
|
||||
{
|
||||
$constraintName = 'Time';
|
||||
$invalidConstraintValue = '34:90:70';
|
||||
|
@ -72,14 +79,16 @@ EOF;
|
|||
'Exception message is different from the one expected.'
|
||||
);
|
||||
}
|
||||
$this->fail('Validation exception expected to compare message.');
|
||||
self::fail('Validation exception expected to compare message.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage Symfony/Validator constraint "FluxCapacitor" does not exist.
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidationWithNonExistingConstraint(): void
|
||||
public function validationWithNonExistingConstraint(): void
|
||||
{
|
||||
$fantasyConstraintName = 'FluxCapacitor';
|
||||
$fantasyValue = '8GW';
|
||||
|
|
|
@ -21,8 +21,8 @@ use SplFileInfo;
|
|||
/**
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Size
|
||||
* @covers \Respect\Validation\Exceptions\SizeException
|
||||
* @covers \Respect\Validation\Rules\Size
|
||||
*/
|
||||
class SizeTest extends TestCase
|
||||
{
|
||||
|
@ -74,8 +74,10 @@ class SizeTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider validSizeProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldConvertUnitonConstructor($size, $bytes): void
|
||||
public function shouldConvertUnitonConstructor($size, $bytes): void
|
||||
{
|
||||
$rule = new Size($size);
|
||||
|
||||
|
@ -85,23 +87,30 @@ class SizeTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "42jb" is not a recognized file size
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowsAnExceptionWhenSizeIsNotValid(): void
|
||||
public function shouldThrowsAnExceptionWhenSizeIsNotValid(): void
|
||||
{
|
||||
new Size('42jb');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validFileProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateFile($filename, $minSize, $maxSize, $expectedValidation): void
|
||||
public function shouldValidateFile($filename, $minSize, $maxSize, $expectedValidation): void
|
||||
{
|
||||
$rule = new Size($minSize, $maxSize);
|
||||
|
||||
self::assertEquals($expectedValidation, $rule->validate($filename));
|
||||
}
|
||||
|
||||
public function testShouldValidateSplFileInfo(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldValidateSplFileInfo(): void
|
||||
{
|
||||
$root = vfsStream::setup();
|
||||
$file1Gb = vfsStream::newFile('1gb.txt')->withContent(LargeFileContent::withGigabytes(1))->at($root);
|
||||
|
@ -115,8 +124,10 @@ class SizeTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\SizeException
|
||||
* @expectedExceptionMessageRegExp #"vfs:.?/.?/root.?/1gb.txt" must be greater than "2pb"#
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowsSizeExceptionWhenAsserting(): void
|
||||
public function shouldThrowsSizeExceptionWhenAsserting(): void
|
||||
{
|
||||
$root = vfsStream::setup();
|
||||
$file1Gb = vfsStream::newFile('1gb.txt')->withContent(LargeFileContent::withGigabytes(1))->at($root);
|
||||
|
|
|
@ -23,8 +23,10 @@ class SlugTest extends TestCase
|
|||
{
|
||||
/**
|
||||
* @dataProvider providerValidSlug
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidSlug($input): void
|
||||
public function validSlug($input): void
|
||||
{
|
||||
$rule = new Slug();
|
||||
|
||||
|
@ -33,8 +35,10 @@ class SlugTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerInvalidSlug
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidSlug($input): void
|
||||
public function invalidSlug($input): void
|
||||
{
|
||||
$rule = new Slug();
|
||||
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Sorted
|
||||
* @covers \Respect\Validation\Exceptions\SortedException
|
||||
* @covers \Respect\Validation\Rules\Sorted
|
||||
*/
|
||||
class SortedTest extends TestCase
|
||||
{
|
||||
public function testPasses(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function passes(): void
|
||||
{
|
||||
$arr = [1, 2, 3];
|
||||
$rule = new Sorted();
|
||||
|
@ -32,7 +35,10 @@ class SortedTest extends TestCase
|
|||
$rule->check($arr);
|
||||
}
|
||||
|
||||
public function testPassesWithEqualValues(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function passesWithEqualValues(): void
|
||||
{
|
||||
$arr = [1, 2, 2, 3];
|
||||
$rule = new Sorted();
|
||||
|
@ -44,8 +50,10 @@ class SortedTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\SortedException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotPasses(): void
|
||||
public function notPasses(): void
|
||||
{
|
||||
$arr = [1, 2, 4, 3];
|
||||
$rule = new Sorted();
|
||||
|
@ -54,7 +62,10 @@ class SortedTest extends TestCase
|
|||
$rule->check($arr);
|
||||
}
|
||||
|
||||
public function testPassesDescending(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function passesDescending(): void
|
||||
{
|
||||
$arr = [10, 9, 8];
|
||||
$rule = new Sorted(null, false);
|
||||
|
@ -64,7 +75,10 @@ class SortedTest extends TestCase
|
|||
$rule->check($arr);
|
||||
}
|
||||
|
||||
public function testPassesDescendingWithEqualValues(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function passesDescendingWithEqualValues(): void
|
||||
{
|
||||
$arr = [10, 9, 9, 8];
|
||||
$rule = new Sorted(null, false);
|
||||
|
@ -74,7 +88,10 @@ class SortedTest extends TestCase
|
|||
$rule->check($arr);
|
||||
}
|
||||
|
||||
public function testPassesByFunction(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function passesByFunction(): void
|
||||
{
|
||||
$arr = [
|
||||
[
|
||||
|
@ -98,8 +115,10 @@ class SortedTest extends TestCase
|
|||
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\SortedException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotPassesByFunction(): void
|
||||
public function notPassesByFunction(): void
|
||||
{
|
||||
$arr = [
|
||||
[
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Space
|
||||
* @covers \Respect\Validation\Exceptions\SpaceException
|
||||
* @covers \Respect\Validation\Rules\Space
|
||||
*/
|
||||
class SpaceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidSpace
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidDataWithSpaceShouldReturnTrue($validSpace, $additional = ''): void
|
||||
public function validDataWithSpaceShouldReturnTrue($validSpace, $additional = ''): void
|
||||
{
|
||||
$validator = new Space($additional);
|
||||
self::assertTrue($validator->validate($validSpace));
|
||||
|
@ -34,8 +36,10 @@ class SpaceTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidSpace
|
||||
* @expectedException \Respect\Validation\Exceptions\SpaceException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidSpaceShouldFailAndThrowSpaceException($invalidSpace, $additional = ''): void
|
||||
public function invalidSpaceShouldFailAndThrowSpaceException($invalidSpace, $additional = ''): void
|
||||
{
|
||||
$validator = new Space($additional);
|
||||
self::assertFalse($validator->validate($invalidSpace));
|
||||
|
@ -45,16 +49,20 @@ class SpaceTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
{
|
||||
$validator = new Space($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Space($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\StartsWith
|
||||
* @covers \Respect\Validation\Exceptions\StartsWithException
|
||||
* @covers \Respect\Validation\Rules\StartsWith
|
||||
*/
|
||||
class StartsWithTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForStartsWith
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testStartsWith($start, $input): void
|
||||
public function startsWith($start, $input): void
|
||||
{
|
||||
$v = new StartsWith($start);
|
||||
self::assertTrue($v->__invoke($input));
|
||||
|
@ -36,8 +38,10 @@ class StartsWithTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotStartsWith
|
||||
* @expectedException \Respect\Validation\Exceptions\StartsWithException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testNotStartsWith($start, $input, $caseSensitive = false): void
|
||||
public function notStartsWith($start, $input, $caseSensitive = false): void
|
||||
{
|
||||
$v = new StartsWith($start, $caseSensitive);
|
||||
self::assertFalse($v->__invoke($input));
|
||||
|
|
|
@ -16,16 +16,18 @@ namespace Respect\Validation\Rules;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\SubdivisionCode
|
||||
* @covers \Respect\Validation\Exceptions\SubdivisionCodeException
|
||||
* @covers \Respect\Validation\Rules\SubdivisionCode
|
||||
*/
|
||||
class SubdivisionCodeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "whatever" is not a supported country code
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowsExceptionWhenInvalidFormat(): void
|
||||
public function shouldThrowsExceptionWhenInvalidFormat(): void
|
||||
{
|
||||
new SubdivisionCode('whatever');
|
||||
}
|
||||
|
@ -33,13 +35,18 @@ class SubdivisionCodeTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "JK" is not a supported country code
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotAcceptWrongNamesOnConstructor(): void
|
||||
public function shouldNotAcceptWrongNamesOnConstructor(): void
|
||||
{
|
||||
new SubdivisionCode('JK');
|
||||
}
|
||||
|
||||
public function testShouldDefineASubdivisionCodeFormatOnConstructor(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldDefineASubdivisionCodeFormatOnConstructor(): void
|
||||
{
|
||||
$countryCode = 'US';
|
||||
$countrySubdivision = new SubdivisionCode($countryCode);
|
||||
|
@ -60,8 +67,10 @@ class SubdivisionCodeTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForValidSubdivisionCodeInformation
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateValidSubdivisionCodeInformation($countryCode, $input): void
|
||||
public function shouldValidateValidSubdivisionCodeInformation($countryCode, $input): void
|
||||
{
|
||||
$countrySubdivision = new SubdivisionCode($countryCode);
|
||||
|
||||
|
@ -79,8 +88,10 @@ class SubdivisionCodeTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForInvalidSubdivisionCodeInformation
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidateInvalidSubdivisionCodeInformation($countryCode, $input): void
|
||||
public function shouldNotValidateInvalidSubdivisionCodeInformation($countryCode, $input): void
|
||||
{
|
||||
$countrySubdivision = new SubdivisionCode($countryCode);
|
||||
|
||||
|
@ -90,8 +101,10 @@ class SubdivisionCodeTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\Locale\BrSubdivisionCodeException
|
||||
* @expectedExceptionMessage "CA" must be a subdivision code of Brazil
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowsSubdivisionCodeException(): void
|
||||
public function shouldThrowsSubdivisionCodeException(): void
|
||||
{
|
||||
$countrySubdivision = new SubdivisionCode('BR');
|
||||
$countrySubdivision->assert('CA');
|
||||
|
|
|
@ -30,15 +30,17 @@ function is_link($link)
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\SymbolicLink
|
||||
* @covers \Respect\Validation\Exceptions\SymbolicLinkException
|
||||
* @covers \Respect\Validation\Rules\SymbolicLink
|
||||
*/
|
||||
class SymbolicLinkTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\SymbolicLink::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidSymbolicLinkShouldReturnTrue(): void
|
||||
public function validSymbolicLinkShouldReturnTrue(): void
|
||||
{
|
||||
$GLOBALS['is_link'] = true;
|
||||
|
||||
|
@ -49,8 +51,10 @@ class SymbolicLinkTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\SymbolicLink::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidSymbolicLinkShouldThrowException(): void
|
||||
public function invalidSymbolicLinkShouldThrowException(): void
|
||||
{
|
||||
$GLOBALS['is_link'] = false;
|
||||
|
||||
|
@ -61,14 +65,16 @@ class SymbolicLinkTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\SymbolicLink::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateObjects(): void
|
||||
public function shouldValidateObjects(): void
|
||||
{
|
||||
$rule = new SymbolicLink();
|
||||
$object = $this->createMock('SplFileInfo', ['isLink'], ['somelink.lnk']);
|
||||
$object->expects($this->once())
|
||||
$object->expects(self::once())
|
||||
->method('isLink')
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
self::assertTrue($rule->validate($object));
|
||||
}
|
||||
|
|
|
@ -30,8 +30,10 @@ class TypeTest extends RuleTestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "whatever" is not a valid type (Available: array, bool, boolean, callable, double, float, int, integer, null, object, resource, string)
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowExceptionWhenTypeIsNotValid(): void
|
||||
public function shouldThrowExceptionWhenTypeIsNotValid(): void
|
||||
{
|
||||
new Type('whatever');
|
||||
}
|
||||
|
|
|
@ -22,7 +22,10 @@ use Respect\Validation\Validatable;
|
|||
*/
|
||||
final class VatinTest extends TestCase
|
||||
{
|
||||
public function testShouldAcceptCountryCodeOnConstructor(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldAcceptCountryCodeOnConstructor(): void
|
||||
{
|
||||
$countryCode = 'PL';
|
||||
$rule = new Vatin($countryCode);
|
||||
|
@ -33,8 +36,10 @@ final class VatinTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "BR" is not a supported country code
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowAnExceptionWhenCountryCodeIsNotSupported(): void
|
||||
public function shouldThrowAnExceptionWhenCountryCodeIsNotSupported(): void
|
||||
{
|
||||
new Vatin('BR');
|
||||
}
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Version
|
||||
* @covers \Respect\Validation\Exceptions\VersionException
|
||||
* @covers \Respect\Validation\Rules\Version
|
||||
*/
|
||||
class VersionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidVersion
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidVersionShouldReturnTrue($input): void
|
||||
public function validVersionShouldReturnTrue($input): void
|
||||
{
|
||||
$rule = new Version();
|
||||
self::assertTrue($rule->__invoke($input));
|
||||
|
@ -36,8 +38,10 @@ class VersionTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidVersion
|
||||
* @expectedException \Respect\Validation\Exceptions\VersionException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidVersionShouldThrowException($input): void
|
||||
public function invalidVersionShouldThrowException($input): void
|
||||
{
|
||||
$rule = new Version();
|
||||
self::assertFalse($rule->__invoke($input));
|
||||
|
|
|
@ -17,16 +17,18 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\VideoUrl
|
||||
* @covers \Respect\Validation\Exceptions\VideoUrlException
|
||||
* @covers \Respect\Validation\Rules\VideoUrl
|
||||
*/
|
||||
class VideoUrlTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "teste" is not a recognized video service.
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowsAnExceptionWhenProviderIsNotValid(): void
|
||||
public function shouldThrowsAnExceptionWhenProviderIsNotValid(): void
|
||||
{
|
||||
new VideoUrl('teste');
|
||||
}
|
||||
|
@ -66,8 +68,10 @@ class VideoUrlTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider validVideoUrlProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateVideoUrl($service, $input): void
|
||||
public function shouldValidateVideoUrl($service, $input): void
|
||||
{
|
||||
$rule = new VideoUrl($service);
|
||||
|
||||
|
@ -76,8 +80,10 @@ class VideoUrlTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider invalidVideoUrlProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldInvalidateNonVideoUrl($service, $input): void
|
||||
public function shouldInvalidateNonVideoUrl($service, $input): void
|
||||
{
|
||||
$rule = new VideoUrl($service);
|
||||
|
||||
|
@ -87,8 +93,10 @@ class VideoUrlTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\VideoUrlException
|
||||
* @expectedExceptionMessage "exemplo.com" must be a valid video URL
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUseAProperExceptionMessageWhenVideoUrlIsNotValid(): void
|
||||
public function useAProperExceptionMessageWhenVideoUrlIsNotValid(): void
|
||||
{
|
||||
$rule = new VideoUrl();
|
||||
$rule->check('exemplo.com');
|
||||
|
@ -97,8 +105,10 @@ class VideoUrlTest extends TestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\VideoUrlException
|
||||
* @expectedExceptionMessage "exemplo.com" must be a valid "YouTube" video URL
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUseAProperExceptionMessageWhenVideoUrlIsNotValidForTheDefinedProvider(): void
|
||||
public function useAProperExceptionMessageWhenVideoUrlIsNotValidForTheDefinedProvider(): void
|
||||
{
|
||||
$rule = new VideoUrl('YouTube');
|
||||
$rule->check('exemplo.com');
|
||||
|
|
|
@ -17,15 +17,17 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Vowel
|
||||
* @covers \Respect\Validation\Exceptions\VowelException
|
||||
* @covers \Respect\Validation\Rules\Vowel
|
||||
*/
|
||||
class VowelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerForValidVowels
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidDataWithVowelsShouldReturnTrue($validVowels, $additional = ''): void
|
||||
public function validDataWithVowelsShouldReturnTrue($validVowels, $additional = ''): void
|
||||
{
|
||||
$validator = new Vowel($additional);
|
||||
self::assertTrue($validator->validate($validVowels));
|
||||
|
@ -34,8 +36,10 @@ class VowelTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidVowels
|
||||
* @expectedException \Respect\Validation\Exceptions\VowelException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidVowelsShouldFailAndThrowVowelException($invalidVowels, $additional = ''): void
|
||||
public function invalidVowelsShouldFailAndThrowVowelException($invalidVowels, $additional = ''): void
|
||||
{
|
||||
$validator = new Vowel($additional);
|
||||
self::assertFalse($validator->validate($invalidVowels));
|
||||
|
@ -45,16 +49,20 @@ class VowelTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidParams
|
||||
* @expectedException \Respect\Validation\Exceptions\ComponentException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
public function invalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
|
||||
{
|
||||
$validator = new Vowel($additional);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Vowel($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -21,14 +21,20 @@ use Respect\Validation\Test\RuleTestCase;
|
|||
*/
|
||||
class WhenTest extends RuleTestCase
|
||||
{
|
||||
public function testShouldConstructAnObjectWithoutElseRule(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldConstructAnObjectWithoutElseRule(): void
|
||||
{
|
||||
$rule = new When($this->createValidatableMock(true), $this->createValidatableMock(true));
|
||||
|
||||
self::assertInstanceOf(AlwaysInvalid::class, $rule->else);
|
||||
}
|
||||
|
||||
public function testShouldConstructAnObjectWithElseRule(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldConstructAnObjectWithElseRule(): void
|
||||
{
|
||||
$rule = new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(true));
|
||||
|
||||
|
@ -38,8 +44,10 @@ class WhenTest extends RuleTestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedExceptionMessage Exception for ThenNotValid:assert() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowExceptionForTheThenRuleWhenTheIfRuleIsValidAndTheThenRuleIsNotOnAssertMethod(): void
|
||||
public function shouldThrowExceptionForTheThenRuleWhenTheIfRuleIsValidAndTheThenRuleIsNotOnAssertMethod(): void
|
||||
{
|
||||
$if = $this->createValidatableMock(true);
|
||||
$then = $this->createValidatableMock(false, 'ThenNotValid');
|
||||
|
@ -52,8 +60,10 @@ class WhenTest extends RuleTestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedExceptionMessage Exception for ThenNotValid:check() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowExceptionForTheThenRuleWhenTheIfRuleIsValidAndTheThenRuleIsNotOnCheckMethod(): void
|
||||
public function shouldThrowExceptionForTheThenRuleWhenTheIfRuleIsValidAndTheThenRuleIsNotOnCheckMethod(): void
|
||||
{
|
||||
$if = $this->createValidatableMock(true);
|
||||
$then = $this->createValidatableMock(false, 'ThenNotValid');
|
||||
|
@ -66,8 +76,10 @@ class WhenTest extends RuleTestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedExceptionMessage Exception for ElseNotValid:assert() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowExceptionForTheElseRuleWhenTheIfRuleIsNotValidAndTheElseRuleIsNotOnAssertMethod(): void
|
||||
public function shouldThrowExceptionForTheElseRuleWhenTheIfRuleIsNotValidAndTheElseRuleIsNotOnAssertMethod(): void
|
||||
{
|
||||
$if = $this->createValidatableMock(false);
|
||||
$then = $this->createValidatableMock(false);
|
||||
|
@ -80,8 +92,10 @@ class WhenTest extends RuleTestCase
|
|||
/**
|
||||
* @expectedException \Respect\Validation\Exceptions\ValidationException
|
||||
* @expectedExceptionMessage Exception for ElseNotValid:check() method
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldThrowExceptionForTheElseRuleWhenTheIfRuleIsNotValidAndTheElseRuleIsNotOnCheckMethod(): void
|
||||
public function shouldThrowExceptionForTheElseRuleWhenTheIfRuleIsNotValidAndTheElseRuleIsNotOnCheckMethod(): void
|
||||
{
|
||||
$if = $this->createValidatableMock(false);
|
||||
$then = $this->createValidatableMock(false);
|
||||
|
|
|
@ -30,15 +30,17 @@ function is_writable($writable)
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Writable
|
||||
* @covers \Respect\Validation\Exceptions\WritableException
|
||||
* @covers \Respect\Validation\Rules\Writable
|
||||
*/
|
||||
class WritableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\Writable::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidWritableFileShouldReturnTrue(): void
|
||||
public function validWritableFileShouldReturnTrue(): void
|
||||
{
|
||||
$GLOBALS['is_writable'] = true;
|
||||
|
||||
|
@ -49,8 +51,10 @@ class WritableTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\Writable::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidWritableFileShouldReturnFalse(): void
|
||||
public function invalidWritableFileShouldReturnFalse(): void
|
||||
{
|
||||
$GLOBALS['is_writable'] = false;
|
||||
|
||||
|
@ -61,14 +65,16 @@ class WritableTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers \Respect\Validation\Rules\Writable::validate
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidateObjects(): void
|
||||
public function shouldValidateObjects(): void
|
||||
{
|
||||
$rule = new Writable();
|
||||
$object = $this->createMock('SplFileInfo', ['isWritable'], ['somefile.txt']);
|
||||
$object->expects($this->once())
|
||||
$object->expects(self::once())
|
||||
->method('isWritable')
|
||||
->will($this->returnValue(true));
|
||||
->will(self::returnValue(true));
|
||||
|
||||
self::assertTrue($rule->validate($object));
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Xdigit
|
||||
* @covers \Respect\Validation\Exceptions\XdigitException
|
||||
* @covers \Respect\Validation\Rules\Xdigit
|
||||
*/
|
||||
class XdigitTest extends TestCase
|
||||
{
|
||||
|
@ -31,8 +31,10 @@ class XdigitTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerForXdigit
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testValidateValidHexasdecimalDigits($input): void
|
||||
public function validateValidHexasdecimalDigits($input): void
|
||||
{
|
||||
$this->xdigitsValidator->assert($input);
|
||||
$this->xdigitsValidator->check($input);
|
||||
|
@ -42,8 +44,10 @@ class XdigitTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerForNotXdigit
|
||||
* @expectedException \Respect\Validation\Exceptions\XdigitException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidHexadecimalDigitsShouldThrowXdigitException($input): void
|
||||
public function invalidHexadecimalDigitsShouldThrowXdigitException($input): void
|
||||
{
|
||||
self::assertFalse($this->xdigitsValidator->validate($input));
|
||||
$this->xdigitsValidator->assert($input);
|
||||
|
@ -51,8 +55,10 @@ class XdigitTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider providerAdditionalChars
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testAdditionalCharsShouldBeRespected($additional, $query): void
|
||||
public function additionalCharsShouldBeRespected($additional, $query): void
|
||||
{
|
||||
$validator = new Xdigit($additional);
|
||||
self::assertTrue($validator->validate($query));
|
||||
|
|
|
@ -17,12 +17,15 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Yes
|
||||
* @covers \Respect\Validation\Exceptions\YesException
|
||||
* @covers \Respect\Validation\Rules\Yes
|
||||
*/
|
||||
class YesTest extends TestCase
|
||||
{
|
||||
public function testShouldUseDefaultPattern(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldUseDefaultPattern(): void
|
||||
{
|
||||
$rule = new Yes();
|
||||
|
||||
|
@ -32,10 +35,13 @@ class YesTest extends TestCase
|
|||
self::assertEquals($expectedPattern, $actualPattern);
|
||||
}
|
||||
|
||||
public function testShouldUseLocalPatternForYesExpressionWhenDefined(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldUseLocalPatternForYesExpressionWhenDefined(): void
|
||||
{
|
||||
if (!defined('YESEXPR')) {
|
||||
$this->markTestSkipped('Constant YESEXPR is not defined');
|
||||
self::markTestSkipped('Constant YESEXPR is not defined');
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -50,8 +56,10 @@ class YesTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider validYesProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
public function shouldValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
{
|
||||
$rule = new Yes();
|
||||
|
||||
|
@ -71,8 +79,10 @@ class YesTest extends TestCase
|
|||
|
||||
/**
|
||||
* @dataProvider invalidYesProvider
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldNotValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
public function shouldNotValidatePatternAccordingToTheDefinedLocale($input): void
|
||||
{
|
||||
$rule = new Yes();
|
||||
|
||||
|
|
|
@ -20,12 +20,15 @@ use Zend\Validator\ValidatorInterface;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Zend
|
||||
* @covers \Respect\Validation\Exceptions\ZendException
|
||||
* @covers \Respect\Validation\Rules\Zend
|
||||
*/
|
||||
class ZendTest extends TestCase
|
||||
{
|
||||
public function testConstructorWithValidatorName(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function constructorWithValidatorName(): void
|
||||
{
|
||||
$v = new Zend('Date');
|
||||
self::assertAttributeInstanceOf(
|
||||
|
@ -36,9 +39,11 @@ class ZendTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructorWithValidatorName
|
||||
* @depends constructorWithValidatorName
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testConstructorWithValidatorClassName(): void
|
||||
public function constructorWithValidatorClassName(): void
|
||||
{
|
||||
$v = new Zend(ZendDate::class);
|
||||
self::assertAttributeInstanceOf(
|
||||
|
@ -48,7 +53,10 @@ class ZendTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testConstructorWithZendValidatorInstance(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function constructorWithZendValidatorInstance(): void
|
||||
{
|
||||
$zendInstance = new ZendDate();
|
||||
$v = new Zend($zendInstance);
|
||||
|
@ -60,9 +68,11 @@ class ZendTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructorWithZendValidatorInstance
|
||||
* @depends constructorWithZendValidatorInstance
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUserlandValidatorExtendingZendInterface(): void
|
||||
public function userlandValidatorExtendingZendInterface(): void
|
||||
{
|
||||
$v = new Zend(new MyValidator());
|
||||
self::assertAttributeInstanceOf(
|
||||
|
@ -72,7 +82,10 @@ class ZendTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testConstructorWithZendValidatorPartialNamespace(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function constructorWithZendValidatorPartialNamespace(): void
|
||||
{
|
||||
$v = new Zend('Sitemap\Lastmod');
|
||||
self::assertAttributeInstanceOf(
|
||||
|
@ -83,10 +96,12 @@ class ZendTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructorWithValidatorName
|
||||
* @depends testConstructorWithZendValidatorPartialNamespace
|
||||
* @depends constructorWithValidatorName
|
||||
* @depends constructorWithZendValidatorPartialNamespace
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testConstructorWithValidatorName_and_params(): void
|
||||
public function constructorWithValidatorName_and_params(): void
|
||||
{
|
||||
$zendValidatorName = 'StringLength';
|
||||
$zendValidatorParams = ['min' => 10, 'max' => 25];
|
||||
|
@ -98,9 +113,11 @@ class ZendTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructorWithValidatorName
|
||||
* @depends constructorWithValidatorName
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testZendDateValidatorWithRespectMethods(): void
|
||||
public function zendDateValidatorWithRespectMethods(): void
|
||||
{
|
||||
$v = new Zend('Date');
|
||||
$date = new DateTime();
|
||||
|
@ -109,11 +126,13 @@ class ZendTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructorWithValidatorName
|
||||
* @depends testZendDateValidatorWithRespectMethods
|
||||
* @depends constructorWithValidatorName
|
||||
* @depends zendDateValidatorWithRespectMethods
|
||||
* @expectedException \Respect\Validation\Exceptions\ZendException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testRespectExceptionForFailedValidation(): void
|
||||
public function respectExceptionForFailedValidation(): void
|
||||
{
|
||||
$v = new Zend('Date');
|
||||
$notValid = 'a';
|
||||
|
@ -127,12 +146,14 @@ class ZendTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructorWithValidatorName
|
||||
* @depends testConstructorWithValidatorName_and_params
|
||||
* @depends testZendDateValidatorWithRespectMethods
|
||||
* @depends constructorWithValidatorName
|
||||
* @depends constructorWithValidatorName_and_params
|
||||
* @depends zendDateValidatorWithRespectMethods
|
||||
* @expectedException \Respect\Validation\Exceptions\ZendException
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testParamsNot(): void
|
||||
public function paramsNot(): void
|
||||
{
|
||||
$v = new Zend('StringLength', ['min' => 10, 'max' => 25]);
|
||||
$v->assert('aw');
|
||||
|
|
|
@ -18,12 +18,18 @@ use Respect\Validation\Exceptions\ComponentException;
|
|||
|
||||
class ValidatorTest extends TestCase
|
||||
{
|
||||
public function testStaticCreateShouldReturnNewValidator(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function staticCreateShouldReturnNewValidator(): void
|
||||
{
|
||||
self::assertInstanceOf(Validator::class, Validator::create());
|
||||
}
|
||||
|
||||
public function testInvalidRuleClassShouldThrowComponentException(): void
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function invalidRuleClassShouldThrowComponentException(): void
|
||||
{
|
||||
$this->expectException(ComponentException::class);
|
||||
Validator::iDoNotExistSoIShouldThrowException();
|
||||
|
@ -31,8 +37,10 @@ class ValidatorTest extends TestCase
|
|||
|
||||
/**
|
||||
* Regression test #174.
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testShouldReturnValidatorInstanceWhenTheNotRuleIsCalledWithArguments(): void
|
||||
public function shouldReturnValidatorInstanceWhenTheNotRuleIsCalledWithArguments(): void
|
||||
{
|
||||
$validator = new Validator();
|
||||
|
||||
|
|
Loading…
Reference in a new issue