[Form] Fixed transform()/reverseTransform() to always throw TransformationFailedExceptions

This commit is contained in:
Bernhard Schussek 2013-05-03 10:51:22 +02:00
parent 3f5cffec8a
commit bcb540021a
35 changed files with 164 additions and 169 deletions

View File

@ -11,7 +11,7 @@
namespace Symfony\Bridge\Doctrine\Form\DataTransformer;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\DataTransformerInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
@ -27,6 +27,8 @@ class CollectionToArrayTransformer implements DataTransformerInterface
* @param Collection $collection A collection of entities
*
* @return mixed An array of entities
*
* @throws TransformationFailedException
*/
public function transform($collection)
{
@ -35,7 +37,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
}
if (!$collection instanceof Collection) {
throw new UnexpectedTypeException($collection, 'Doctrine\Common\Collections\Collection');
throw new TransformationFailedException('Expected a Doctrine\Common\Collections\Collection object.');
}
return $collection->toArray();

View File

@ -13,7 +13,7 @@ namespace Symfony\Bridge\Propel1\Form\DataTransformer;
use \PropelObjectCollection;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* CollectionToArrayTransformer class.
@ -30,7 +30,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
}
if (!$collection instanceof PropelObjectCollection) {
throw new UnexpectedTypeException($collection, '\PropelObjectCollection');
throw new TransformationFailedException('Expected a \PropelObjectCollection.');
}
return $collection->getData();
@ -45,7 +45,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
}
if (!is_array($array)) {
throw new UnexpectedTypeException($array, 'array');
throw new TransformationFailedException('Expected an array.');
}
$collection->setData($array);

View File

