Skip to content

Commit

Permalink
Adhere to the interface and throw a TransformationFailedException whe…
Browse files Browse the repository at this point in the history
…n not a PhoneNumber object
  • Loading branch information
thewilkybarkid committed Aug 1, 2014
1 parent e0b45b4 commit 49db55e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Form/DataTransformer/PhoneNumberToStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function transform($phoneNumber)
if (null === $phoneNumber) {
return '';
} elseif (false === $phoneNumber instanceof PhoneNumber) {
return $phoneNumber;
throw new TransformationFailedException('Expected a \libphonenumber\PhoneNumber.');
}

$util = PhoneNumberUtil::getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public function testTransform($defaultRegion, $format, $actual, $expected)
$phoneNumber = $actual;
}

$transformed = $transformer->transform($phoneNumber);
try {
$transformed = $transformer->transform($phoneNumber);
} catch (TransformationFailedException $e) {
$transformed = self::TRANSFORMATION_FAILED;
}

$this->assertSame($expected, $transformed);
}
Expand All @@ -64,7 +68,7 @@ public function transformProvider()
{
return array(
array(PhoneNumberUtil::UNKNOWN_REGION, PhoneNumberFormat::INTERNATIONAL, null, ''),
array(PhoneNumberUtil::UNKNOWN_REGION, PhoneNumberFormat::INTERNATIONAL, 'foo', 'foo'),
array(PhoneNumberUtil::UNKNOWN_REGION, PhoneNumberFormat::NATIONAL, 'foo', self::TRANSFORMATION_FAILED),
array(
PhoneNumberUtil::UNKNOWN_REGION,
PhoneNumberFormat::INTERNATIONAL,
Expand Down

0 comments on commit 49db55e

Please sign in to comment.