Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
convert values to uppercase before testing
to string
Convert value to uppercase before testing
  • Loading branch information
wilsenhc committed Jul 5, 2022
commit a73c7c420924be35f2c99f13fae85dcda93eca6f
3 changes: 3 additions & 0 deletions src/Rules/Rif.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Wilsenhc\RifValidation\Rules;

use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Str;

class Rif implements Rule
{
Expand Down Expand Up @@ -40,6 +41,8 @@ public function passes($attribute, $value): bool
{
$this->attribute = $attribute;

$value = Str::upper($value);

// Verificar si el RIF tiene el formato valido
if (!preg_match('/^[VEPJGC]-?[\d]{8}-?[\d]$/i', $value))
{
Expand Down
19 changes: 19 additions & 0 deletions tests/Rules/RifTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,23 @@ public function it_will_return_false_if_format_is_invalid()

$this->assertFalse($this->rule->passes('rif', $rif));
}

/** @test */
public function it_will_convert_values_to_uppercase_before_testing()
{
// Valid RIF of "Universidad de Carabobo"
$rif = 'g-20000041-4';

$this->assertTrue($this->rule->passes('rif', $rif));

// Valid RIF of "Banesco Banco Universal"
$rif = 'j-07013380-5';

$this->assertTrue($this->rule->passes('rif', $rif));

// Valid RIF of "Nicolas Maduro Moros"
$rif = 'v-05892464-0';

$this->assertTrue($this->rule->passes('rif', $rif));
}
}