This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
feat: created CNPJ mask filter and applied it in Client model. #105
Open
andrebian
wants to merge
4
commits into
Coderockr:master
Choose a base branch
from
andrebian:cnpj
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a0dbc29
feat: created CNPJ mask filter and applied it in Client model.
andrebian ae5b767
fix: forcing string before apply str_pad
andrebian 2dc0cfd
fix: removed int return
andrebian 75cada0
fix: fixed data provider and Ebert error indication for TestCase
andrebian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,37 @@ | ||
<?php | ||
|
||
namespace Orcamentos\Filter; | ||
|
||
/** | ||
* Class CNPJMask | ||
* @package Orcamentos\Filter | ||
*/ | ||
class CNPJMask | ||
{ | ||
/** | ||
* @param $cnpj | ||
* @return string | ||
*/ | ||
public function removeMask($cnpj) | ||
{ | ||
return (string)preg_replace("/\D/", '', $cnpj); | ||
} | ||
|
||
/** | ||
* @param $cnpj | ||
* @return string | ||
*/ | ||
public function applyMask($cnpj) | ||
{ | ||
// asserting that only digits will be present | ||
$cnpj = $this->removeMask($cnpj); | ||
|
||
// applying 14 digits | ||
$cnpj = str_pad($cnpj, 14, '0', STR_PAD_LEFT); | ||
|
||
$pattern = "/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/"; | ||
$replacement = "\$1.\$2.\$3/\$4-\$5"; | ||
|
||
return (string)preg_replace($pattern, $replacement, $cnpj); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,9 +3,8 @@ | |
namespace Orcamentos\Test; | ||
|
||
use Mockery as m; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
class ApplicationTestCase extends PHPUnit_Framework_TestCase | ||
class ApplicationTestCase extends \PHPUnit\Framework\TestCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class extends undeclared class |
||
{ | ||
protected $repositoryMock; | ||
protected $emMock; | ||
|
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,68 @@ | ||
<?php | ||
|
||
namespace Orcamentos\Service; | ||
|
||
use Orcamentos\Filter\CNPJMask; | ||
|
||
/** | ||
* Class CNPJMaskTest | ||
* @package Orcamentos\Service | ||
*/ | ||
class CNPJMaskTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function dataForAddMask() | ||
{ | ||
return array( | ||
array( | ||
'expected' => '18.915.219/0001-86', | ||
'actual' => '18915219000186' | ||
), | ||
array( | ||
'expected' => '09.376.674/0001-60', | ||
'actual' => '09376674000160' | ||
), | ||
array( | ||
'expected' => '09.376.674/0001-60', | ||
'actual' => 9376674000160 | ||
) | ||
); | ||
} | ||
|
||
public function dataForRemoveMask() | ||
{ | ||
return array( | ||
array( | ||
'actual' => '18.915.219/0001-86', | ||
'expected' => 18915219000186 | ||
), | ||
array( | ||
'actual' => '09.376.674/0001-60', | ||
'expected' => 9376674000160 | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider dataForRemoveMask | ||
*/ | ||
public function testRemoveMask($actual, $expected) | ||
{ | ||
$filter = new CNPJMask(); | ||
|
||
$cnpj = $filter->removeMask($actual); | ||
|
||
$this->assertEquals($expected, $cnpj); | ||
} | ||
|
||
/** | ||
* @dataProvider dataForAddMask | ||
*/ | ||
public function testApplyMask($expected, $actual) | ||
{ | ||
$filter = new CNPJMask(); | ||
|
||
$cnpj = $filter->applyMask($actual); | ||
|
||
$this->assertEquals($expected, $cnpj); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument 1
(input)
isint
but\str_pad()
takesstring