Merge branch '2.1' into 2.2

* 2.1:
  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
  [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...
  Fix wrong method in findTaggedServiceIds(), add example to docblock.

Conflicts:
	src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php
	src/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php
	src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ArrayToPartsTransformerTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoiceToValueTransformerTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoicesToValuesTransformerTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php
This commit is contained in:
Fabien Potencier 2013-05-06 10:37:50 +02:00
commit b9bc5b4770
44 changed files with 214 additions and 149 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;
@ -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();

View File

@ -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
*/

View File

@ -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,

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

@ -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');
}
}
}

View File

@ -946,9 +946,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
*/
@ -956,7 +967,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);
}
}

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

@ -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)
{

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();
@ -93,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) {

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

@ -175,7 +175,7 @@ class FormValidator extends ConstraintValidator
$groups = $form->getConfig()->getOption('validation_groups');
if (null !== $groups) {
if (is_callable($groups)) {
if (!is_string($groups) && is_callable($groups)) {
$groups = call_user_func($groups, $form);
}

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()
{
@ -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()
{
@ -326,7 +326,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformRequiresArray()
{

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()
{
@ -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()
{

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

@ -248,7 +248,7 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformExpectsNumeric()
{
@ -258,7 +258,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

@ -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()
{

View File

@ -291,6 +291,24 @@ class FormValidatorTest extends \PHPUnit_Framework_TestCase
$this->validator->validate($form, new Form());
}
public function testDontExecuteFunctionNames()
{
$context = $this->getExecutionContext();
$graphWalker = $context->getGraphWalker();
$object = $this->getMock('\stdClass');
$options = array('validation_groups' => 'header');
$form = $this->getBuilder('name', '\stdClass', $options)
->setData($object)
->getForm();
$graphWalker->expects($this->once())
->method('walkReference')
->with($object, 'header', 'data', true);
$this->validator->initialize($context);
$this->validator->validate($form, new Form());
}
public function testHandleClosureValidationGroups()
{
$context = $this->getMockExecutionContext();

View File

@ -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;
}
}

View File

@ -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>

View File

@ -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>