Skip to content

Commit a73c7c4

Browse files
committed
convert values to uppercase before testing
to string Convert value to uppercase before testing
1 parent 5c7c7fd commit a73c7c4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Rules/Rif.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Wilsenhc\RifValidation\Rules;
44

55
use Illuminate\Contracts\Validation\Rule;
6+
use Illuminate\Support\Str;
67

78
class Rif implements Rule
89
{
@@ -40,6 +41,8 @@ public function passes($attribute, $value): bool
4041
{
4142
$this->attribute = $attribute;
4243

44+
$value = Str::upper($value);
45+
4346
// Verificar si el RIF tiene el formato valido
4447
if (!preg_match('/^[VEPJGC]-?[\d]{8}-?[\d]$/i', $value))
4548
{

tests/Rules/RifTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,23 @@ public function it_will_return_false_if_format_is_invalid()
7373

7474
$this->assertFalse($this->rule->passes('rif', $rif));
7575
}
76+
77+
/** @test */
78+
public function it_will_convert_values_to_uppercase_before_testing()
79+
{
80+
// Valid RIF of "Universidad de Carabobo"
81+
$rif = 'g-20000041-4';
82+
83+
$this->assertTrue($this->rule->passes('rif', $rif));
84+
85+
// Valid RIF of "Banesco Banco Universal"
86+
$rif = 'j-07013380-5';
87+
88+
$this->assertTrue($this->rule->passes('rif', $rif));
89+
90+
// Valid RIF of "Nicolas Maduro Moros"
91+
$rif = 'v-05892464-0';
92+
93+
$this->assertTrue($this->rule->passes('rif', $rif));
94+
}
7695
}

0 commit comments

Comments
 (0)