-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from melhorenvio/hotfix/cpf-validation-rule
fix: cpf validation rule
- Loading branch information
Showing
5 changed files
with
93 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ docs | |
vendor | ||
coverage | ||
.idea | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="tap" target="build/report.tap"/> | ||
<log type="junit" target="build/report.junit.xml"/> | ||
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace Melhorenvio\ValidationRules\Tests; | ||
|
||
use Melhorenvio\ValidationRules\Rules\Cpf; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CpfTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* @dataProvider provideInvalidCpfs | ||
*/ | ||
public function test_with_invalid_cpfs(string $cpf) | ||
{ | ||
$rule = new Cpf(); | ||
|
||
$this->assertFalse($rule->passes('cpf', $cpf)); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider provideValidCpfs | ||
*/ | ||
public function test_with_valid_cpfs(string $cpf) | ||
{ | ||
$rule = new Cpf(); | ||
|
||
$this->assertTrue($rule->passes('cpf', $cpf)); | ||
} | ||
|
||
public function test_with_empty_cpf() | ||
{ | ||
$rule = new Cpf(); | ||
|
||
$this->assertFalse($rule->passes('cpf', '')); | ||
$this->assertFalse($rule->passes('cpf', null)); | ||
} | ||
|
||
public function test_with_zeroed_cpf() | ||
{ | ||
$rule = new Cpf(); | ||
|
||
$this->assertFalse($rule->passes('cpf', '0')); | ||
$this->assertFalse($rule->passes('cpf', 0)); | ||
} | ||
|
||
public static function provideInvalidCpfs(): array | ||
{ | ||
return [ | ||
['00000000000'], | ||
['11111111111'], | ||
['22222222222'], | ||
['33333333333'], | ||
['44444444444'], | ||
['55555555555'], | ||
['66666666666'], | ||
['77777777777'], | ||
['88888888888'], | ||
['99999999999'], | ||
['000.000.000-00'], | ||
['111.111.111-11'], | ||
['222.222.222-22'], | ||
['333.333.333-33'], | ||
['444.444.444-44'], | ||
['555.555.555-55'], | ||
['666.666.666-66'], | ||
['777.777.777-77'], | ||
['888.888.888-88'], | ||
['999.999.999-99'] | ||
]; | ||
} | ||
|
||
public static function provideValidCpfs(): array | ||
{ | ||
return [ | ||
['322.282.090-23'], | ||
['024.278.590-52'], | ||
['014.533.750-23'], | ||
['335.203.900-35'], | ||
['108.810.610-26'], | ||
['97005733037'], | ||
['86939244000'], | ||
['62747195040'], | ||
['75726024010'], | ||
['45061931050'], | ||
]; | ||
} | ||
} |