Skip to content

Commit

Permalink
Fix skipped test for Renavam (#33)
Browse files Browse the repository at this point in the history
Fix skipped test for Renavam

Tests to validate empty number was skipped because it was empty. It is
prepared to throw exception when given number is empty or null.
  • Loading branch information
tonicospinelli authored Jul 18, 2017
1 parent 64cd161 commit 6070701
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/Renavam.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,26 @@ final class Renavam extends AbstractDocument
public function __construct($renavam)
{
$renavam = preg_replace('/\D/', '', $renavam);
$renavam = str_pad($renavam, self::LENGTH, 0, STR_PAD_LEFT);
$renavam = $this->padNumber($renavam);
parent::__construct($renavam, self::LENGTH, self::NUMBER_OF_DIGITS, self::LABEL);
}

/**
* Pad left a number to length(11) with 0(ZERO)
*
* @param string $number
*
* @return string
*/
private function padNumber($number)
{
if (empty($number)) {
return '';
}

return str_pad($number, self::LENGTH, 0, STR_PAD_LEFT);
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 4 additions & 1 deletion tests/RenavamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public function provideValidNumbersAndExpectedFormat()

public function provideEmptyData()
{
return [];
return [
[Renavam::LABEL, ''],
[Renavam::LABEL, null],
];
}

public function provideInvalidNumber()
Expand Down

0 comments on commit 6070701

Please sign in to comment.