Skip to content

Commit

Permalink
Handle stringified values of PhoneNumberType (fixes #60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Propaganistas committed Feb 13, 2018
1 parent a291e83 commit e660b58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Traits/ParsesTypes.php
Expand Up @@ -38,8 +38,8 @@ protected static function parseTypes($types)
return Collection::make(is_array($types) ? $types : func_get_args())
->map(function ($type) {
// If the type equals a constant's value, just return it.
if (in_array($type, static::$types, true)) {
return $type;
if (is_numeric($type) && in_array($type, static::$types)) {
return (int) $type;
}

// Otherwise we'll assume the type is the constant's name.
Expand Down
2 changes: 2 additions & 0 deletions tests/PhoneNumberTest.php
Expand Up @@ -286,8 +286,10 @@ public function it_can_check_the_type()
public function it_can_verify_types()
{
$this->assertTrue(PhoneNumber::isValidType(PhoneNumberType::MOBILE));
$this->assertTrue(PhoneNumber::isValidType((string) PhoneNumberType::MOBILE));
$this->assertTrue(PhoneNumber::isValidType('mobile'));
$this->assertFalse(PhoneNumber::isValidType(99999));
$this->assertFalse(PhoneNumber::isValidType('99999'));
$this->assertFalse(PhoneNumber::isValidType('foo'));
}

Expand Down
9 changes: 9 additions & 0 deletions tests/PhoneValidatorTest.php
Expand Up @@ -505,4 +505,13 @@ public function it_has_a_rule_class()
$expected = 'phone:BE,toll_free,6,my_field,AUTO,LENIENT';
$this->assertEquals($expected, (string) $actual);
}

/** @test */
public function it_validates_with_stringified_type_constant()
{
$this->assertTrue($this->validator->make(
['field' => '0470123456'],
['field' => 'phone:BE,' . PhoneNumberType::MOBILE])->passes()
);
}
}

0 comments on commit e660b58

Please sign in to comment.