@ -47,7 +47,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformThrowsExceptionIfNotPropelObjectCollection()
{
@ -84,7 +84,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformThrowsExceptionIfNotArray()
{

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form;
/**
* Transforms a value between different representations.
*
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface DataTransformerInterface
{
@ -43,8 +43,7 @@ interface DataTransformerInterface
*
* @return mixed The value in the transformed representation
*
* @throws UnexpectedTypeException when the argument is not a string
* @throws TransformationFailedException when the transformation fails
* @throws \Symfony\Component\Form\Exception\TransformationFailedException When the transformation fails.
*/
public function transform($value);
@ -70,8 +69,7 @@ interface DataTransformerInterface
*
* @return mixed The value in the original representation
*
* @throws UnexpectedTypeException when the argument is not of the expected type
* @throws TransformationFailedException when the transformation fails
* @throws \Symfony\Component\Form\Exception\TransformationFailedException When the transformation fails.
*/
public function reverseTransform($value);
}

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -34,7 +33,7 @@ class ArrayToPartsTransformer implements DataTransformerInterface
}
if (!is_array($array) ) {
throw new UnexpectedTypeException($array, 'array');
throw new TransformationFailedException('Expected an array.');
}
$result = array();
@ -53,7 +52,7 @@ class ArrayToPartsTransformer implements DataTransformerInterface
public function reverseTransform($array)
{
if (!is_array($array) ) {
throw new UnexpectedTypeException($array, 'array');
throw new TransformationFailedException('Expected an array.');
}
$result = array();

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* Transforms between a Boolean and a string.
@ -45,7 +45,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
*
* @return string String value.
*
* @throws UnexpectedTypeException if the given value is not a Boolean
* @throws TransformationFailedException If the given value is not a Boolean.
*/
public function transform($value)
{
@ -54,7 +54,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
}
if (!is_bool($value)) {
throw new UnexpectedTypeException($value, 'Boolean');
throw new TransformationFailedException('Expected a Boolean.');
}
return true === $value ? $this->trueValue : null;
@ -67,7 +67,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
*
* @return Boolean Boolean value.
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException If the given value is not a string.
*/
public function reverseTransform($value)
{
@ -76,7 +76,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
}
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
throw new TransformationFailedException('Expected a string.');
}
return true;

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -42,12 +41,12 @@ class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
* as select tag, the value is not modified.
*
* @param mixed $choice An array if "multiple" is set to true, a scalar
* value otherwise.
* value otherwise.
*
* @return mixed An array
*
* @throws UnexpectedTypeException if the given value is not scalar
* @throws TransformationFailedException if the choices can not be retrieved
* @throws TransformationFailedException If the given value is not scalar or
* if the choices can not be retrieved.
*/
public function transform($choice)
{
@ -77,14 +76,15 @@ class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
*
* @return mixed A scalar value
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the recuperation of the choices fails or
* if some choice can't be found
* @throws TransformationFailedException If the given value is not an array,
* if the recuperation of the choices
* fails or if some choice can't be
* found.
*/
public function reverseTransform($values)
{
if (!is_array($values)) {
throw new UnexpectedTypeException($values, 'array');
throw new TransformationFailedException('Expected an array.');
}
try {

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
@ -41,7 +40,7 @@ class ChoiceToValueTransformer implements DataTransformerInterface
public function reverseTransform($value)
{
if (null !== $value && !is_scalar($value)) {
throw new UnexpectedTypeException($value, 'scalar');
throw new TransformationFailedException('Expected a scalar.');
}
// These are now valid ChoiceList values, so we can return null

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -40,8 +39,8 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
*
* @return mixed An array
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the choices can not be retrieved
* @throws TransformationFailedException If the given value is not an array
* or if the choices can not be retrieved.
*/
public function transform($array)
{
@ -50,7 +49,7 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
}
if (!is_array($array)) {
throw new UnexpectedTypeException($array, 'array');
throw new TransformationFailedException('Expected an array.');
}
try {
@ -79,14 +78,15 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
*
* @return mixed An array
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the recuperation of the choices fails or
* if some choice can't be found
* @throws TransformationFailedException If the given value is not an array,
* if the recuperation of the choices
* fails or if some choice can't be
* found.
*/
public function reverseTransform($values)
{
if (!is_array($values)) {
throw new UnexpectedTypeException($values, 'array');
throw new TransformationFailedException('Expected an array.');
}
try {
@ -109,7 +109,9 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
}
if (count($unknown) > 0) {
throw new TransformationFailedException('The choices "' . implode('", "', $unknown) . '" were not found');
throw new TransformationFailedException(
sprintf('The choices "%s" were not found', implode('", "', $unknown))
);
}
return $result;

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
/**
@ -39,7 +38,7 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
*
* @return array
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException If the given value is not an array.
*/
public function transform($array)
{
@ -48,7 +47,7 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
}
if (!is_array($array)) {
throw new UnexpectedTypeException($array, 'array');
throw new TransformationFailedException('Expected an array.');
}
return $this->choiceList->getValuesForChoices($array);
@ -59,8 +58,9 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
*
* @return array
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if could not find all matching choices for the given values
* @throws TransformationFailedException If the given value is not an array
* or if no matching choice could be
* found for some given value.
*/
public function reverseTransform($array)
{
@ -69,7 +69,7 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
}
if (!is_array($array)) {
throw new UnexpectedTypeException($array, 'array');
throw new TransformationFailedException('Expected an array.');
}
$choices = $this->choiceList->getChoicesForValues($array);

View File

@ -22,7 +22,7 @@ class DataTransformerChain implements DataTransformerInterface
{
/**
* The value transformers
* @var array
* @var DataTransformerInterface[]
*/
protected $transformers;
@ -48,8 +48,7 @@ class DataTransformerChain implements DataTransformerInterface
*
* @return mixed The transformed value
*
* @throws Symfony\Component\Form\Exception\TransformationFailedException
* @throws Symfony\Component\Form\Exception\UnexpectedTypeException
* @throws \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function transform($value)
{
@ -73,8 +72,7 @@ class DataTransformerChain implements DataTransformerInterface
*
* @return mixed The reverse-transformed value
*
* @throws Symfony\Component\Form\Exception\TransformationFailedException
* @throws Symfony\Component\Form\Exception\UnexpectedTypeException
* @throws \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function reverseTransform($value)
{

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* Transforms between a normalized time and a localized time string/array.
@ -34,7 +33,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
* @param array $fields The date fields
* @param Boolean $pad Whether to use padding
*
* @throws UnexpectedTypeException if a timezone is not a string
* @throws \Symfony\Component\Form\Exception\UnexpectedTypeException if a timezone is not a string
*/
public function __construct($inputTimezone = null, $outputTimezone = null, array $fields = null, $pad = false)
{
@ -51,12 +50,13 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
/**
* Transforms a normalized date into a localized date.
*
* @param DateTime $dateTime Normalized date.
* @param \DateTime $dateTime Normalized date.
*
* @return array Localized date.
*
* @throws UnexpectedTypeException if the given value is not an instance of \DateTime
* @throws TransformationFailedException if the output timezone is not supported
* @throws TransformationFailedException If the given value is not an
* instance of \DateTime or if the
* output timezone is not supported.
*/
public function transform($dateTime)
{
@ -72,7 +72,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
}
if (!$dateTime instanceof \DateTime) {
throw new UnexpectedTypeException($dateTime, '\DateTime');
throw new TransformationFailedException('Expected a \DateTime.');
}
$dateTime = clone $dateTime;
@ -108,11 +108,12 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
*
* @param array $value Localized date
*
* @return DateTime Normalized date
* @return \DateTime Normalized date
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the value could not be transformed
* @throws TransformationFailedException if the input timezone is not supported
* @throws TransformationFailedException If the given value is not an array,
* if the value could not be transformed
* or if the input timezone is not
* supported.
*/
public function reverseTransform($value)
{
@ -121,7 +122,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
}
if (!is_array($value)) {
throw new UnexpectedTypeException($value, 'array');
throw new TransformationFailedException('Expected an array.');
}
if ('' === implode('', $value)) {

View File

@ -39,8 +39,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
* @param integer $calendar One of the \IntlDateFormatter calendar constants
* @param string $pattern A pattern to pass to \IntlDateFormatter
*
* @throws UnexpectedTypeException If a format is not supported
* @throws UnexpectedTypeException if a timezone is not a string
* @throws UnexpectedTypeException If a format is not supported or if a timezone is not a string
*/
public function __construct($inputTimezone = null, $outputTimezone = null, $dateFormat = null, $timeFormat = null, $calendar = \IntlDateFormatter::GREGORIAN, $pattern = null)
{
@ -73,10 +72,11 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
*
* @param \DateTime $dateTime Normalized date.
*
* @return string|array Localized date string/array.
* @return string|array Localized date string/array.
*
* @throws UnexpectedTypeException if the given value is not an instance of \DateTime
* @throws TransformationFailedException if the date could not be transformed
* @throws TransformationFailedException If the given value is not an instance
* of \DateTime or if the date could not
* be transformed.
*/
public function transform($dateTime)
{
@ -85,7 +85,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
}
if (!$dateTime instanceof \DateTime) {
throw new UnexpectedTypeException($dateTime, '\DateTime');
throw new TransformationFailedException('Expected a \DateTime.');
}
// convert time to UTC before passing it to the formatter
@ -110,14 +110,14 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
*
* @return \DateTime Normalized date
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the date could not be parsed
* @throws TransformationFailedException if the input timezone is not supported
* @throws TransformationFailedException if the given value is not a string,
* if the date could not be parsed or
* if the input timezone is not supported
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
throw new TransformationFailedException('Expected a string.');
}
if ('' === $value) {

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
@ -29,7 +28,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
}
if (!$dateTime instanceof \DateTime) {
throw new UnexpectedTypeException($dateTime, '\DateTime');
throw new TransformationFailedException('Expected a \DateTime.');
}
if ($this->inputTimezone !== $this->outputTimezone) {
@ -46,7 +45,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
public function reverseTransform($rfc3339)
{
if (!is_string($rfc3339)) {
throw new UnexpectedTypeException($rfc3339, 'string');
throw new TransformationFailedException('Expected a string.');
}
if ('' === $rfc3339) {

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* Transforms between a date string and a DateTime object
@ -58,7 +57,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
* @param string $format The date format
* @param Boolean $parseUsingPipe Whether to parse by appending a pipe "|" to the parse format
*
* @throws UnexpectedTypeException if a timezone is not a string
* @throws \Symfony\Component\Form\Exception\UnexpectedTypeException if a timezone is not a string
*/
public function __construct($inputTimezone = null, $outputTimezone = null, $format = 'Y-m-d H:i:s', $parseUsingPipe = null)
{
@ -93,8 +92,9 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
*
* @return string A value as produced by PHP's date() function
*
* @throws UnexpectedTypeException if the given value is not a \DateTime instance
* @throws TransformationFailedException if the output timezone is not supported
* @throws TransformationFailedException If the given value is not a \DateTime
* instance or if the output timezone
* is not supported.
*/
public function transform($value)
{
@ -103,7 +103,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
}
if (!$value instanceof \DateTime) {
throw new UnexpectedTypeException($value, '\DateTime');
throw new TransformationFailedException('Expected a \DateTime.');
}
$value = clone $value;
@ -123,9 +123,9 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
*
* @return \DateTime An instance of \DateTime
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the date could not be parsed
* @throws TransformationFailedException if the input timezone is not supported
* @throws TransformationFailedException If the given value is not a string,
* if the date could not be parsed or
* if the input timezone is not supported.
*/
public function reverseTransform($value)
{
@ -134,7 +134,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
}
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
throw new TransformationFailedException('Expected a string.');
}
try {

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* Transforms between a timestamp and a DateTime object
@ -25,12 +24,13 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
/**
* Transforms a DateTime object into a timestamp in the configured timezone.
*
* @param DateTime $value A DateTime object
* @param \DateTime $value A \DateTime object
*
* @return integer A timestamp
*
* @throws UnexpectedTypeException if the given value is not an instance of \DateTime
* @throws TransformationFailedException if the output timezone is not supported
* @throws TransformationFailedException If the given value is not an instance
* of \DateTime or if the output
* timezone is not supported.
*/
public function transform($value)
{
@ -39,7 +39,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
}
if (!$value instanceof \DateTime) {
throw new UnexpectedTypeException($value, '\DateTime');
throw new TransformationFailedException('Expected a \DateTime.');
}
$value = clone $value;
@ -57,10 +57,10 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
*
* @param string $value A timestamp
*
* @return \DateTime An instance of \DateTime
* @return \DateTime A \DateTime object
*
* @throws UnexpectedTypeException if the given value is not a timestamp
* @throws TransformationFailedException if the given timestamp is invalid
* @throws TransformationFailedException If the given value is not a timestamp
* or if the given timestamp is invalid.
*/
public function reverseTransform($value)
{
@ -69,7 +69,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
}
if (!is_numeric($value)) {
throw new UnexpectedTypeException($value, 'numeric');
throw new TransformationFailedException('Expected a numeric.');
}
try {

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* Transforms between an integer and a localized number with grouping
@ -28,7 +27,7 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
throw new TransformationFailedException('Expected a string.');
}
if ('' === $value) {

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* Transforms between a normalized format and a localized money string.
@ -50,14 +50,14 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
*
* @return string Localized money string.
*
* @throws UnexpectedTypeException if the given value is not numeric
* @throws TransformationFailedException if the value can not be transformed
* @throws TransformationFailedException If the given value is not numeric or
* if the value can not be transformed.
*/
public function transform($value)
{
if (null !== $value) {
if (!is_numeric($value)) {
throw new UnexpectedTypeException($value, 'numeric');
throw new TransformationFailedException('Expected a numeric.');
}
$value /= $this->divisor;
@ -73,8 +73,8 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
*
* @return number Normalized number
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the value can not be transformed
* @throws TransformationFailedException If the given value is not a string
* or if the value can not be transformed.
*/
public function reverseTransform($value)
{

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* Transforms between a number type and a localized number with grouping
@ -60,8 +59,8 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
*
* @return string Localized value.
*
* @throws UnexpectedTypeException if the given value is not numeric
* @throws TransformationFailedException if the value can not be transformed
* @throws TransformationFailedException If the given value is not numeric
* or if the value can not be transformed.
*/
public function transform($value)
{
@ -70,7 +69,7 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
}
if (!is_numeric($value)) {
throw new UnexpectedTypeException($value, 'numeric');
throw new TransformationFailedException('Expected a numeric.');
}
$formatter = $this->getNumberFormatter();
@ -90,13 +89,13 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
*
* @return integer|float The numeric value
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the value can not be transformed
* @throws TransformationFailedException If the given value is not a string
* or if the value can not be transformed.
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
throw new TransformationFailedException('Expected a string.');
}
if ('' === $value) {

View File

@ -70,8 +70,8 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
*
* @return number Percentage value
*
* @throws UnexpectedTypeException if the given value is not numeric
* @throws TransformationFailedException if the value could not be transformed
* @throws TransformationFailedException If the given value is not numeric or
* if the value could not be transformed.
*/
public function transform($value)
{
@ -80,7 +80,7 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
}
if (!is_numeric($value)) {
throw new UnexpectedTypeException($value, 'numeric');
throw new TransformationFailedException('Expected a numeric.');
}
if (self::FRACTIONAL == $this->type) {
@ -105,13 +105,13 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
*
* @return number Normalized value.
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the value could not be transformed
* @throws TransformationFailedException If the given value is not a string or
* if the value could not be transformed.
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
throw new TransformationFailedException('Expected a string.');
}
if ('' === $value) {

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -52,13 +51,13 @@ class ValueToDuplicatesTransformer implements DataTransformerInterface
*
* @return mixed The value
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the given array can not be transformed
* @throws TransformationFailedException If the given value is not an array or
* if the given array can not be transformed.
*/
public function reverseTransform($array)
{
if (!is_array($array)) {
throw new UnexpectedTypeException($array, 'array');
throw new TransformationFailedException('Expected an array.');
}
$result = current($array);

View File

@ -68,7 +68,7 @@ class ArrayToPartsTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformRequiresArray()
{
@ -123,7 +123,7 @@ class ArrayToPartsTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformPartiallyNull()
{
@ -140,7 +140,7 @@ class ArrayToPartsTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformRequiresArray()
{

View File

@ -38,14 +38,14 @@ class BooleanToStringTransformerTest extends \PHPUnit_Framework_TestCase
public function testTransformExpectsBoolean()
{
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$this->transformer->transform('1');
}
public function testReverseTransformExpectsString()
{
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$this->transformer->reverseTransform(1);
}

View File

@ -67,7 +67,7 @@ class ChoiceToValueTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformExpectsScalar()
{

View File

@ -45,7 +45,7 @@ class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformExpectsArray()
{
@ -67,7 +67,7 @@ class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformExpectsArray()
{

View File

@ -117,7 +117,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformRequiresDateTime()
{
@ -191,7 +191,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformPartiallyEmptyYear()
{
@ -206,7 +206,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformPartiallyEmptyMonth()
{
@ -221,7 +221,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformPartiallyEmptyDay()
{
@ -236,7 +236,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformPartiallyEmptyHour()
{
@ -251,7 +251,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformPartiallyEmptyMinute()
{
@ -266,7 +266,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformPartiallyEmptySecond()
{
@ -326,7 +326,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformRequiresArray()
{
@ -335,7 +335,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithNegativeYear()
{
@ -351,7 +351,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithNegativeMonth()
{
@ -367,7 +367,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithNegativeDay()
{
@ -383,7 +383,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithNegativeHour()
{
@ -399,7 +399,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithNegativeMinute()
{
@ -415,7 +415,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithNegativeSecond()
{
@ -431,7 +431,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithInvalidMonth()
{
@ -447,7 +447,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithInvalidDay()
{
@ -463,7 +463,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithStringDay()
{
@ -479,7 +479,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithStringMonth()
{
@ -495,7 +495,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithStringYear()
{

View File

@ -148,7 +148,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformRequiresValidDateTime()
{
@ -231,7 +231,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformRequiresString()
{

View File

@ -79,7 +79,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformRequiresValidDateTime()
{
@ -102,7 +102,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformRequiresString()
{
@ -111,7 +111,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformWithNonExistingDate()
{
@ -121,7 +121,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformExpectsValidDateString()
{

View File

@ -101,7 +101,7 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase
{
$transformer = new DateTimeToStringTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$transformer->transform('1234');
}
@ -156,7 +156,7 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase
{
$reverseTransformer = new DateTimeToStringTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$reverseTransformer->reverseTransform(1234);
}

View File

@ -60,7 +60,7 @@ class DateTimeToTimestampTransformerTest extends DateTimeTestCase
{
$transformer = new DateTimeToTimestampTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$transformer->transform('1234');
}
@ -97,7 +97,7 @@ class DateTimeToTimestampTransformerTest extends DateTimeTestCase
{
$reverseTransformer = new DateTimeToTimestampTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$reverseTransformer->reverseTransform('2010-2010-2010');
}

View File

@ -50,7 +50,7 @@ class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformExpectsString()
{
@ -60,7 +60,7 @@ class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformExpectsValidNumber()
{
@ -70,7 +70,7 @@ class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformDisallowsNaN()
{
@ -80,7 +80,7 @@ class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformDisallowsNaN2()
{
@ -90,7 +90,7 @@ class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformDisallowsInfinity()
{
@ -100,7 +100,7 @@ class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformDisallowsNegativeInfinity()
{

View File

@ -33,7 +33,7 @@ class MoneyToLocalizedStringTransformerTest extends LocalizedTestCase
{
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$transformer->transform('abcd');
}
@ -56,7 +56,7 @@ class MoneyToLocalizedStringTransformerTest extends LocalizedTestCase
{
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$transformer->reverseTransform(12345);
}

View File

@ -207,7 +207,7 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformExpectsNumeric()
{
@ -217,7 +217,7 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformExpectsString()
{

View File

@ -94,7 +94,7 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
{
$transformer = new PercentToLocalizedStringTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$transformer->transform('foo');
}
@ -103,7 +103,7 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
{
$transformer = new PercentToLocalizedStringTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
$transformer->reverseTransform(1);
}

View File

@ -83,7 +83,7 @@ class ValueToDuplicatesTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformPartiallyNull()
{
@ -97,7 +97,7 @@ class ValueToDuplicatesTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformDifferences()
{
@ -111,7 +111,7 @@ class ValueToDuplicatesTransformerTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformRequiresArray()
{