22
33namespace Linio \DynamicFormBundle \Tests \Form \FormFactoryTest ;
44
5+ use Linio \DynamicFormBundle \Exception \NonExistentFormException ;
56use Linio \DynamicFormBundle \Form \FormFactory ;
7+ use Linio \DynamicFormBundle \HelpMessageProvider ;
68use Prophecy \Prophecy \ObjectProphecy ;
79use Symfony \Component \Form \DataTransformerInterface ;
10+ use Symfony \Component \Form \Extension \Core \Type \FormType ;
11+ use Symfony \Component \Form \FormBuilder ;
12+ use Symfony \Component \Form \FormFactory as SymfonyFormFactory ;
813use Symfony \Component \Validator \Constraints \IsTrue ;
914
1015class FormFactoryTest extends \PHPUnit_Framework_TestCase
@@ -49,7 +54,7 @@ public function testIsCreatingASimpleForm()
4954 ],
5055 ];
5156
52- $ this ->formFactoryMock ->createNamedBuilder ('foo ' , ' form ' , ['foo_form_data ' ], ['foo_form_options ' ])
57+ $ this ->formFactoryMock ->createNamedBuilder ('foo ' , FormType::class , ['foo_form_data ' ], ['foo_form_options ' ])
5358 ->willReturn ($ this ->formBuilderMock ->reveal ());
5459
5560 $ this ->formBuilderMock ->create ('field1 ' , 'field1_type ' , ['field1_options ' ])
@@ -91,7 +96,7 @@ public function testIsCreatingFormWithValidators()
9196 ],
9297 ];
9398
94- $ this ->formFactoryMock ->createNamedBuilder ('foo ' , ' form ' , [], [])
99+ $ this ->formFactoryMock ->createNamedBuilder ('foo ' , FormType::class , [], [])
95100 ->willReturn ($ this ->formBuilderMock ->reveal ());
96101
97102 $ this ->formBuilderMock ->create ('field1 ' , 'field1_type ' , $ expectedFieldOptions )
@@ -113,15 +118,15 @@ public function testIsCreatingFormWithValidators()
113118
114119 public function testIsCreatingFormWithTransformers ()
115120 {
116- $ fieldOneMock = $ this ->prophesize (' Symfony\Component\Form\ FormBuilder' );
121+ $ fieldOneMock = $ this ->prophesize (FormBuilder::class );
117122
118123 $ formConfiguration = [
119124 'foo ' => [
120125 'field1 ' => [
121126 'enabled ' => true ,
122127 'type ' => 'field1_type ' ,
123128 'transformer ' => [
124- 'class ' => ' Linio\DynamicFormBundle\Tests\Form\FormFactoryTest\ MockTransformer' ,
129+ 'class ' => MockTransformer::class ,
125130 'calls ' => [
126131 ['setUserFormat ' , ['d/m/Y ' ]],
127132 ['setInputFormat ' , ['Y-m-d ' ]],
@@ -137,7 +142,7 @@ public function testIsCreatingFormWithTransformers()
137142
138143 $ expectedFieldOptions = [];
139144
140- $ this ->formFactoryMock ->createNamedBuilder ('foo ' , ' form ' , [], [])
145+ $ this ->formFactoryMock ->createNamedBuilder ('foo ' , FormType::class , [], [])
141146 ->willReturn ($ this ->formBuilderMock ->reveal ());
142147
143148 $ this ->formBuilderMock ->create ('field1 ' , 'field1_type ' , $ expectedFieldOptions )
@@ -175,13 +180,13 @@ public function testIsCreatingFormWithHelpMessages()
175180 ],
176181 ];
177182
178- $ helpMessageProviderMock = $ this ->prophesize (' Linio\DynamicFormBundle\ HelpMessageProvider' );
183+ $ helpMessageProviderMock = $ this ->prophesize (HelpMessageProvider::class );
179184
180185 $ helpMessageProviderMock ->getHelpMessage ('cms:message ' )
181186 ->shouldBeCalled ()
182187 ->willReturn ('message ' );
183188
184- $ this ->formFactoryMock ->createNamedBuilder ('foo ' , ' form ' , ['foo_form_data ' ], $ formConfiguration )
189+ $ this ->formFactoryMock ->createNamedBuilder ('foo ' , FormType::class , ['foo_form_data ' ], $ formConfiguration )
185190 ->shouldBeCalled ()
186191 ->willReturn ($ this ->formBuilderMock ->reveal ());
187192
@@ -251,9 +256,6 @@ public function testIsHandlingNullName()
251256 $ this ->assertEquals ($ configuration , $ actual );
252257 }
253258
254- /**
255- * @expectedException \Linio\DynamicFormBundle\Exception\NonExistentFormException
256- */
257259 public function testIsHandlingNotExistenFormException ()
258260 {
259261 $ configuration = [
@@ -271,6 +273,8 @@ public function testIsHandlingNotExistenFormException()
271273
272274 $ this ->formFactory ->setConfiguration ($ configuration );
273275
276+ $ this ->expectException (NonExistentFormException::class);
277+
274278 $ this ->formFactory ->getConfiguration ('bar ' );
275279 }
276280
@@ -303,8 +307,8 @@ public function testIsCreatingValidator()
303307
304308 public function setup ()
305309 {
306- $ this ->formBuilderMock = $ this ->prophesize (' Symfony\Component\Form\ FormBuilder' );
307- $ this ->formFactoryMock = $ this ->prophesize (' Symfony\Component\Form\FormFactory ' );
310+ $ this ->formBuilderMock = $ this ->prophesize (FormBuilder::class );
311+ $ this ->formFactoryMock = $ this ->prophesize (SymfonyFormFactory::class );
308312
309313 $ this ->formFactory = new FormFactory ();
310314 }
0 commit comments