浏览代码

use class names for types in 2.8 too

This should generate less deprecation notices.
Grégoire Paris 9 年之前
父节点
当前提交
724d22c1a9

+ 3 - 3
Form/Extension/Field/Type/FormTypeFieldExtension.php

@@ -206,9 +206,9 @@ class FormTypeFieldExtension extends AbstractTypeExtension
     public function getExtendedType()
     {
         return
-            method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions') ?
-            'form' :
-            'Symfony\Component\Form\Extension\Core\Type\FormType';
+            method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ?
+            'Symfony\Component\Form\Extension\Core\Type\FormType' :
+            'form';
     }
 
     /**

+ 3 - 3
Form/Type/CollectionType.php

@@ -27,9 +27,9 @@ class CollectionType extends AbstractType
     public function getParent()
     {
         return
-            method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions') ?
-            'collection' :
-            'Symfony\Component\Form\Extension\Core\Type\CollectionType';
+            method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ?
+            'Symfony\Component\Form\Extension\Core\Type\CollectionType' :
+            'collection';
     }
 
     /**

+ 13 - 6
Tests/Form/Extension/ChoiceTypeExtensionTest.php

@@ -19,11 +19,7 @@ class ChoiceTypeExtensionTest extends \PHPUnit_Framework_TestCase
 {
     protected function setup()
     {
-        if (method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions')) {
-            $this->factory = Forms::createFormFactoryBuilder()
-                  ->addTypeExtension(new ChoiceTypeExtension())
-                  ->getFormFactory();
-        } else {
+        if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
             $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
             $container->expects($this->any())->method('has')->will($this->returnValue(true));
             $container->expects($this->any())->method('get')
@@ -42,11 +38,22 @@ class ChoiceTypeExtensionTest extends \PHPUnit_Framework_TestCase
                 ),
             );
 
-            $dependency = new DependencyInjectionExtension($container, $typeServiceIds, $typeExtensionServiceIds, $guesserServiceIds, $mappingTypes, $extensionTypes);
+            $dependency = new DependencyInjectionExtension(
+                $container,
+                $typeServiceIds,
+                $typeExtensionServiceIds,
+                $guesserServiceIds,
+                $mappingTypes,
+                $extensionTypes
+            );
 
             $this->factory = Forms::createFormFactoryBuilder()
                 ->addExtension($dependency)
                 ->getFormFactory();
+        } else {
+            $this->factory = Forms::createFormFactoryBuilder()
+                  ->addTypeExtension(new ChoiceTypeExtension())
+                  ->getFormFactory();
         }
     }
 

+ 3 - 3
Tests/Form/Extension/Field/Type/FormTypeFieldExtensionTest.php

@@ -24,9 +24,9 @@ class FormTypeFieldExtensionTest extends \PHPUnit_Framework_TestCase
         $extension = new FormTypeFieldExtension(array(), array());
 
         $this->assertSame(
-            method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions') ?
-            'form' :
-            'Symfony\Component\Form\Extension\Core\Type\FormType',
+            method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ?
+            'Symfony\Component\Form\Extension\Core\Type\FormType' :
+            'form',
             $extension->getExtendedType()
         );
     }

+ 3 - 3
Tests/Form/Widget/FilterChoiceWidgetTest.php

@@ -76,9 +76,9 @@ class FilterChoiceWidgetTest extends BaseWidgetTest
     protected function getChoiceClass()
     {
         return
-            method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions') ?
-            'choice' :
-            'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
+            method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ?
+            'Symfony\Component\Form\Extension\Core\Type\ChoiceType' :
+            'choice';
     }
 
     /**

+ 3 - 3
Tests/Form/Widget/FormChoiceWidgetTest.php

@@ -128,9 +128,9 @@ class FormChoiceWidgetTest extends BaseWidgetTest
     protected function getChoiceClass()
     {
         return
-            method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions') ?
-            'choice' :
-            'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
+            method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ?
+            'Symfony\Component\Form\Extension\Core\Type\ChoiceType' :
+            'choice';
     }
 
     /**

+ 4 - 4
Tests/Form/Widget/FormSonataNativeCollectionWidgetTest.php

@@ -56,7 +56,7 @@ class FormSonataNativeCollectionWidgetTest extends BaseWidgetTest
         $extensions = parent::getExtensions();
         $guesser = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
         $extension = new TestExtension($guesser);
-        if (method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions')) {
+        if (!method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
             $extension->addType(new CollectionType());
         }
 
@@ -71,8 +71,8 @@ class FormSonataNativeCollectionWidgetTest extends BaseWidgetTest
     protected function getChoiceClass()
     {
         return
-            method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions') ?
-            'sonata_type_native_collection' :
-            'Sonata\AdminBundle\Form\Type\CollectionType';
+            method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ?
+            'Sonata\AdminBundle\Form\Type\CollectionType' :
+            'sonata_type_native_collection';
     }
 }