Skip to content

[Form] Deprecate VersionAwareTest trait #57839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-7.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Read more about this in the [Symfony documentation](https://symfony.com/doc/7.2/

If you're upgrading from a version below 7.1, follow the [7.1 upgrade guide](UPGRADE-7.1.md) first.

Form
----

* Deprecate the `VersionAwareTest` trait, use feature detection instead

FrameworkBundle
---------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2869,8 +2869,6 @@ public function testColor()

public function testWeekSingleText()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01', [
'input' => 'string',
'widget' => 'single_text',
Expand All @@ -2889,8 +2887,6 @@ public function testWeekSingleText()

public function testWeekSingleTextNoHtml5()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01', [
'input' => 'string',
'widget' => 'single_text',
Expand All @@ -2910,8 +2906,6 @@ public function testWeekSingleTextNoHtml5()

public function testWeekChoices()
{
$this->requiresFeatureSet(404);

$data = ['year' => (int) date('Y'), 'week' => 1];

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', $data, [
Expand All @@ -2938,8 +2932,6 @@ public function testWeekChoices()

public function testWeekText()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '2000-W01', [
'input' => 'string',
'widget' => 'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1842,8 +1842,6 @@ public function testTimezoneWithPlaceholder()

public function testWeekChoices()
{
$this->requiresFeatureSet(404);

$data = ['year' => (int) date('Y'), 'week' => 1];

$form = $this->factory->createNamed('name', WeekType::class, $data, [
Expand Down
37 changes: 0 additions & 37 deletions src/Symfony/Bridge/Twig/Tests/Extension/AbstractLayoutTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\VersionAwareTest;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

abstract class AbstractLayoutTestCase extends FormLayoutTestCase
{
use VersionAwareTest;

protected MockObject&CsrfTokenManagerInterface $csrfTokenManager;
protected array $testableFeatures = [];

Expand Down Expand Up @@ -676,8 +673,6 @@ public function testSingleExpandedChoiceAttributesWithMainAttributes()

public function testSingleChoiceWithPreferred()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
'preferred_choices' => ['&b'],
Expand All @@ -702,8 +697,6 @@ public function testSingleChoiceWithPreferred()

public function testSingleChoiceWithPreferredAndNoSeparator()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
'preferred_choices' => ['&b'],
Expand All @@ -727,8 +720,6 @@ public function testSingleChoiceWithPreferredAndNoSeparator()

public function testSingleChoiceWithPreferredAndBlankSeparator()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
'preferred_choices' => ['&b'],
Expand All @@ -753,8 +744,6 @@ public function testSingleChoiceWithPreferredAndBlankSeparator()

public function testChoiceWithOnlyPreferred()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
'preferred_choices' => ['&a', '&b'],
Expand Down Expand Up @@ -1818,8 +1807,6 @@ public function testNumber()

public function testRenderNumberWithHtml5NumberType()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\NumberType', 1234.56, [
'html5' => true,
]);
Expand All @@ -1836,8 +1823,6 @@ public function testRenderNumberWithHtml5NumberType()

public function testRenderNumberWithHtml5NumberTypeAndStepAttribute()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\NumberType', 1234.56, [
'html5' => true,
'attr' => ['step' => '0.1'],
Expand Down Expand Up @@ -1912,8 +1897,6 @@ public function testPercent()

public function testPercentNoSymbol()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false, 'rounding_mode' => \NumberFormatter::ROUND_CEILING]);
$this->assertWidgetMatchesXpath($form->createView(), [],
'/input
Expand All @@ -1927,8 +1910,6 @@ public function testPercentNoSymbol()

public function testPercentCustomSymbol()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '‱', 'rounding_mode' => \NumberFormatter::ROUND_CEILING]);
$this->assertWidgetMatchesXpath($form->createView(), [],
'/input
Expand Down Expand Up @@ -2606,8 +2587,6 @@ public function testColor()

public function testLabelWithTranslationParameters()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
'label_translation_parameters' => [
Expand All @@ -2625,8 +2604,6 @@ public function testLabelWithTranslationParameters()

public function testHelpWithTranslationParameters()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'for company %company%',
'help_translation_parameters' => [
Expand Down Expand Up @@ -2697,8 +2674,6 @@ public function trans(TranslatorInterface $translator, ?string $locale = null):

public function testAttributesWithTranslationParameters()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'attr' => [
'title' => 'Message to %company%',
Expand All @@ -2720,8 +2695,6 @@ public function testAttributesWithTranslationParameters()

public function testButtonWithTranslationParameters()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamedBuilder('myform')
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
'label' => 'Submit to %company%',
Expand All @@ -2745,8 +2718,6 @@ public function testButtonWithTranslationParameters()
*/
public function testSubmitFormNoValidate(bool $validate)
{
$this->requiresFeatureSet(404);

$form = $this->factory->create(SubmitType::class, null, [
'validate' => $validate,
]);
Expand Down Expand Up @@ -2776,8 +2747,6 @@ public static function submitFormNoValidateProvider()

public function testWeekSingleText()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01', [
'input' => 'string',
'widget' => 'single_text',
Expand All @@ -2795,8 +2764,6 @@ public function testWeekSingleText()

public function testWeekSingleTextNoHtml5()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01', [
'input' => 'string',
'widget' => 'single_text',
Expand All @@ -2815,8 +2782,6 @@ public function testWeekSingleTextNoHtml5()

public function testWeekChoices()
{
$this->requiresFeatureSet(404);

$data = ['year' => (int) date('Y'), 'week' => 1];

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', $data, [
Expand All @@ -2841,8 +2806,6 @@ public function testWeekChoices()

public function testWeekText()
{
$this->requiresFeatureSet(404);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '2000-W01', [
'input' => 'string',
'widget' => 'text',
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.2
---

* Deprecate the `VersionAwareTest` trait, use feature detection instead

7.1
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ public function testDefaultTranslationDomain()

public function testPassLabelTranslationParametersToView()
{
$this->requiresFeatureSet(403);

$view = $this->factory->create($this->getTestedType(), null, array_merge($this->getTestOptions(), [
'label_translation_parameters' => ['%param%' => 'value'],
]))
Expand All @@ -126,8 +124,6 @@ public function testPassLabelTranslationParametersToView()

public function testPassAttrTranslationParametersToView()
{
$this->requiresFeatureSet(403);

$view = $this->factory->create($this->getTestedType(), null, array_merge($this->getTestOptions(), [
'attr_translation_parameters' => ['%param%' => 'value'],
]))
Expand All @@ -138,8 +134,6 @@ public function testPassAttrTranslationParametersToView()

public function testInheritLabelTranslationParametersFromParent()
{
$this->requiresFeatureSet(403);

$view = $this->factory
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, [
'label_translation_parameters' => ['%param%' => 'value'],
Expand All @@ -153,8 +147,6 @@ public function testInheritLabelTranslationParametersFromParent()

public function testInheritAttrTranslationParametersFromParent()
{
$this->requiresFeatureSet(403);

$view = $this->factory
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, [
'attr_translation_parameters' => ['%param%' => 'value'],
Expand All @@ -168,8 +160,6 @@ public function testInheritAttrTranslationParametersFromParent()

public function testPreferOwnLabelTranslationParameters()
{
$this->requiresFeatureSet(403);

$view = $this->factory
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, [
'label_translation_parameters' => ['%parent_param%' => 'parent_value', '%override_param%' => 'parent_override_value'],
Expand All @@ -185,8 +175,6 @@ public function testPreferOwnLabelTranslationParameters()

public function testPreferOwnAttrTranslationParameters()
{
$this->requiresFeatureSet(403);

$view = $this->factory
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, [
'attr_translation_parameters' => ['%parent_param%' => 'parent_value', '%override_param%' => 'parent_override_value'],
Expand All @@ -202,8 +190,6 @@ public function testPreferOwnAttrTranslationParameters()

public function testDefaultLabelTranslationParameters()
{
$this->requiresFeatureSet(403);

$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
->add('child', $this->getTestedType(), $this->getTestOptions())
->getForm()
Expand All @@ -214,8 +200,6 @@ public function testDefaultLabelTranslationParameters()

public function testDefaultAttrTranslationParameters()
{
$this->requiresFeatureSet(403);

$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
->add('child', $this->getTestedType(), $this->getTestOptions())
->getForm()
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Form/Tests/VersionAwareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@

namespace Symfony\Component\Form\Tests;

/**
* @deprecated since Symfony 7.2, use feature detection instead.
*/
trait VersionAwareTest
{
protected static int $supportedFeatureSetVersion = 404;

/**
* @deprecated since Symfony 7.2, use feature detection instead.
*/
protected function requiresFeatureSet(int $requiredFeatureSetVersion)
{
trigger_deprecation('symfony/form', '7.2', 'The "%s" trait is deprecated, use feature detection instead.', VersionAwareTest::class);

if ($requiredFeatureSetVersion > static::$supportedFeatureSetVersion) {
$this->markTestSkipped(\sprintf('Test requires features from symfony/form %.2f but only version %.2f is supported.', $requiredFeatureSetVersion / 100, static::$supportedFeatureSetVersion / 100));
}
Expand Down