2011-09-04 00:20:02 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Respect/Validation.
|
|
|
|
*
|
|
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-09-04 00:20:02 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2017-11-04 11:21:40 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
|
|
|
* @group rule
|
2017-02-04 14:01:14 +01:00
|
|
|
* @covers \Respect\Validation\Rules\Cpf
|
|
|
|
* @covers \Respect\Validation\Exceptions\CpfException
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2017-11-04 11:21:40 +01:00
|
|
|
class CpfTest extends TestCase
|
2013-01-14 23:44:49 +01:00
|
|
|
{
|
2011-10-06 00:23:03 +02:00
|
|
|
protected $cpfValidator;
|
2011-09-06 04:34:00 +02:00
|
|
|
|
2013-01-14 23:44:49 +01:00
|
|
|
protected function setUp()
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2015-06-08 16:47:14 +02:00
|
|
|
$this->cpfValidator = new Cpf();
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
|
2011-09-06 04:34:00 +02:00
|
|
|
/**
|
2011-09-20 03:13:10 +02:00
|
|
|
* @dataProvider providerValidFormattedCpf
|
2011-09-06 04:34:00 +02:00
|
|
|
*/
|
2013-01-14 23:44:49 +01:00
|
|
|
public function testFormattedCpfsShouldValidate($input)
|
2011-09-04 00:20:02 +02:00
|
|
|
{
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertTrue($this->cpfValidator->assert($input));
|
2011-09-04 00:20:02 +02:00
|
|
|
}
|
2011-09-06 04:34:00 +02:00
|
|
|
|
|
|
|
/**
|
2011-09-20 03:13:10 +02:00
|
|
|
* @dataProvider providerValidUnformattedCpf
|
2011-09-06 04:34:00 +02:00
|
|
|
*/
|
2013-01-14 23:44:49 +01:00
|
|
|
public function testUnformattedCpfsShouldValidates($input)
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertTrue($this->cpfValidator->assert($input));
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-20 03:13:10 +02:00
|
|
|
* @dataProvider providerInvalidFormattedCpf
|
2017-02-04 14:01:14 +01:00
|
|
|
* @expectedException \Respect\Validation\Exceptions\CpfException
|
2011-09-06 04:34:00 +02:00
|
|
|
*/
|
2013-01-14 23:44:49 +01:00
|
|
|
public function testInvalidCpfShouldFailWhenFormatted($input)
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertFalse($this->cpfValidator->assert($input));
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-20 03:13:10 +02:00
|
|
|
* @dataProvider providerInvalidUnformattedCpf
|
2017-02-04 14:01:14 +01:00
|
|
|
* @expectedException \Respect\Validation\Exceptions\CpfException
|
2011-09-06 04:34:00 +02:00
|
|
|
*/
|
2013-01-14 23:44:49 +01:00
|
|
|
public function testInvalidCpfShouldFailWhenNotFormatted($input)
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertFalse($this->cpfValidator->assert($input));
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
|
|
|
|
2011-09-04 00:20:02 +02:00
|
|
|
/**
|
2011-09-20 03:13:10 +02:00
|
|
|
* @dataProvider providerInvalidFormattedAndUnformattedCpfLength
|
2017-02-04 14:01:14 +01:00
|
|
|
* @expectedException \Respect\Validation\Exceptions\CpfException
|
2011-09-06 04:34:00 +02:00
|
|
|
*/
|
2013-01-14 23:44:49 +01:00
|
|
|
public function testCpfsWithIncorrectLengthShouldFail($input)
|
2011-09-04 00:20:02 +02:00
|
|
|
{
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertFalse($this->cpfValidator->assert($input));
|
2011-09-04 00:20:02 +02:00
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
|
|
|
|
public function providerValidFormattedCpf()
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
['342.444.198-88'],
|
|
|
|
['342.444.198.88'],
|
|
|
|
['350.45261819'],
|
|
|
|
['693-319-118-40'],
|
|
|
|
['3.6.8.8.9.2.5.5.4.8.8'],
|
|
|
|
];
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
|
|
|
|
2013-01-14 23:44:49 +01:00
|
|
|
public function providerValidUnformattedCpf()
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
['11598647644'],
|
|
|
|
['86734718697'],
|
|
|
|
['86223423284'],
|
|
|
|
['24845408333'],
|
|
|
|
['95574461102'],
|
|
|
|
];
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
|
|
|
|
2013-01-14 23:44:49 +01:00
|
|
|
public function providerInvalidFormattedCpf()
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
[''],
|
|
|
|
['000.000.000-00'],
|
|
|
|
['111.222.444-05'],
|
|
|
|
['999999999.99'],
|
|
|
|
['8.8.8.8.8.8.8.8.8.8.8'],
|
|
|
|
['693-319-110-40'],
|
|
|
|
['698.111-111.00'],
|
|
|
|
];
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
|
|
|
|
2013-01-14 23:44:49 +01:00
|
|
|
public function providerInvalidUnformattedCpf()
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
['11111111111'],
|
|
|
|
['22222222222'],
|
|
|
|
['12345678900'],
|
|
|
|
['99299929384'],
|
|
|
|
['84434895894'],
|
|
|
|
['44242340000'],
|
|
|
|
];
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
|
2011-09-20 03:13:10 +02:00
|
|
|
public function providerInvalidFormattedAndUnformattedCpfLength()
|
2011-09-06 04:34:00 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
['1'],
|
|
|
|
['22'],
|
|
|
|
['123'],
|
|
|
|
['992999999999929384'],
|
|
|
|
];
|
2011-09-06 04:34:00 +02:00
|
|
|
}
|
2011-09-23 00:20:24 +02:00
|
|
|
}
|