merged branch colinfrei/deprecationErrors (PR #6180)

This PR was merged into the master branch.

Commits
-------

6b10550 Merge branch 'master' of github.com:symfony/symfony into deprecationErrors
1d82112 [Form] Fix two cases where deprecated methods were being used
b8cdbdc [Form] Catch deprecation errors that are caused by BC code
ebcb432 [Form] [FrameworkBundle] catch deprecation errors in tests
c21b12e [Form] handle BC use of deprecated stuff in non-test-methods.
fc2be6d [Form] catch deprecated errors in tests
800a032 [Form] replace bindRequest() with bind(), as bindRequest is deprecated
d5b2638 [Form] Trigger errors for deprecated methods in Form Component
f3d6966 [Validator] Stop using deprecated methods
d57ad32 [Form] Catch deprecation errors when using deprecated methods/classes in tests
3241157 [Validator] Trigger errors for deprecations
1f9eb7f return value of handleError
b35de9e Handle errors using a custom error handler
f49704b trigger errors for deprecated methods in HttpFoundation component

Discussion
----------

trigger_error() for deprecations

See also #6173 and #6139.

Started triggering errors in the HttpFoundation component.
It seems as if most of the time the error is just duplicating the text in the @deprecation comment.

Any opinions on if duplicating the text is acceptable, or if fetching the comment text to output the error makes sense?

---------------------------------------------------------------------------

by Seldaek at 2012-12-04T13:39:42Z

IMO it's fine to just duplicate the `@deprecated` note in the message, since anyway this code is meant to be completely deleted, this duplication should not do much harm.

---------------------------------------------------------------------------

by fabpot at 2012-12-06T08:22:21Z

@colinfrei I've merged PR #6173. Do you have time to implement the `trigger_error()` call everywhere? Thanks.

---------------------------------------------------------------------------

by colinfrei at 2012-12-06T08:36:55Z

Yep I'll finish that, probably until the beginning of next week.

---------------------------------------------------------------------------

by bschussek at 2012-12-10T10:15:12Z

Thank you for working on this!

---------------------------------------------------------------------------

by fabpot at 2012-12-12T11:08:53Z

@colinfrei: Is this PR finished? Can I merge it?

---------------------------------------------------------------------------

by colinfrei at 2012-12-12T12:09:19Z

@fabpot not quite - I lost some work due to a computer crash over the weekend. The only thing open is fixing the tests  for the Form Component and catching the cases where the Form Component intentionally uses deprecated stuff.

---------------------------------------------------------------------------

by colinfrei at 2012-12-15T07:32:28Z

@fabpot - finished adding trigger_errors and catching them in Tests and as needed.
Travis is failing, but that seems to be master being broken due to the Finder changes?

I changed a few cases where the code was using deprecated methods which wasn't necessary in my eyes, specifically   1d8211249b, 800a032f07, f3d696636a
This commit is contained in:
Fabien Potencier 2012-12-15 08:53:57 +01:00
commit e3cc337b00
57 changed files with 525 additions and 63 deletions

View File

@ -143,6 +143,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
*/
public function guessMinLength($class, $property)
{
trigger_error('guessMinLength() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**

View File

@ -63,7 +63,7 @@ class UniqueEntityValidator extends ConstraintValidator
$em = $this->registry->getManagerForClass(get_class($entity));
}
$className = $this->context->getCurrentClass();
$className = $this->context->getClassName();
$class = $em->getClassMetadata($className);
/* @var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata */
@ -120,6 +120,6 @@ class UniqueEntityValidator extends ConstraintValidator
$errorPath = null !== $constraint->errorPath ? $constraint->errorPath : $fields[0];
$this->context->addViolationAtSubPath($errorPath, $constraint->message, array(), $criteria[$fields[0]]);
$this->context->addViolationAt($errorPath, $constraint->message, array(), $criteria[$fields[0]]);
}
}

View File

