22
33namespace EnumBundle \Tests \Form \Type ;
44
5+ use EnumBundle \Form \Type \EnumType ;
56use EnumBundle \Tests \Form \TestExtension ;
67use EnumBundle \Tests \GenderEnum ;
8+ use Symfony \Component \Form \AbstractType ;
79use Symfony \Component \Form \Test \TypeTestCase ;
810
911/**
@@ -26,18 +28,18 @@ protected function setUp()
2628 public function testEnumOptionIsRequired ()
2729 {
2830 $ this ->setExpectedException ('Symfony\Component\OptionsResolver\Exception\MissingOptionsException ' );
29- $ this ->factory -> create ( ' enum ' );
31+ $ this ->createForm ( );
3032 }
3133
3234 public function testEnumOptionIsInvalid ()
3335 {
3436 $ this ->setExpectedException ('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException ' );
35- $ this ->factory -> create ( ' enum ' , null , [ ' enum ' => ' state '] );
37+ $ this ->createForm ( ' state ' );
3638 }
3739
3840 public function testEnumOptionValid ()
3941 {
40- $ form = $ this ->factory -> create ( ' enum ' , null , [ ' enum ' => ' gender '] );
42+ $ form = $ this ->createForm ( ' gender ' );
4143
4244 $ this ->assertEquals (['male ' => 'Male ' , 'female ' => 'Female ' ], $ form ->getConfig ()->getOption ('choices ' ));
4345 }
@@ -48,4 +50,20 @@ protected function getExtensions()
4850 new TestExtension ($ this ->enumRegistry ->reveal ())
4951 ];
5052 }
53+
54+ private function createForm ($ enum = null )
55+ {
56+ $ options = [];
57+ if ($ enum ) {
58+ $ options ['enum ' ] = $ enum ;
59+ }
60+
61+ if (method_exists (AbstractType::class, 'getBlockPrefix ' )) {
62+ $ name = EnumType::class; //Symfony 3.x support
63+ } else {
64+ $ name = 'enum ' ; //Symfony 2.x support
65+ }
66+
67+ return $ this ->factory ->create ($ name , null , $ options );
68+ }
5169}
0 commit comments