瀏覽代碼

Fixed getExtendedType compatibility for symfony >= 2.8 (#4444)

* Fixed getExtendedType compatibility for symfony >= 2.8

* Updated unit tests for ChoiceTypeExtension

* Added NEXT_MAJOR comments

* Updated php comments that were added as phpDoc
Eduardo Conceição 8 年之前
父節點
當前提交
f703676485

+ 8 - 4
Form/Extension/ChoiceTypeExtension.php

@@ -56,12 +56,16 @@ class ChoiceTypeExtension extends AbstractTypeExtension
     }
 
     /**
-     * Returns the name of the type being extended.
-     *
-     * @return string The name of the type being extended
+     * {@inheritdoc}
      */
     public function getExtendedType()
     {
-        return 'choice';
+        /*
+         * NEXT_MAJOR: Remove when dropping Symfony <2.8 support. It should
+         * simply be return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
+         */
+        return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
+            ? 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'
+            : 'choice';
     }
 }

+ 8 - 4
Form/Extension/Field/Type/MopaCompatibilityTypeFieldExtension.php

@@ -58,12 +58,16 @@ class MopaCompatibilityTypeFieldExtension extends AbstractTypeExtension
     }
 
     /**
-     * Returns the name of the type being extended.
-     *
-     * @return string The name of the type being extended
+     * {@inheritdoc}
      */
     public function getExtendedType()
     {
-        return 'form';
+        /*
+         * NEXT_MAJOR: Remove when dropping Symfony <2.8 support. It should
+         * simply be return 'Symfony\Component\Form\Extension\Core\Type\FormType';
+         */
+        return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
+            ? 'Symfony\Component\Form\Extension\Core\Type\FormType'
+            : 'form';
     }
 }

+ 17 - 1
Tests/Form/Extension/ChoiceTypeExtensionTest.php

@@ -62,7 +62,23 @@ class ChoiceTypeExtensionTest extends PHPUnit_Framework_TestCase
     {
         $extension = new ChoiceTypeExtension();
 
-        $this->assertSame('choice', $extension->getExtendedType());
+        /*
+         * NEXT_MAJOR: Remove when dropping Symfony <2.8 support. It should
+         * simply be:
+         *
+         * $this->assertSame(
+         *     'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
+         *     $extension->getExtendedType()
+         * );
+         */
+        if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
+            $this->assertSame(
+                'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
+                $extension->getExtendedType()
+            );
+        } else {
+            $this->assertSame('choice', $extension->getExtendedType());
+        }
     }
 
     public function testDefaultOptionsWithSortable()