@ -126,6 +126,7 @@ class PropelTypeGuesser implements FormTypeGuesserInterface
*/
public function guessMinLength($class, $property)
{
trigger_error('guessMinLength() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**

View File

@ -68,6 +68,8 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
protected function tearDown()
{
$this->engine = null;
parent::tearDown();
}
protected function renderEnctype(FormView $view)

View File

@ -69,6 +69,8 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest
protected function tearDown()
{
$this->engine = null;
parent::tearDown();
}
protected function renderEnctype(FormView $view)

View File

@ -51,8 +51,10 @@ abstract class AbstractType implements FormTypeInterface
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$resolver->setDefaults($this->getDefaultOptions(array()));
$resolver->addAllowedValues($this->getAllowedOptionValues(array()));
restore_error_handler();
}
/**
@ -67,6 +69,8 @@ abstract class AbstractType implements FormTypeInterface
*/
public function getDefaultOptions(array $options)
{
trigger_error('getDefaultOptions() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
return array();
}
@ -82,6 +86,8 @@ abstract class AbstractType implements FormTypeInterface
*/
public function getAllowedOptionValues(array $options)
{
trigger_error('getAllowedOptionValues() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
return array();
}
@ -104,6 +110,8 @@ abstract class AbstractType implements FormTypeInterface
*/
public function setExtensions(array $extensions)
{
trigger_error('setExtensions() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
$this->extensions = $extensions;
}
@ -117,6 +125,8 @@ abstract class AbstractType implements FormTypeInterface
*/
public function getExtensions()
{
trigger_error('getExtensions() is deprecated since version 2.1 and will be removed in 2.3. Use ResolvedFormTypeInterface::getTypeExtensions instead.', E_USER_DEPRECATED);
return $this->extensions;
}
}

View File

@ -44,8 +44,10 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$resolver->setDefaults($this->getDefaultOptions());
$resolver->addAllowedValues($this->getAllowedOptionValues());
restore_error_handler();
}
/**
@ -58,6 +60,8 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface
*/
public function getDefaultOptions()
{
trigger_error('getDefaultOptions() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
return array();
}
@ -71,6 +75,8 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface
*/
public function getAllowedOptionValues()
{
trigger_error('getAllowedOptionValues() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
return array();
}
}

View File

@ -27,6 +27,8 @@ class CallbackValidator implements FormValidatorInterface
*/
public function __construct($callback)
{
trigger_error('CallbackValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
$this->callback = $callback;
}
@ -35,6 +37,8 @@ class CallbackValidator implements FormValidatorInterface
*/
public function validate(FormInterface $form)
{
trigger_error('validate() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return call_user_func($this->callback, $form);
}
}

View File

@ -33,6 +33,8 @@ class DataEvent extends Event
*/
public function __construct(FormInterface $form, $data)
{
trigger_error('DataEvent is deprecated since version 2.1 and will be removed in 2.3. Code against \Symfony\Component\Form\FormEvent instead.', E_USER_DEPRECATED);
$this->form = $form;
$this->data = $data;
}

View File

@ -22,6 +22,11 @@ use Symfony\Component\Form\AbstractType;
*/
class FieldType extends AbstractType
{
function __construct()
{
trigger_error('FieldType is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* {@inheritdoc}
*/

View File

@ -70,6 +70,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
*/
public function guessMinLength($class, $property)
{
trigger_error('guessMinLength() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**

View File

@ -210,6 +210,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function getTypes()
{
trigger_error('getTypes() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getType() instead.', E_USER_DEPRECATED);
$types = array();
for ($type = $this->config->getType(); null !== $type; $type = $type->getParent()) {
@ -279,6 +281,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function hasParent()
{
trigger_error('hasParent() is deprecated since version 2.1 and will be removed in 2.3. Use getParent() or inverse isRoot() instead.', E_USER_DEPRECATED);
return null !== $this->parent;
}
@ -310,6 +314,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function hasAttribute($name)
{
trigger_error('hasAttribute() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::hasAttribute() instead.', E_USER_DEPRECATED);
return $this->config->hasAttribute($name);
}
@ -325,6 +331,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function getAttribute($name)
{
trigger_error('getAttribute() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getAttribute() instead.', E_USER_DEPRECATED);
return $this->config->getAttribute($name);
}
@ -358,7 +366,9 @@ class Form implements \IteratorAggregate, FormInterface
// Hook to change content of the data
if ($dispatcher->hasListeners(FormEvents::PRE_SET_DATA) || $dispatcher->hasListeners(FormEvents::SET_DATA)) {
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$event = new FormEvent($this, $modelData);
restore_error_handler();
$dispatcher->dispatch(FormEvents::PRE_SET_DATA, $event);
// BC until 2.3
$dispatcher->dispatch(FormEvents::SET_DATA, $event);
@ -470,6 +480,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function getClientData()
{
trigger_error('getClientData() is deprecated since version 2.1 and will be removed in 2.3. Use getViewData() instead.', E_USER_DEPRECATED);
return $this->getViewData();
}
@ -519,7 +531,9 @@ class Form implements \IteratorAggregate, FormInterface
// Hook to change content of the data bound by the browser
if ($dispatcher->hasListeners(FormEvents::PRE_BIND) || $dispatcher->hasListeners(FormEvents::BIND_CLIENT_DATA)) {
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$event = new FormEvent($this, $submittedData);
restore_error_handler();
$dispatcher->dispatch(FormEvents::PRE_BIND, $event);
// BC until 2.3
$dispatcher->dispatch(FormEvents::BIND_CLIENT_DATA, $event);
@ -579,7 +593,9 @@ class Form implements \IteratorAggregate, FormInterface
// Hook to change content of the data into the normalized
// representation
if ($dispatcher->hasListeners(FormEvents::BIND) || $dispatcher->hasListeners(FormEvents::BIND_NORM_DATA)) {
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$event = new FormEvent($this, $normData);
restore_error_handler();
$dispatcher->dispatch(FormEvents::BIND, $event);
// BC until 2.3
$dispatcher->dispatch(FormEvents::BIND_NORM_DATA, $event);
@ -603,9 +619,11 @@ class Form implements \IteratorAggregate, FormInterface
$dispatcher->dispatch(FormEvents::POST_BIND, $event);
}
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
foreach ($this->config->getValidators() as $validator) {
$validator->validate($this);
}
restore_error_handler();
return $this;
}
@ -627,6 +645,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function bindRequest(Request $request)
{
trigger_error('bindRequest() is deprecated since version 2.1 and will be removed in 2.3. Use FormConfigInterface::bind() instead.', E_USER_DEPRECATED);
return $this->bind($request);
}
@ -635,7 +655,7 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function addError(FormError $error)
{
if ($this->parent && $this->getErrorBubbling()) {
if ($this->parent && $this->config->getErrorBubbling()) {
$this->parent->addError($error);
} else {
$this->errors[] = $error;
@ -654,6 +674,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function getErrorBubbling()
{
trigger_error('getErrorBubbling() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getErrorBubbling() instead.', E_USER_DEPRECATED);
return $this->config->getErrorBubbling();
}
@ -725,6 +747,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function hasErrors()
{
trigger_error('hasErrors() is deprecated since version 2.1 and will be removed in 2.3. Count getErrors() instead.', E_USER_DEPRECATED);
return count($this->errors) > 0;
}
@ -774,6 +798,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function getNormTransformers()
{
trigger_error('getNormTransformers() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getModelTransformers() instead.', E_USER_DEPRECATED);
return $this->config->getModelTransformers();
}
@ -787,6 +813,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function getClientTransformers()
{
trigger_error('getClientTransformers() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getViewTransformers() instead.', E_USER_DEPRECATED);
return $this->config->getViewTransformers();
}
@ -808,6 +836,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function getChildren()
{
trigger_error('getChilren() is deprecated since version 2.1 and will be removed in 2.3. Use all() instead.', E_USER_DEPRECATED);
return $this->all();
}
@ -821,6 +851,8 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function hasChildren()
{
trigger_error('hasChildren() is deprecated since version 2.1 and will be removed in 2.3. Use count() instead.', E_USER_DEPRECATED);
return count($this->children) > 0;
}

View File

@ -295,6 +295,8 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
*/
public function getTypes()
{
trigger_error('getTypes() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getType() instead.', E_USER_DEPRECATED);
$types = array();
for ($type = $this->getType(); null !== $type; $type = $type->getParent()) {

View File

@ -196,6 +196,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function addValidator(FormValidatorInterface $validator)
{
trigger_error('addValidator() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
@ -251,6 +253,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function appendClientTransformer(DataTransformerInterface $viewTransformer)
{
trigger_error('appendClientTransformer() is deprecated since version 2.1 and will be removed in 2.3. Use addViewTransformer() instead.', E_USER_DEPRECATED);
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
@ -271,6 +275,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function prependClientTransformer(DataTransformerInterface $viewTransformer)
{
trigger_error('prependClientTransformer() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
@ -290,6 +296,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function resetClientTransformers()
{
trigger_error('resetClientTransformers() is deprecated since version 2.1 and will be removed in 2.3. Use resetViewTransformers() instead.', E_USER_DEPRECATED);
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
@ -342,6 +350,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function appendNormTransformer(DataTransformerInterface $modelTransformer)
{
trigger_error('appendNormTransformer() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
@ -363,6 +373,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function prependNormTransformer(DataTransformerInterface $modelTransformer)
{
trigger_error('prependNormTransformer() is deprecated since version 2.1 and will be removed in 2.3. Use addModelTransformer() instead.', E_USER_DEPRECATED);
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
@ -382,6 +394,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function resetNormTransformers()
{
trigger_error('resetNormTransformers() is deprecated since version 2.1 and will be removed in 2.3. Use resetModelTransformers() instead.', E_USER_DEPRECATED);
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
@ -471,6 +485,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function getClientTransformers()
{
trigger_error('getClientTransformers() is deprecated since version 2.1 and will be removed in 2.3. Use getViewTransformers() instead.', E_USER_DEPRECATED);
return $this->getViewTransformers();
}
@ -492,6 +508,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function getNormTransformers()
{
trigger_error('getNormTransformers() is deprecated since version 2.1 and will be removed in 2.3. Use getModelTransformers() instead.', E_USER_DEPRECATED);
return $this->getModelTransformers();
}
@ -508,6 +526,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
public function getValidators()
{
trigger_error('getValidators() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->validators;
}

View File

@ -99,7 +99,9 @@ class FormFactory implements FormFactoryInterface
$typeGuess = $guesser->guessType($class, $property);
$maxLengthGuess = $guesser->guessMaxLength($class, $property);
// Keep $minLengthGuess for BC until Symfony 2.3
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$minLengthGuess = $guesser->guessMinLength($class, $property);
restore_error_handler();
$requiredGuess = $guesser->guessRequired($class, $property);
$patternGuess = $guesser->guessPattern($class, $property);
@ -146,6 +148,8 @@ class FormFactory implements FormFactoryInterface
*/
public function hasType($name)
{
trigger_error('hasType() is deprecated since version 2.1 and will be removed in 2.3. Use FormRegistryInterface::hasType() instead.', E_USER_DEPRECATED);
return $this->registry->hasType($name);
}
@ -160,6 +164,8 @@ class FormFactory implements FormFactoryInterface
*/
public function addType(FormTypeInterface $type)
{
trigger_error('addType() is deprecated since version 2.1 and will be removed in 2.3. Use form extensions or type registration in the Dependency Injection Container instead.', E_USER_DEPRECATED);
$parentType = $type->getParent();
$this->registry->addType($this->resolvedTypeFactory->createResolvedType(
@ -185,6 +191,8 @@ class FormFactory implements FormFactoryInterface
*/
public function getType($name)
{
trigger_error('getType() is deprecated since version 2.1 and will be removed in 2.3. Use FormRegistryInterface::getType() instead.', E_USER_DEPRECATED);
return $this->registry->getType($name)->getInnerType();
}

View File

@ -68,6 +68,8 @@ class FormRegistry implements FormRegistryInterface
*/
public function addType(ResolvedFormTypeInterface $type)
{
trigger_error('addType() is deprecated since version 2.1 and will be removed in 2.3. Use form extensions or type registration in the Dependency Injection Container instead.', E_USER_DEPRECATED);
$this->types[$type->getName()] = $type;
}
@ -129,11 +131,13 @@ class FormRegistry implements FormRegistryInterface
);
}
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$this->addType($this->resolvedTypeFactory->createResolvedType(
$type,
$typeExtensions,
$parentType ? $this->getType($parentType) : null
));
restore_error_handler();
}
/**

View File

@ -75,6 +75,8 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
*/
public function guessMinLength($class, $property)
{
trigger_error('guessMinLength() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->guess(function ($guesser) use ($class, $property) {
return $guesser->guessMinLength($class, $property);
});

View File

@ -64,6 +64,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function getName()
{
trigger_error('getName() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'vars\' instead which contains an entry named "name".', E_USER_DEPRECATED);
return $this->vars['name'];
}
@ -78,6 +79,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function set($name, $value)
{
trigger_error('set() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'vars\' instead.', E_USER_DEPRECATED);
$this->vars[$name] = $value;
return $this;
@ -93,6 +96,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function has($name)
{
trigger_error('has() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'vars\' instead.', E_USER_DEPRECATED);
return array_key_exists($name, $this->vars);
}
@ -107,6 +112,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function get($name, $default = null)
{
trigger_error('get() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'vars\' instead.', E_USER_DEPRECATED);
if (false === $this->has($name)) {
return $default;
}
@ -122,6 +129,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function all()
{
trigger_error('all() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'vars\' instead.', E_USER_DEPRECATED);
return $this->vars;
}
@ -135,6 +144,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function getVars()
{
trigger_error('getVars() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'vars\' instead.', E_USER_DEPRECATED);
return $this->vars;
}
@ -152,6 +163,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function setAttribute($name, $value)
{
trigger_error('setAttribute() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'vars\' instead which contains an entry named "attr".', E_USER_DEPRECATED);
$this->vars['attr'][$name] = $value;
return $this;
@ -207,6 +220,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function setParent(FormView $parent = null)
{
trigger_error('setParent() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'parent\' instead.', E_USER_DEPRECATED);
$this->parent = $parent;
return $this;
@ -222,6 +237,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function getParent()
{
trigger_error('getParent() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'parent\' instead.', E_USER_DEPRECATED);
return $this->parent;
}
@ -235,6 +252,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function hasParent()
{
trigger_error('hasParent() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'parent\' instead.', E_USER_DEPRECATED);
return null !== $this->parent;
}
@ -250,6 +269,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function setChildren(array $children)
{
trigger_error('setChildren() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'children\' instead.', E_USER_DEPRECATED);
$this->children = $children;
return $this;
@ -265,6 +286,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function getChildren()
{
trigger_error('getChildren() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'children\' instead.', E_USER_DEPRECATED);
return $this->children;
}
@ -280,6 +303,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function getChild($name)
{
trigger_error('getChild() is deprecated since version 2.1 and will be removed in 2.3. Access the public property \'children\' instead.', E_USER_DEPRECATED);
return $this->children[$name];
}
@ -293,6 +318,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function hasChildren()
{
trigger_error('hasChildren() is deprecated since version 2.1 and will be removed in 2.3. Use count() instead.', E_USER_DEPRECATED);
return count($this->children) > 0;
}

View File

@ -45,6 +45,8 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
{
$this->csrfProvider = null;
$this->factory = null;
parent::tearDown();
}
protected function assertXpathNodeValue(\DomElement $element, $expression, $nodeValue)

View File

@ -118,12 +118,16 @@ class CompoundFormTest extends AbstractFormTest
{
$this->form->add($this->getBuilder()->getForm());
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$this->assertTrue($this->form->hasChildren());
restore_error_handler();
}
public function testHasNoChildren()
{
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$this->assertFalse($this->form->hasChildren());
restore_error_handler();
}
public function testAdd()
@ -151,7 +155,9 @@ class CompoundFormTest extends AbstractFormTest
$this->form->remove('foo');
$this->assertNull($child->getParent());
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$this->assertFalse($this->form->hasChildren());
restore_error_handler();
}
/**
@ -364,7 +370,7 @@ class CompoundFormTest extends AbstractFormTest
$form->add($this->getBuilder('name')->getForm());
$form->add($this->getBuilder('image')->getForm());
$form->bindRequest($request);
$form->bind($request);
$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
@ -413,7 +419,7 @@ class CompoundFormTest extends AbstractFormTest
$form->add($this->getBuilder('name')->getForm());
$form->add($this->getBuilder('image')->getForm());
$form->bindRequest($request);
$form->bind($request);
$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
@ -454,7 +460,7 @@ class CompoundFormTest extends AbstractFormTest
->addEventSubscriber(new BindRequestListener())
->getForm();
$form->bindRequest($request);
$form->bind($request);
$file = new UploadedFile($path, 'upload.png', 'image/png', 123, UPLOAD_ERR_OK);
@ -487,7 +493,7 @@ class CompoundFormTest extends AbstractFormTest
->addEventSubscriber(new BindRequestListener())
->getForm();
$form->bindRequest($request);
$form->bind($request);
$this->assertEquals('Bernhard', $form->getData());
@ -519,7 +525,7 @@ class CompoundFormTest extends AbstractFormTest
$form->add($this->getBuilder('firstName')->getForm());
$form->add($this->getBuilder('lastName')->getForm());
$form->bindRequest($request);
$form->bind($request);
$this->assertEquals('Bernhard', $form['firstName']->getData());
$this->assertEquals('Schussek', $form['lastName']->getData());
@ -549,7 +555,7 @@ class CompoundFormTest extends AbstractFormTest
$form->add($this->getBuilder('firstName')->getForm());
$form->add($this->getBuilder('lastName')->getForm());
$form->bindRequest($request);
$form->bind($request);
$this->assertEquals('Bernhard', $form['firstName']->getData());
$this->assertEquals('Schussek', $form['lastName']->getData());

View File

@ -0,0 +1,36 @@
<?php
namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\FormInterface as NonTestFormInterface;
use Symfony\Component\Form\FormEvent;
class DeprecationErrorHandler
{
public static function handle($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
public static function handleBC($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}
return false;
}
public static function getFormEvent(NonTestFormInterface $form, $data)
{
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$event = new FormEvent($form, $data);
restore_error_handler();
return $event;
}
}

View File

@ -11,9 +11,9 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener;
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
use Symfony\Component\Form\Tests\DeprecationErrorHandler;
class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
{
@ -42,7 +42,7 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
{
$data = '1';
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$this->listener->preBind($event);
@ -53,7 +53,7 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
{
$data = '0';
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$this->listener->preBind($event);
@ -64,7 +64,7 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
{
$data = '';
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$this->listener->preBind($event);

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
use Symfony\Component\Form\Tests\DeprecationErrorHandler;
class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
{
@ -27,7 +27,7 @@ class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
{
$data = "www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$filter = new FixUrlProtocolListener('http');
$filter->onBind($event);
@ -39,7 +39,7 @@ class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
{
$data = "http://www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$filter = new FixUrlProtocolListener('http');
$filter->onBind($event);
@ -51,7 +51,7 @@ class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
{
$data = "ftp://www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$filter = new FixUrlProtocolListener('http');
$filter->onBind($event);

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\MergeCollectionListener;
use Symfony\Component\Form\Tests\DeprecationErrorHandler;
abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
{
@ -84,7 +84,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData);
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener->onBind($event);
// The original object was modified
@ -108,7 +108,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData);
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener->onBind($event);
// The original object was modified
@ -133,7 +133,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData);
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener->onBind($event);
// We still have the original object
@ -157,7 +157,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData);
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener->onBind($event);
// The original object was modified
@ -182,7 +182,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData);
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener->onBind($event);
// We still have the original object
@ -201,7 +201,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
public function testRequireArrayOrTraversable($allowAdd, $allowDelete)
{
$newData = 'no array or traversable';
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener = new MergeCollectionListener($allowAdd, $allowDelete);
$listener->onBind($event);
}
@ -215,7 +215,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData);
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener->onBind($event);
$this->assertSame($originalData, $event->getData());
@ -233,7 +233,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData);
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener->onBind($event);
$this->assertSame($newData, $event->getData());
@ -251,7 +251,7 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData);
$event = new FormEvent($this->form, $newData);
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
$listener->onBind($event);
$this->assertNull($event->getData());

View File

@ -11,9 +11,9 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Tests\DeprecationErrorHandler;
class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
{
@ -80,7 +80,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->getForm('2')));
$data = array(1 => 'string', 2 => 'string');
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array('max_length' => '10'), false, false);
$listener->preSetData($event);
@ -95,7 +95,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
public function testPreSetDataRequiresArrayOrTraversable()
{
$data = 'no array or traversable';
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preSetData($event);
}
@ -105,7 +105,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->factory->expects($this->never())->method('createNamed');
$data = null;
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preSetData($event);
}
@ -120,7 +120,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->getForm('1')));
$data = array(0 => 'string', 1 => 'string');
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array('max_length' => 10), true, false);
$listener->preBind($event);
@ -134,7 +134,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1'));
$data = array(0 => 'string');
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event);
@ -148,7 +148,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('0'));
$data = array();
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event);
@ -161,7 +161,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1'));
$data = array(0 => 'string', 2 => 'string');
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preBind($event);
@ -176,7 +176,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
public function testPreBindRequiresArrayOrTraversable()
{
$data = 'no array or traversable';
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preBind($event);
}
@ -186,7 +186,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1'));
$data = null;
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event);
@ -199,7 +199,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1'));
$data = '';
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event);
@ -211,7 +211,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1'));
$data = array(0 => 'first', 1 => 'second', 2 => 'third');
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->onBind($event);
@ -223,7 +223,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1'));
$data = array(0 => 'first', 1 => 'second', 2 => 'third');
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->onBind($event);
@ -236,7 +236,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
public function testOnBindNormDataRequiresArrayOrTraversable()
{
$data = 'no array or traversable';
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->onBind($event);
}
@ -246,7 +246,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1'));
$data = null;
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->onBind($event);

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
use Symfony\Component\Form\Tests\DeprecationErrorHandler;
class TrimListenerTest extends \PHPUnit_Framework_TestCase
{
@ -27,7 +27,7 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
{
$data = " Foo! ";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$filter = new TrimListener();
$filter->preBind($event);
@ -39,7 +39,7 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
{
$data = 1234;
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$filter = new TrimListener();
$filter->preBind($event);
@ -60,7 +60,7 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
$data = $data."ab\ncd".$data;
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FormEvent($form, $data);
$event = DeprecationErrorHandler::getFormEvent($form, $data);
$filter = new TrimListener();
$filter->preBind($event);

View File

@ -11,9 +11,9 @@
namespace Symfony\Component\Form\Tests\Extension\Csrf\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
use Symfony\Component\Form\Tests\DeprecationErrorHandler;
class CsrfValidationListenerTest extends \PHPUnit_Framework_TestCase
{
@ -67,7 +67,7 @@ class CsrfValidationListenerTest extends \PHPUnit_Framework_TestCase
public function testStringFormData()
{
$data = "XP4HUzmHPi";
$event = new FormEvent($this->form, $data);
$event = DeprecationErrorHandler::getFormEvent($this->form, $data);
$validation = new CsrfValidationListener('csrf', $this->csrfProvider, 'unknown');
$validation->preBind($event);

View File

@ -14,9 +14,9 @@ namespace Symfony\Component\Form\Tests\Extension\HttpFoundation\EventListener;
use Symfony\Component\Form\Extension\HttpFoundation\EventListener\BindRequestListener;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Form\Tests\DeprecationErrorHandler;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -98,7 +98,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfigBuilder('author', null, $dispatcher);
$form = new Form($config);
$event = new FormEvent($form, $request);
$event = DeprecationErrorHandler::getFormEvent($form, $request);
$listener = new BindRequestListener();
$listener->preBind($event);
@ -125,7 +125,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfigBuilder('', null, $dispatcher);
$form = new Form($config);
$event = new FormEvent($form, $request);
$event = DeprecationErrorHandler::getFormEvent($form, $request);
$listener = new BindRequestListener();
$listener->preBind($event);
@ -154,7 +154,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
$config->setCompound(true);
$config->setDataMapper($this->getMock('Symfony\Component\Form\DataMapperInterface'));
$form = new Form($config);
$event = new FormEvent($form, $request);
$event = DeprecationErrorHandler::getFormEvent($form, $request);
$listener = new BindRequestListener();
$listener->preBind($event);
@ -180,7 +180,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
$config = new FormConfigBuilder('author', null, $dispatcher);
$config->setCompound(false);
$form = new Form($config);
$event = new FormEvent($form, $request);
$event = DeprecationErrorHandler::getFormEvent($form, $request);
$listener = new BindRequestListener();
$listener->preBind($event);
@ -203,7 +203,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfigBuilder('author', null, $dispatcher);
$form = new Form($config);
$event = new FormEvent($form, $request);
$event = DeprecationErrorHandler::getFormEvent($form, $request);
$listener = new BindRequestListener();
$listener->preBind($event);
@ -227,7 +227,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfigBuilder('', null, $dispatcher);
$form = new Form($config);
$event = new FormEvent($form, $request);
$event = DeprecationErrorHandler::getFormEvent($form, $request);
$listener = new BindRequestListener();
$listener->preBind($event);
@ -253,7 +253,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
$config->setCompound(true);
$config->setDataMapper($this->getMock('Symfony\Component\Form\DataMapperInterface'));
$form = new Form($config);
$event = new FormEvent($form, $request);
$event = DeprecationErrorHandler::getFormEvent($form, $request);
$listener = new BindRequestListener();
$listener->preBind($event);
@ -275,7 +275,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
$config = new FormConfigBuilder('author', null, $dispatcher);
$config->setCompound(false);
$form = new Form($config);
$event = new FormEvent($form, $request);
$event = DeprecationErrorHandler::getFormEvent($form, $request);
$listener = new BindRequestListener();
$listener->preBind($event);

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Form\Tests\Extension\Validator\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormError;
@ -19,6 +18,7 @@ use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\Form\Extension\Validator\Constraints\Form;
use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Form\Tests\DeprecationErrorHandler;
class ValidationListenerTest extends \PHPUnit_Framework_TestCase
{
@ -111,7 +111,7 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
->method('mapViolation')
->with($violation, $form, false);
$this->listener->validateForm(new FormEvent($form, null));
$this->listener->validateForm(DeprecationErrorHandler::getFormEvent($form, null));
}
public function testMapViolationAllowsNonSyncIfInvalid()
@ -128,7 +128,7 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
// pass true now
->with($violation, $form, true);
$this->listener->validateForm(new FormEvent($form, null));
$this->listener->validateForm(DeprecationErrorHandler::getFormEvent($form, null));
}
public function testValidateIgnoresNonRoot()
@ -144,6 +144,6 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
$this->violationMapper->expects($this->never())
->method('mapViolation');
$this->listener->validateForm(new FormEvent($form, null));
$this->listener->validateForm(DeprecationErrorHandler::getFormEvent($form, null));
}
}

View File

@ -85,7 +85,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
->method('addType')
->with($resolvedType);
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$this->factory->addType($type);
restore_error_handler();
}
public function testHasType()
@ -95,7 +97,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
->with('name')
->will($this->returnValue('RESULT'));
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$this->assertSame('RESULT', $this->factory->hasType('name'));
restore_error_handler();
}
public function testGetType()
@ -112,7 +116,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
->with('name')
->will($this->returnValue($resolvedType));
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$this->assertEquals($type, $this->factory->getType('name'));
restore_error_handler();
}
public function testCreateNamedBuilderWithTypeName()

View File

@ -32,6 +32,13 @@ abstract class FormIntegrationTestCase extends \PHPUnit_Framework_TestCase
$this->factory = Forms::createFormFactoryBuilder()
->addExtensions($this->getExtensions())
->getFormFactory();
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
}
protected function tearDown()
{
restore_error_handler();
}
protected function getExtensions()

View File

@ -76,7 +76,9 @@ class FormRegistryTest extends \PHPUnit_Framework_TestCase
->method('getName')
->will($this->returnValue('foo'));
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$this->registry->addType($resolvedType);
restore_error_handler();
$this->assertSame($resolvedType, $this->registry->getType('foo'));
}
@ -223,7 +225,9 @@ class FormRegistryTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->registry->hasType('foo'));
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$this->registry->addType($resolvedType);
restore_error_handler();
$this->assertTrue($this->registry->hasType('foo'));
}

View File

@ -644,9 +644,11 @@ class SimpleFormTest extends AbstractFormTest
{
$test = $this;
$validator = $this->getFormValidator();
set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handle'));
$form = $this->getBuilder()
->addValidator($validator)
->getForm();
restore_error_handler();
$validator->expects($this->once())
->method('validate')

View File

@ -23,7 +23,7 @@ class VirtualFormAwareIterator extends \ArrayIterator implements \RecursiveItera
{
public function getChildren()
{
return new self($this->current()->getChildren());
return new self($this->current()->all());
}
public function hasChildren()

View File

@ -466,6 +466,8 @@ class Request
*/
public static function trustProxyData()
{
trigger_error('trustProxyData() is deprecated since version 2.0 and will be removed in 2.3. Use setTrustedProxies() instead.', E_USER_DEPRECATED);
self::$trustProxy = true;
}
@ -1420,6 +1422,8 @@ class Request
*/
public function splitHttpAcceptHeader($header)
{
trigger_error('splitHttpAcceptHeader() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$headers = array();
foreach (AcceptHeader::fromString($header)->all() as $item) {
$key = $item->getValue();

View File

@ -259,6 +259,8 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
*/
public function getFlashes()
{
trigger_error('getFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);
$all = $this->getBag($this->flashName)->all();
$return = array();
@ -282,6 +284,8 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
*/
public function setFlashes($values)
{
trigger_error('setFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);
foreach ($values as $name => $value) {
$this->getBag($this->flashName)->set($name, $value);
}
@ -297,6 +301,8 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
*/
public function getFlash($name, $default = null)
{
trigger_error('getFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);
$return = $this->getBag($this->flashName)->get($name);
return empty($return) ? $default : reset($return);
@ -310,6 +316,8 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
*/
public function setFlash($name, $value)
{
trigger_error('setFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);
$this->getBag($this->flashName)->set($name, $value);
}
@ -322,6 +330,8 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
*/
public function hasFlash($name)
{
trigger_error('hasFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);
return $this->getBag($this->flashName)->has($name);
}
@ -332,6 +342,8 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
*/
public function removeFlash($name)
{
trigger_error('removeFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);
$this->getBag($this->flashName)->get($name);
}
@ -342,6 +354,8 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
*/
public function clearFlashes()
{
trigger_error('clearFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);
return $this->getBag($this->flashName)->clear();
}
}

View File

@ -17,6 +17,15 @@ use Symfony\Component\HttpFoundation\Request;
class RequestTest extends \PHPUnit_Framework_TestCase
{
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
/**
* @covers Symfony\Component\HttpFoundation\Request::__construct
*/
@ -713,7 +722,9 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$request->initialize(array(), array(), array(), array(), array(), $server);
if ($proxy) {
set_error_handler(array($this, "deprecationErrorHandler"));
$this->startTrustingProxyData();
restore_error_handler();
}
$this->assertEquals($expected, $request->getClientIp($proxy));
@ -830,6 +841,8 @@ class RequestTest extends \PHPUnit_Framework_TestCase
public function testOverrideGlobals()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$request = new Request();
$request->initialize(array('foo' => 'bar'));
@ -860,6 +873,8 @@ class RequestTest extends \PHPUnit_Framework_TestCase
// restore initial $_SERVER array
$_SERVER = $server;
restore_error_handler();
}
public function testGetScriptName()
@ -1107,7 +1122,9 @@ class RequestTest extends \PHPUnit_Framework_TestCase
{
$request = new Request();
set_error_handler(array($this, "deprecationErrorHandler"));
$this->assertEquals($expected, $request->splitHttpAcceptHeader($acceptHeader));
restore_error_handler();
}
public function splitHttpAcceptHeaderData()
@ -1275,11 +1292,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($request->isSecure());
// trusted proxy via deprecated trustProxyData()
set_error_handler(array($this, "deprecationErrorHandler"));
Request::trustProxyData();
$this->assertEquals('2.2.2.2', $request->getClientIp());
$this->assertEquals('real.example.com', $request->getHost());
$this->assertEquals(443, $request->getPort());
$this->assertTrue($request->isSecure());
restore_error_handler();
// disabling proxy trusting
Request::setTrustedProxies(array());

View File

@ -47,6 +47,15 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$this->session = null;
}
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
public function testStart()
{
$this->assertEquals('', $this->session->getId());
@ -193,6 +202,8 @@ class SessionTest extends \PHPUnit_Framework_TestCase
public function testGetSetFlashes()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$array = array('notice' => 'hello', 'error' => 'none');
$this->assertEquals(array(), $this->session->getFlashes());
$this->session->setFlashes($array);
@ -203,10 +214,14 @@ class SessionTest extends \PHPUnit_Framework_TestCase
// test that BC works by only retrieving the first added.
$this->session->getFlashBag()->add('notice', 'foo2');
$this->assertEquals(array('notice' => 'foo'), $this->session->getFlashes());
restore_error_handler();
}
public function testGetFlashesWithArray()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$array = array('notice' => 'hello', 'error' => 'none');
$this->assertEquals(array(), $this->session->getFlashes());
$this->session->setFlash('foo', $array);
@ -218,10 +233,14 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$this->session->setFlash('foo', $array);
$this->assertEquals(array('foo' => 'hello'), $this->session->getFlashes());
$this->assertEquals(array(), $this->session->getFlashes());
restore_error_handler();
}
public function testGetSetFlash()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->assertNull($this->session->getFlash('notice'));
$this->assertEquals('default', $this->session->getFlash('notice', 'default'));
$this->session->getFlashBag()->add('notice', 'foo');
@ -230,27 +249,39 @@ class SessionTest extends \PHPUnit_Framework_TestCase
// test that BC works by only retrieving the first added.
$this->assertEquals('foo', $this->session->getFlash('notice'));
$this->assertNull($this->session->getFlash('notice'));
restore_error_handler();
}
public function testHasFlash()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->assertFalse($this->session->hasFlash('notice'));
$this->session->setFlash('notice', 'foo');
$this->assertTrue($this->session->hasFlash('notice'));
restore_error_handler();
}
public function testRemoveFlash()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->session->setFlash('notice', 'foo');
$this->session->setFlash('error', 'bar');
$this->assertTrue($this->session->hasFlash('notice'));
$this->session->removeFlash('error');
$this->assertTrue($this->session->hasFlash('notice'));
$this->assertFalse($this->session->hasFlash('error'));
restore_error_handler();
}
public function testClearFlashes()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->assertFalse($this->session->hasFlash('notice'));
$this->assertFalse($this->session->hasFlash('error'));
$this->session->setFlash('notice', 'foo');
@ -260,6 +291,8 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$this->session->clearFlashes();
$this->assertFalse($this->session->hasFlash('notice'));
$this->assertFalse($this->session->hasFlash('error'));
restore_error_handler();
}
/**

View File

@ -58,6 +58,8 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
public function getMessageTemplate()
{
trigger_error('getMessageTemplate() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->messageTemplate;
}
@ -68,6 +70,8 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
public function getMessageParameters()
{
trigger_error('getMessageParameters() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->messageParameters;
}
@ -78,6 +82,8 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
protected function setMessage($template, array $parameters = array())
{
trigger_error('setMessage() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
$this->messageTemplate = $template;
$this->messageParameters = $parameters;
@ -107,5 +113,6 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
protected function isValid($value, Constraint $constraint)
{
trigger_error('isValid() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
}

View File

@ -26,6 +26,13 @@ class Max extends Constraint
public $invalidMessage = 'This value should be a valid number.';
public $limit;
public function __construct($options = null)
{
trigger_error('Max is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
parent::__construct($options);
}
/**
* {@inheritDoc}
*/

View File

@ -26,6 +26,13 @@ class MaxLength extends Constraint
public $limit;
public $charset = 'UTF-8';
public function __construct($options = null)
{
trigger_error('MaxLength is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
parent::__construct($options);
}
/**
* {@inheritDoc}
*/

View File

@ -24,6 +24,11 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
*/
class MaxLengthValidator extends ConstraintValidator
{
public function __construct($options = null)
{
trigger_error('MaxLengthValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* {@inheritDoc}
*/

View File

@ -23,6 +23,11 @@ use Symfony\Component\Validator\ConstraintValidator;
*/
class MaxValidator extends ConstraintValidator
{
public function __construct($options = null)
{
trigger_error('MaxValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* {@inheritDoc}
*/

View File

@ -26,6 +26,13 @@ class Min extends Constraint
public $invalidMessage = 'This value should be a valid number.';
public $limit;
public function __construct($options = null)
{
trigger_error('Min is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
parent::__construct($options);
}
/**
* {@inheritDoc}
*/

View File

@ -26,6 +26,13 @@ class MinLength extends Constraint
public $limit;
public $charset = 'UTF-8';
public function __construct($options = null)
{
trigger_error('MinLength is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
parent::__construct($options);
}
/**
* {@inheritDoc}
*/

View File

@ -24,6 +24,11 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
*/
class MinLengthValidator extends ConstraintValidator
{
public function __construct($options = null)
{
trigger_error('MinLengthValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* {@inheritDoc}
*/

View File

@ -23,6 +23,11 @@ use Symfony\Component\Validator\ConstraintValidator;
*/
class MinValidator extends ConstraintValidator
{
public function __construct($options = null)
{
trigger_error('MinValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
* Checks if the passed value is valid.
*

View File

@ -100,6 +100,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function addViolationAtPath($propertyPath, $message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null)
{
trigger_error('addViolationAtPath() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$this->globalContext->getViolations()->add(new ConstraintViolation(
$message,
$params,
@ -124,10 +126,12 @@ class ExecutionContext implements ExecutionContextInterface
* @param integer|null $code The violation code.
*
* @deprecated Deprecated since version 2.2, to be removed in 2.3. Use the
* method {@link atViolationAt} instead.
* method {@link addViolationAt} instead.
*/
public function addViolationAtSubPath($subPath, $message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null)
{
trigger_error('addViolationAtSubPath() is deprecated since version 2.2 and will be removed in 2.3. Use addViolationAt() instead.', E_USER_DEPRECATED);
if (func_num_args() >= 4) {
$this->addViolationAt($subPath, $message, $params, $invalidValue, $pluralization, $code);
} else {
@ -288,6 +292,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getCurrentClass()
{
trigger_error('getCurrentClass() is deprecated since version 2.2 and will be removed in 2.3. Use getClassName() instead', E_USER_DEPRECATED);
return $this->getClassName();
}
@ -304,6 +310,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getCurrentProperty()
{
trigger_error('getCurrentProperty() is deprecated since version 2.2 and will be removed in 2.3. Use getClassName() instead', E_USER_DEPRECATED);
return $this->getPropertyName();
}
@ -319,6 +327,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getCurrentValue()
{
trigger_error('getCurrentValue() is deprecated since version 2.2 and will be removed in 2.3. Use getValue() instead', E_USER_DEPRECATED);
return $this->value;
}
@ -332,6 +342,8 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getGraphWalker()
{
trigger_error('getGraphWalker() is deprecated since version 2.2 and will be removed in 2.3. Use validate() and validateValue() instead', E_USER_DEPRECATED);
return $this->globalContext->getVisitor()->getGraphWalker();
}

View File

@ -55,6 +55,8 @@ class GraphWalker
*/
public function __construct(ValidationVisitor $visitor, MetadataFactoryInterface $metadataFactory, array &$validatedObjects = array())
{
trigger_error('GraphWalker is deprecated since version 2.2 and will be removed in 2.3. This class has been replaced by ValidationVisitorInterface and MetadataInterface.', E_USER_DEPRECATED);
$this->visitor = $visitor;
$this->metadataFactory = $metadataFactory;
$this->validatedObjects = &$validatedObjects;
@ -67,6 +69,8 @@ class GraphWalker
*/
public function getViolations()
{
trigger_error('getViolations() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->visitor->getViolations();
}
@ -83,6 +87,8 @@ class GraphWalker
*/
public function walkObject(ClassMetadata $metadata, $object, $group, $propertyPath)
{
trigger_error('walkObject() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$hash = spl_object_hash($object);
// Exit, if the object is already validated for the current group
@ -118,6 +124,8 @@ class GraphWalker
*/
public function walkProperty(ClassMetadata $metadata, $property, $object, $group, $propertyPath, $propagatedGroup = null)
{
trigger_error('walkProperty() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
if (!is_object($object)) {
throw new UnexpectedTypeException($object, 'object');
}
@ -140,6 +148,8 @@ class GraphWalker
*/
public function walkPropertyValue(ClassMetadata $metadata, $property, $value, $group, $propertyPath)
{
trigger_error('walkPropertyValue() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
foreach ($metadata->getMemberMetadatas($property) as $member) {
$member->accept($this->visitor, $value, $group, $propertyPath);
}
@ -163,6 +173,8 @@ class GraphWalker
*/
public function walkReference($value, $group, $propertyPath, $traverse, $deep = false)
{
trigger_error('walkReference() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$this->visitor->validate($value, $group, $propertyPath, $traverse, $deep);
}
@ -180,6 +192,8 @@ class GraphWalker
*/
public function walkConstraint(Constraint $constraint, $value, $group, $propertyPath, $currentClass = null, $currentProperty = null)
{
trigger_error('walkConstraint() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$metadata = null;
// BC code to make getCurrentClass() and getCurrentProperty() work when

View File

@ -118,6 +118,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface, MetadataFac
*/
public function getClassMetadata($class)
{
trigger_error('getClassMetadata() is deprecated since version 2.2 and will be removed in 2.3. Use getMetadataFor() instead.', E_USER_DEPRECATED);
return $this->getMetadataFor($class);
}
}

View File

@ -194,6 +194,8 @@ abstract class MemberMetadata extends ElementMetadata implements PropertyMetadat
*/
public function getValue($object)
{
trigger_error('getValue() is deprecated since version 2.2 and will be removed in 2.3. Use getPropertyValue() instead.', E_USER_DEPRECATED);
return $this->getPropertyValue($object);
}

View File

@ -25,9 +25,20 @@ class ConstraintValidatorTest_Validator extends ConstraintValidator
$this->params = $params;
}
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
public function validate($value, Constraint $constraint)
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->setMessage($this->message, $this->params);
restore_error_handler();
}
}

View File

@ -48,12 +48,23 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase
$this->context = null;
}
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
public function testNullIsValid()
{
$this->context->expects($this->never())
->method('addViolation');
set_error_handler(array($this, "deprecationErrorHandler"));
$this->validator->validate(null, new All(new Min(4)));
restore_error_handler();
}
/**
@ -61,7 +72,9 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase
*/
public function testThrowsExceptionIfNotTraversable()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->validator->validate('foo.barbar', new All(new Min(4)));
restore_error_handler();
}
/**
@ -69,7 +82,9 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase
*/
public function testWalkSingleConstraint($array)
{
set_error_handler(array($this, "deprecationErrorHandler"));
$constraint = new Min(4);
restore_error_handler();
$i = 0;
@ -90,8 +105,10 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase
*/
public function testWalkMultipleConstraints($array)
{
set_error_handler(array($this, "deprecationErrorHandler"));
$constraint1 = new Min(4);
$constraint2 = new Max(6);
restore_error_handler();
$constraints = array($constraint1, $constraint2);
$i = 0;

View File

@ -50,20 +50,35 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
$this->validator = null;
}
public function deprecationErrorHandler($errorNumber, $message, $file, $line, $context)
{
if ($errorNumber & E_USER_DEPRECATED) {
return true;
}
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}
abstract protected function prepareTestData(array $contents);
public function testNullIsValid()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->context->expects($this->never())
->method('addViolationAtSubPath');
$this->validator->validate(null, new Collection(array('fields' => array(
'foo' => new Min(4),
))));
restore_error_handler();
}
public function testFieldsAsDefaultOption()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$data = $this->prepareTestData(array('foo' => 'foobar'));
$this->context->expects($this->never())
@ -72,6 +87,8 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
$this->validator->validate($data, new Collection(array(
'foo' => new Min(4),
)));
restore_error_handler();
}
/**
@ -79,14 +96,20 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
*/
public function testThrowsExceptionIfNotTraversable()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->validator->validate('foobar', new Collection(array('fields' => array(
'foo' => new Min(4),
))));
restore_error_handler();
}
public function testWalkSingleConstraint()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$constraint = new Min(4);
restore_error_handler();
$array = array(
'foo' => 3,
@ -115,10 +138,12 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
public function testWalkMultipleConstraints()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$constraints = array(
new Min(4),
new NotNull(),
);
restore_error_handler();
$array = array(
'foo' => 3,
@ -149,6 +174,8 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
public function testExtraFieldsDisallowed()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$data = $this->prepareTestData(array(
'foo' => 5,
'baz' => 6,
@ -166,11 +193,15 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
),
'extraFieldsMessage' => 'myMessage',
)));
restore_error_handler();
}
// bug fix
public function testNullNotConsideredExtraField()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$data = $this->prepareTestData(array(
'foo' => null,
));
@ -185,10 +216,14 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
->method('addViolationAtSubPath');
$this->validator->validate($data, $constraint);
restore_error_handler();
}
public function testExtraFieldsAllowed()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$data = $this->prepareTestData(array(
'foo' => 5,
'bar' => 6,
@ -205,10 +240,14 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
->method('addViolationAtSubPath');
$this->validator->validate($data, $constraint);
restore_error_handler();
}
public function testMissingFieldsDisallowed()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$data = $this->prepareTestData(array());
$constraint = new Collection(array(
@ -225,10 +264,14 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
));
$this->validator->validate($data, $constraint);
restore_error_handler();
}
public function testMissingFieldsAllowed()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$data = $this->prepareTestData(array());
$constraint = new Collection(array(
@ -242,6 +285,8 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
->method('addViolationAtSubPath');
$this->validator->validate($data, $constraint);
restore_error_handler();
}
public function testOptionalFieldPresent()
@ -272,6 +317,8 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
public function testOptionalFieldSingleConstraint()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$array = array(
'foo' => 5,
);
@ -290,10 +337,14 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
$this->validator->validate($data, new Collection(array(
'foo' => new Optional($constraint),
)));
restore_error_handler();
}
public function testOptionalFieldMultipleConstraints()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$array = array(
'foo' => 5,
);
@ -317,6 +368,8 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
$this->validator->validate($data, new Collection(array(
'foo' => new Optional($constraints),
)));
restore_error_handler();
}
public function testRequiredFieldPresent()
@ -353,6 +406,8 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
public function testRequiredFieldSingleConstraint()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$array = array(
'foo' => 5,
);
@ -371,10 +426,14 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
$this->validator->validate($data, new Collection(array(
'foo' => new Required($constraint),
)));
restore_error_handler();
}
public function testRequiredFieldMultipleConstraints()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$array = array(
'foo' => 5,
);
@ -398,10 +457,14 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
$this->validator->validate($array, new Collection(array(
'foo' => new Required($constraints),
)));
restore_error_handler();
}
public function testObjectShouldBeLeftUnchanged()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$value = new \ArrayObject(array(
'foo' => 3
));
@ -415,5 +478,7 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(
'foo' => 3
), (array) $value);
restore_error_handler();
}
}

View File

@ -158,6 +158,8 @@ class ValidationVisitor implements ValidationVisitorInterface, GlobalExecutionCo
*/
public function getGraphWalker()
{
trigger_error('getGraphWalker() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
if (null === $this->graphWalker) {
$this->graphWalker = new GraphWalker($this, $this->metadataFactory, $this->validatedObjects);
}

View File

@ -49,6 +49,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function setClassMetadataFactory(ClassMetadataFactoryInterface $classMetadataFactory)
{
trigger_error('setClassMetadataFactory() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
if ($classMetadataFactory instanceof MetadataFactoryInterface) {
$this->metadataFactory = $classMetadataFactory;
} else {
@ -68,6 +70,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterface $constraintValidatorFactory)
{
trigger_error('setConstraintValidatorFactory() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$this->constraintValidatorFactory = $constraintValidatorFactory;
return $this;
@ -81,6 +85,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function getValidator()
{
trigger_error('getValidator() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidator() instead.', E_USER_DEPRECATED);
return new Validator(
$this->metadataFactory,
$this->constraintValidatorFactory
@ -96,6 +102,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function getClassMetadataFactory()
{
trigger_error('getClassMetadataFactory() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->classMetadataFactory;
}
@ -108,6 +116,8 @@ class ValidatorContext implements ValidatorContextInterface
*/
public function getConstraintValidatorFactory()
{
trigger_error('getConstraintValidatorFactory() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
return $this->constraintValidatorFactory;
}
}

View File

@ -109,6 +109,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public static function buildDefault(array $mappingFiles = array(), $annotations = false, $staticMethod = null)
{
trigger_error('buildDefault() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$xmlMappingFiles = array();
$yamlMappingFiles = array();
$loaders = array();
@ -170,6 +172,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public function __construct(ValidatorContextInterface $defaultContext = null)
{
trigger_error('ValidatorFactory is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$this->defaultContext = null === $defaultContext ? new ValidatorContext() : $defaultContext;
}
@ -186,6 +190,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public function setClassMetadataFactory(ClassMetadataFactoryInterface $metadataFactory)
{
trigger_error('setClassMetadataFactory() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$context = clone $this->defaultContext;
return $context->setClassMetadataFactory($metadataFactory);
@ -204,6 +210,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterface $validatorFactory)
{
trigger_error('setConstraintValidatorFactory() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidatorBuilder() instead.', E_USER_DEPRECATED);
$context = clone $this->defaultContext;
return $context->setConstraintValidatorFactory($validatorFactory);
@ -219,6 +227,8 @@ class ValidatorFactory implements ValidatorContextInterface
*/
public function getValidator()
{
trigger_error('getValidator() is deprecated since version 2.1 and will be removed in 2.3. Use Validation::createValidator() instead.', E_USER_DEPRECATED);
return $this->defaultContext->getValidator();
}
}