Merge branch '2.2'
* 2.2: added additional tests to cover invalid argument exceptions in OutputFormatterStyle component added a missing check for the provider key [Validator] fixed wrong URL for XSD [Validator] Fixed: $traverse and $deep is passed to the visitor from Validator::validate() [Form] Fixed transform()/reverseTransform() to always throw TransformationFailedExceptions [Form] Fixed: String validation groups are never interpreted as callbacks if the repository method returns an array ensure that it's internal poin... [Form] Improved multi-byte handling of NumberToLocalizedStringTransformer Fix wrong method in findTaggedServiceIds(), add example to docblock. Conflicts: src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php
This commit is contained in:
commit
f1c227be22
@ -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;
|
||||
@ -28,7 +28,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
|
||||
*
|
||||
* @return mixed An array of entities
|
||||
*
|
||||
* @throws UnexpectedTypeException
|
||||
* @throws TransformationFailedException
|
||||
*/
|
||||
public function transform($collection)
|
||||
{
|
||||
@ -37,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();
|
||||
|
@ -286,6 +286,31 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
||||
$this->assertEquals(0, $violationsList->count(), 'Violation is using custom repository method.');
|
||||
}
|
||||
|
||||
public function testValidateUniquenessWithUnrewoundArray()
|
||||
{
|
||||
$entity = new SingleIdentEntity(1, 'foo');
|
||||
|
||||
$entityManagerName = 'foo';
|
||||
$repository = $this->createRepositoryMock();
|
||||
$repository->expects($this->once())
|
||||
->method('findByCustom')
|
||||
->will(
|
||||
$this->returnCallback(function() use ($entity) {
|
||||
$returnValue = array(
|
||||
$entity,
|
||||
);
|
||||
next($returnValue);
|
||||
return $returnValue;
|
||||
})
|
||||
)
|
||||
;
|
||||
$em = $this->createEntityManagerMock($repository);
|
||||
$validator = $this->createValidator($entityManagerName, $em, null, array(), null, 'findByCustom');
|
||||
|
||||
$violationsList = $validator->validate($entity);
|
||||
$this->assertCount(0, $violationsList, 'Violation is using unrewound array as return value in the repository method.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group GH-1635
|
||||
*/
|
||||
|
@ -111,6 +111,8 @@ class UniqueEntityValidator extends ConstraintValidator
|
||||
*/
|
||||
if ($result instanceof \Iterator) {
|
||||
$result->rewind();
|
||||
} elseif (is_array($result)) {
|
||||
reset($result);
|
||||
}
|
||||
|
||||
/* If no entity matched the query criteria or a single entity matched,
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -73,5 +73,21 @@ class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$style->setOptions(array('bold'));
|
||||
$this->assertEquals("\033[1mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
try {
|
||||
$style->setOption('foo');
|
||||
$this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||
}
|
||||
|
||||
try {
|
||||
$style->unsetOption('foo');
|
||||
$this->fail('->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1017,9 +1017,20 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
/**
|
||||
* Returns service ids for a given tag.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $container->register('foo')->addTag('my.tag', array('hello' => 'world'));
|
||||
*
|
||||
* $serviceIds = $container->findTaggedServiceIds('my.tag');
|
||||
* foreach ($serviceIds as $serviceId => $tags) {
|
||||
* foreach ($tags as $tag) {
|
||||
* echo $tag['hello'];
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @param string $name The tag name
|
||||
*
|
||||
* @return array An array of tags
|
||||
* @return array An array of tags with the tagged service as key, holding a list of attribute arrays.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@ -1027,7 +1038,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
{
|
||||
$tags = array();
|
||||
foreach ($this->getDefinitions() as $id => $definition) {
|
||||
if ($definition->getTag($name)) {
|
||||
if ($definition->hasTag($name)) {
|
||||
$tags[$id] = $definition->getTag($name);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
@ -46,12 +45,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)
|
||||
{
|
||||
@ -85,14 +84,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 {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -24,7 +24,7 @@ class DataTransformerChain implements DataTransformerInterface
|
||||
{
|
||||
/**
|
||||
* The value transformers
|
||||
* @var array
|
||||
* @var DataTransformerInterface[]
|
||||
*/
|
||||
protected $transformers;
|
||||
|
||||
@ -51,7 +51,6 @@ class DataTransformerChain implements DataTransformerInterface
|
||||
* @return mixed The transformed value
|
||||
*
|
||||
* @throws TransformationFailedException
|
||||
* @throws UnexpectedTypeException
|
||||
*/
|
||||
public function transform($value)
|
||||
{
|
||||
@ -76,7 +75,6 @@ class DataTransformerChain implements DataTransformerInterface
|
||||
* @return mixed The reverse-transformed value
|
||||
*
|
||||
* @throws TransformationFailedException
|
||||
* @throws UnexpectedTypeException
|
||||
*/
|
||||
public function reverseTransform($value)
|
||||
{
|
||||
|
@ -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)) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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();
|
||||
@ -80,6 +79,9 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
||||
throw new TransformationFailedException($formatter->getErrorMessage());
|
||||
}
|
||||
|
||||
// Convert fixed spaces to normal ones
|
||||
$value = str_replace("\xc2\xa0", ' ', $value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -90,13 +92,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) {
|
||||
@ -130,19 +132,31 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
||||
throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like');
|
||||
}
|
||||
|
||||
if (function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value)) {
|
||||
$strlen = function ($string) use ($encoding) {
|
||||
return mb_strlen($string, $encoding);
|
||||
};
|
||||
$substr = function ($string, $offset, $length) use ($encoding) {
|
||||
return mb_substr($string, $offset, $length, $encoding);
|
||||
};
|
||||
} else {
|
||||
$strlen = 'strlen';
|
||||
$substr = 'substr';
|
||||
}
|
||||
|
||||
$length = $strlen($value);
|
||||
|
||||
// After parsing, position holds the index of the character where the
|
||||
// parsing stopped
|
||||
if ($position < strlen($value)) {
|
||||
if ($position < $length) {
|
||||
// Check if there are unrecognized characters at the end of the
|
||||
// number
|
||||
$remainder = substr($value, $position);
|
||||
// number (excluding whitespace characters)
|
||||
$remainder = trim($substr($value, $position, $length), " \t\n\r\0\x0b\xc2\xa0");
|
||||
|
||||
// Remove all whitespace characters
|
||||
if ('' !== preg_replace('/[\s\xc2\xa0]*/', '', $remainder)) {
|
||||
if ('' !== $remainder) {
|
||||
throw new TransformationFailedException(
|
||||
sprintf('The number contains unrecognized characters: "%s"',
|
||||
$remainder
|
||||
));
|
||||
sprintf('The number contains unrecognized characters: "%s"', $remainder)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -227,7 +227,7 @@ class FormValidator extends ConstraintValidator
|
||||
*/
|
||||
private static function resolveValidationGroups($groups, FormInterface $form)
|
||||
{
|
||||
if (is_callable($groups)) {
|
||||
if (!is_string($groups) && is_callable($groups)) {
|
||||
$groups = call_user_func($groups, $form);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
{
|
||||
@ -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()
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testTransformRequiresDateTime()
|
||||
{
|
||||
@ -326,7 +326,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformRequiresArray()
|
||||
{
|
||||
|
@ -142,7 +142,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testTransformRequiresValidDateTime()
|
||||
{
|
||||
@ -221,7 +221,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformRequiresString()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
@ -121,7 +121,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformExpectsValidDateString()
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class IntegerToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformExpectsString()
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ class MoneyToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
||||
|
||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->transform('abcd');
|
||||
}
|
||||
@ -60,7 +60,7 @@ class MoneyToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
||||
|
||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->reverseTransform(12345);
|
||||
}
|
||||
|
@ -26,29 +26,52 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
\Locale::setDefault('de_AT');
|
||||
}
|
||||
|
||||
public function testTransform()
|
||||
public function provideTransformations()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer();
|
||||
|
||||
$this->assertEquals('1', $transformer->transform(1));
|
||||
$this->assertEquals('1,5', $transformer->transform(1.5));
|
||||
$this->assertEquals('1234,5', $transformer->transform(1234.5));
|
||||
$this->assertEquals('12345,912', $transformer->transform(12345.9123));
|
||||
return array(
|
||||
array(null, '', 'de_AT'),
|
||||
array(1, '1', 'de_AT'),
|
||||
array(1.5, '1,5', 'de_AT'),
|
||||
array(1234.5, '1234,5', 'de_AT'),
|
||||
array(12345.912, '12345,912', 'de_AT'),
|
||||
array(1234.5, '1234,5', 'ru'),
|
||||
array(1234.5, '1234,5', 'fi'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testTransformEmpty()
|
||||
/**
|
||||
* @dataProvider provideTransformations
|
||||
*/
|
||||
public function testTransform($from, $to, $locale)
|
||||
{
|
||||
\Locale::setDefault($locale);
|
||||
|
||||
$transformer = new NumberToLocalizedStringTransformer();
|
||||
|
||||
$this->assertSame('', $transformer->transform(null));
|
||||
$this->assertSame($to, $transformer->transform($from));
|
||||
}
|
||||
|
||||
public function testTransformWithGrouping()
|
||||
public function provideTransformationsWithGrouping()
|
||||
{
|
||||
return array(
|
||||
array(1234.5, '1.234,5', 'de_AT'),
|
||||
array(12345.912, '12.345,912', 'de_AT'),
|
||||
array(1234.5, '1 234,5', 'fr'),
|
||||
array(1234.5, '1 234,5', 'ru'),
|
||||
array(1234.5, '1 234,5', 'fi'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTransformationsWithGrouping
|
||||
*/
|
||||
public function testTransformWithGrouping($from, $to, $locale)
|
||||
{
|
||||
\Locale::setDefault($locale);
|
||||
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$this->assertEquals('1.234,5', $transformer->transform(1234.5));
|
||||
$this->assertEquals('12.345,912', $transformer->transform(12345.9123));
|
||||
$this->assertSame($to, $transformer->transform($from));
|
||||
}
|
||||
|
||||
public function testTransformWithPrecision()
|
||||
@ -69,30 +92,48 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
}
|
||||
|
||||
public function testReverseTransform()
|
||||
/**
|
||||
* @dataProvider provideTransformations
|
||||
*/
|
||||
public function testReverseTransform($to, $from, $locale)
|
||||
{
|
||||
\Locale::setDefault($locale);
|
||||
|
||||
$transformer = new NumberToLocalizedStringTransformer();
|
||||
|
||||
$this->assertEquals(1, $transformer->reverseTransform('1'));
|
||||
$this->assertEquals(1.5, $transformer->reverseTransform('1,5'));
|
||||
$this->assertEquals(1234.5, $transformer->reverseTransform('1234,5'));
|
||||
$this->assertEquals(12345.912, $transformer->reverseTransform('12345,912'));
|
||||
$this->assertEquals($to, $transformer->reverseTransform($from));
|
||||
}
|
||||
|
||||
public function testReverseTransformEmpty()
|
||||
/**
|
||||
* @dataProvider provideTransformationsWithGrouping
|
||||
*/
|
||||
public function testReverseTransformWithGrouping($to, $from, $locale)
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer();
|
||||
\Locale::setDefault($locale);
|
||||
|
||||
$this->assertNull($transformer->reverseTransform(''));
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$this->assertEquals($to, $transformer->reverseTransform($from));
|
||||
}
|
||||
|
||||
public function testReverseTransformWithGrouping()
|
||||
// https://github.com/symfony/symfony/issues/7609
|
||||
public function testReverseTransformWithGroupingAndFixedSpaces()
|
||||
{
|
||||
if (!extension_loaded('mbstring')) {
|
||||
$this->markTestSkipped('The "mbstring" extension is required for this test.');
|
||||
}
|
||||
|
||||
\Locale::setDefault('ru');
|
||||
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$this->assertEquals(1234.5, $transformer->reverseTransform("1\xc2\xa0234,5"));
|
||||
}
|
||||
|
||||
public function testReverseTransformWithGroupingButWithoutGroupSeparator()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
// completely valid format
|
||||
$this->assertEquals(1234.5, $transformer->reverseTransform('1.234,5'));
|
||||
$this->assertEquals(12345.912, $transformer->reverseTransform('12.345,912'));
|
||||
// omit group separator
|
||||
$this->assertEquals(1234.5, $transformer->reverseTransform('1234,5'));
|
||||
$this->assertEquals(12345.912, $transformer->reverseTransform('12345,912'));
|
||||
@ -187,7 +228,7 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testTransformExpectsNumeric()
|
||||
{
|
||||
@ -197,7 +238,7 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformExpectsString()
|
||||
{
|
||||
@ -279,6 +320,7 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
* @expectedExceptionMessage The number contains unrecognized characters: "foo3"
|
||||
*/
|
||||
public function testReverseTransformDisallowsCenteredExtraCharacters()
|
||||
{
|
||||
@ -289,6 +331,41 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
|
||||
*/
|
||||
public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
|
||||
{
|
||||
if (!extension_loaded('mbstring')) {
|
||||
$this->markTestSkipped('The "mbstring" extension is required for this test.');
|
||||
}
|
||||
|
||||
\Locale::setDefault('ru');
|
||||
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$transformer->reverseTransform("12\xc2\xa0345,67foo8");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
|
||||
*/
|
||||
public function testReverseTransformIgnoresTrailingSpacesInExceptionMessage()
|
||||
{
|
||||
if (!extension_loaded('mbstring')) {
|
||||
$this->markTestSkipped('The "mbstring" extension is required for this test.');
|
||||
}
|
||||
|
||||
\Locale::setDefault('ru');
|
||||
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$transformer->reverseTransform("12\xc2\xa0345,67foo8 \xc2\xa0\t");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
* @expectedExceptionMessage The number contains unrecognized characters: "foo"
|
||||
*/
|
||||
public function testReverseTransformDisallowsTrailingExtraCharacters()
|
||||
{
|
||||
@ -296,4 +373,21 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$transformer->reverseTransform('123foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
* @expectedExceptionMessage The number contains unrecognized characters: "foo"
|
||||
*/
|
||||
public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()
|
||||
{
|
||||
if (!extension_loaded('mbstring')) {
|
||||
$this->markTestSkipped('The "mbstring" extension is required for this test.');
|
||||
}
|
||||
|
||||
\Locale::setDefault('ru');
|
||||
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$transformer->reverseTransform("12\xc2\xa0345,678foo");
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ class PercentToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
|
||||
{
|
||||
$transformer = new PercentToLocalizedStringTransformer();
|
||||
|
||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->transform('foo');
|
||||
}
|
||||
@ -107,7 +107,7 @@ class PercentToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCas
|
||||
{
|
||||
$transformer = new PercentToLocalizedStringTransformer();
|
||||
|
||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||
|
||||
$transformer->reverseTransform(1);
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -377,6 +377,23 @@ class FormValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->validator->validate($form, new Form());
|
||||
}
|
||||
|
||||
public function testDontExecuteFunctionNames()
|
||||
{
|
||||
$context = $this->getMockExecutionContext();
|
||||
$object = $this->getMock('\stdClass');
|
||||
$options = array('validation_groups' => 'header');
|
||||
$form = $this->getBuilder('name', '\stdClass', $options)
|
||||
->setData($object)
|
||||
->getForm();
|
||||
|
||||
$context->expects($this->once())
|
||||
->method('validate')
|
||||
->with($object, 'data', 'header', true);
|
||||
|
||||
$this->validator->initialize($context);
|
||||
$this->validator->validate($form, new Form());
|
||||
}
|
||||
|
||||
public function testHandleClosureValidationGroups()
|
||||
{
|
||||
$context = $this->getMockExecutionContext();
|
||||
|
@ -47,7 +47,7 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles X509 authentication.
|
||||
* Handles pre-authentication.
|
||||
*
|
||||
* @param GetResponseEvent $event A GetResponseEvent instance
|
||||
*/
|
||||
@ -62,7 +62,7 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
|
||||
list($user, $credentials) = $this->getPreAuthenticatedData($request);
|
||||
|
||||
if (null !== $token = $this->securityContext->getToken()) {
|
||||
if ($token instanceof PreAuthenticatedToken && $token->isAuthenticated() && $token->getUsername() === $user) {
|
||||
if ($token instanceof PreAuthenticatedToken && $this->providerKey == $token->getProviderKey() && $token->isAuthenticated() && $token->getUsername() === $user) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
|
||||
|
||||
<namespace prefix="custom">Symfony\Component\Validator\Tests\Fixtures\</namespace>
|
||||
|
||||
|
@ -2,6 +2,6 @@
|
||||
<!DOCTYPE foo>
|
||||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
|
||||
<class name="Symfony\Component\Validator\Tests\Fixtures\Entity" />
|
||||
</constraint-mapping>
|
||||
|
@ -87,7 +87,7 @@ class Validator implements ValidatorInterface
|
||||
$visitor = $this->createVisitor($value);
|
||||
|
||||
foreach ($this->resolveGroups($groups) as $group) {
|
||||
$visitor->validate($value, $group, '');
|
||||
$visitor->validate($value, $group, '', $traverse, $deep);
|
||||
}
|
||||
|
||||
return $visitor->getViolations();
|
||||
|
Reference in New Issue
Block a user