mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 23:02:16 +02:00
Apply contribution guidelines to "Bsn" rule
This commit is contained in:
parent
68b3f207f8
commit
99466513b2
|
@ -14,12 +14,14 @@ declare(strict_types=1);
|
|||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
/**
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author Ronald Drenth <ronalddrenth@gmail.com>
|
||||
* @author William Espindola <oi@williamespindola.com.br>
|
||||
*/
|
||||
class BsnException extends ValidationException
|
||||
final class BsnException extends ValidationException
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
|
|
|
@ -13,14 +13,19 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use function ctype_digit;
|
||||
use function mb_strlen;
|
||||
|
||||
/**
|
||||
* Validates a Dutch citizen service number (BSN).
|
||||
*
|
||||
* @author Ronald Drenth <ronalddrenth@gmail.com>
|
||||
*
|
||||
* @see https://nl.wikipedia.org/wiki/Burgerservicenummer
|
||||
*
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author Ronald Drenth <ronalddrenth@gmail.com>
|
||||
* @author William Espindola <oi@williamespindola.com.br>
|
||||
*/
|
||||
class Bsn extends AbstractRule
|
||||
final class Bsn extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
38
tests/integration/rules/bsn.phpt
Normal file
38
tests/integration/rules/bsn.phpt
Normal file
|
@ -0,0 +1,38 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\BsnException;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::bsn()->check('acb');
|
||||
} catch (BsnException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::bsn())->check('612890053');
|
||||
} catch (BsnException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::bsn()->assert('abc');
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::bsn())->assert('612890053');
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
"acb" must be a BSN
|
||||
"612890053" must not be a BSN
|
||||
- "abc" must be a BSN
|
||||
- "612890053" must not be a BSN
|
|
@ -1,10 +0,0 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
v::bsn()->check('612890053');
|
||||
?>
|
||||
--EXPECTF--
|
|
@ -1,16 +0,0 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\BsnException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::bsn()->check('acb');
|
||||
} catch (BsnException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
"acb" must be a BSN
|
|
@ -1,16 +0,0 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AllOfException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::bsn()->assert('abc');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage();
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
- "abc" must be a BSN
|
|
@ -13,86 +13,62 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Respect\Validation\Test\RuleTestCase;
|
||||
|
||||
/**
|
||||
* @group rule
|
||||
* @group rule
|
||||
*
|
||||
* @covers \Respect\Validation\Rules\Bsn
|
||||
* @covers \Respect\Validation\Exceptions\BsnException
|
||||
*
|
||||
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
* @author Ronald Drenth <ronalddrenth@gmail.com>
|
||||
* @author William Espindola <oi@williamespindola.com.br>
|
||||
*/
|
||||
class BsnTest extends TestCase
|
||||
final class BsnTest extends RuleTestCase
|
||||
{
|
||||
/**
|
||||
* @var Bsn
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
private $rule;
|
||||
public function providerForValidInput(): array
|
||||
{
|
||||
$rule = new Bsn();
|
||||
|
||||
return [
|
||||
[$rule, '612890053'],
|
||||
[$rule, '087880532'],
|
||||
[$rule, '386625918'],
|
||||
[$rule, '601608021'],
|
||||
[$rule, '254650703'],
|
||||
[$rule, '478063441'],
|
||||
[$rule, '478063441'],
|
||||
[$rule, '187368429'],
|
||||
[$rule, '541777348'],
|
||||
[$rule, '254283883'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(): void
|
||||
public function providerForInvalidInput(): array
|
||||
{
|
||||
$this->rule = new Bsn();
|
||||
}
|
||||
$rule = new Bsn();
|
||||
|
||||
/**
|
||||
* @dataProvider providerForBsn
|
||||
*
|
||||
* @param string $input
|
||||
*/
|
||||
public function testShouldValidateBsn($input): void
|
||||
{
|
||||
self::assertTrue($this->rule->validate($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForInvalidBsn
|
||||
*
|
||||
* @param string $input
|
||||
*/
|
||||
public function testShouldNotValidateBsn($input): void
|
||||
{
|
||||
self::assertFalse($this->rule->validate($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerForBsn()
|
||||
{
|
||||
return [
|
||||
['612890053'],
|
||||
['087880532'],
|
||||
['386625918'],
|
||||
['601608021'],
|
||||
['254650703'],
|
||||
['478063441'],
|
||||
['478063441'],
|
||||
['187368429'],
|
||||
['541777348'],
|
||||
['254283883'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerForInvalidBsn()
|
||||
{
|
||||
return [
|
||||
['1234567890'],
|
||||
['0987654321'],
|
||||
['13579024'],
|
||||
['612890054'],
|
||||
['854650703'],
|
||||
['283958721'],
|
||||
['231859081'],
|
||||
['189023323'],
|
||||
['238150912'],
|
||||
['382409678'],
|
||||
['38240.678'],
|
||||
['38240a678'],
|
||||
['abcdefghi'],
|
||||
[$rule, '1234567890'],
|
||||
[$rule, '0987654321'],
|
||||
[$rule, '13579024'],
|
||||
[$rule, '612890054'],
|
||||
[$rule, '854650703'],
|
||||
[$rule, '283958721'],
|
||||
[$rule, '231859081'],
|
||||
[$rule, '189023323'],
|
||||
[$rule, '238150912'],
|
||||
[$rule, '382409678'],
|
||||
[$rule, '38240.678'],
|
||||
[$rule, '38240a678'],
|
||||
[$rule, 'abcdefghi'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue