16
16
use Symfony \Component \Form \FormEvents ;
17
17
use Symfony \Component \Form \Util \PropertyPath ;
18
18
use Symfony \Component \Form \FormConfigBuilder ;
19
- use Symfony \Component \Form \FormView ;
20
19
use Symfony \Component \Form \FormError ;
21
20
use Symfony \Component \Form \Exception \TransformationFailedException ;
22
21
use Symfony \Component \EventDispatcher \EventDispatcher ;
23
22
use Symfony \Component \Form \Tests \Fixtures \FixedDataTransformer ;
24
23
use Symfony \Component \Form \Tests \Fixtures \FixedFilterListener ;
25
24
25
+ class SimpleFormTest_Countable implements \Countable
26
+ {
27
+ private $ count ;
28
+
29
+ public function __construct ($ count )
30
+ {
31
+ $ this ->count = $ count ;
32
+ }
33
+
34
+ public function count ()
35
+ {
36
+ return $ this ->count ;
37
+ }
38
+ }
39
+
40
+ class SimpleFormTest_Traversable implements \IteratorAggregate
41
+ {
42
+ private $ iterator ;
43
+
44
+ public function __construct ($ count )
45
+ {
46
+ $ this ->iterator = new \ArrayIterator ($ count > 0 ? array_fill (0 , $ count , 'Foo ' ) : array ());
47
+ }
48
+
49
+ public function getIterator ()
50
+ {
51
+ return $ this ->iterator ;
52
+ }
53
+ }
54
+
26
55
class SimpleFormTest extends AbstractFormTest
27
56
{
28
57
public function testDataIsInitializedToConfiguredValue ()
@@ -68,7 +97,7 @@ public function testDataIsInitializedFromBind()
68
97
}
69
98
70
99
/**
71
- * @expectedException Symfony\Component\Form\Exception\AlreadyBoundException
100
+ * @expectedException \ Symfony\Component\Form\Exception\AlreadyBoundException
72
101
*/
73
102
public function testBindThrowsExceptionIfAlreadyBound ()
74
103
{
@@ -173,6 +202,42 @@ public function testEmptyIfEmptyArray()
173
202
$ this ->assertTrue ($ this ->form ->isEmpty ());
174
203
}
175
204
205
+ public function testEmptyIfEmptyCountable ()
206
+ {
207
+ $ this ->form = new Form (new FormConfigBuilder ('name ' , __NAMESPACE__ . '\SimpleFormTest_Countable ' , $ this ->dispatcher ));
208
+
209
+ $ this ->form ->setData (new SimpleFormTest_Countable (0 ));
210
+
211
+ $ this ->assertTrue ($ this ->form ->isEmpty ());
212
+ }
213
+
214
+ public function testNotEmptyIfFilledCountable ()
215
+ {
216
+ $ this ->form = new Form (new FormConfigBuilder ('name ' , __NAMESPACE__ . '\SimpleFormTest_Countable ' , $ this ->dispatcher ));
217
+
218
+ $ this ->form ->setData (new SimpleFormTest_Countable (1 ));
219
+
220
+ $ this ->assertFalse ($ this ->form ->isEmpty ());
221
+ }
222
+
223
+ public function testEmptyIfEmptyTraversable ()
224
+ {
225
+ $ this ->form = new Form (new FormConfigBuilder ('name ' , __NAMESPACE__ . '\SimpleFormTest_Traversable ' , $ this ->dispatcher ));
226
+
227
+ $ this ->form ->setData (new SimpleFormTest_Traversable (0 ));
228
+
229
+ $ this ->assertTrue ($ this ->form ->isEmpty ());
230
+ }
231
+
232
+ public function testNotEmptyIfFilledTraversable ()
233
+ {
234
+ $ this ->form = new Form (new FormConfigBuilder ('name ' , __NAMESPACE__ . '\SimpleFormTest_Traversable ' , $ this ->dispatcher ));
235
+
236
+ $ this ->form ->setData (new SimpleFormTest_Traversable (1 ));
237
+
238
+ $ this ->assertFalse ($ this ->form ->isEmpty ());
239
+ }
240
+
176
241
public function testEmptyIfNull ()
177
242
{
178
243
$ this ->form ->setData (null );
@@ -240,7 +305,7 @@ public function testHasNoErrors()
240
305
}
241
306
242
307
/**
243
- * @expectedException Symfony\Component\Form\Exception\AlreadyBoundException
308
+ * @expectedException \ Symfony\Component\Form\Exception\AlreadyBoundException
244
309
*/
245
310
public function testSetParentThrowsExceptionIfAlreadyBound ()
246
311
{
@@ -262,7 +327,7 @@ public function testNotBound()
262
327
}
263
328
264
329
/**
265
- * @expectedException Symfony\Component\Form\Exception\AlreadyBoundException
330
+ * @expectedException \ Symfony\Component\Form\Exception\AlreadyBoundException
266
331
*/
267
332
public function testSetDataThrowsExceptionIfAlreadyBound ()
268
333
{
@@ -674,7 +739,7 @@ public function testSetNullParentWorksWithEmptyName()
674
739
}
675
740
676
741
/**
677
- * @expectedException Symfony\Component\Form\Exception\FormException
742
+ * @expectedException \ Symfony\Component\Form\Exception\FormException
678
743
* @expectedExceptionMessage A form with an empty name cannot have a parent form.
679
744
*/
680
745
public function testFormCannotHaveEmptyNameNotInRootLevel ()
@@ -720,7 +785,7 @@ public function testGetPropertyPathDefaultsToIndexedNameIfParentDataClassIsNull(
720
785
}
721
786
722
787
/**
723
- * @expectedException Symfony\Component\Form\Exception\FormException
788
+ * @expectedException \ Symfony\Component\Form\Exception\FormException
724
789
*/
725
790
public function testViewDataMustNotBeObjectIfDataClassIsNull ()
726
791
{
@@ -750,7 +815,7 @@ public function testViewDataMayBeArrayAccessIfDataClassIsNull()
750
815
}
751
816
752
817
/**
753
- * @expectedException Symfony\Component\Form\Exception\FormException
818
+ * @expectedException \ Symfony\Component\Form\Exception\FormException
754
819
*/
755
820
public function testViewDataMustBeObjectIfDataClassIsSet ()
756
821
{
@@ -765,7 +830,7 @@ public function testViewDataMustBeObjectIfDataClassIsSet()
765
830
}
766
831
767
832
/**
768
- * @expectedException Symfony\Component\Form\Exception\FormException
833
+ * @expectedException \ Symfony\Component\Form\Exception\FormException
769
834
*/
770
835
public function testSetDataCannotInvokeItself ()
771
836
{
0 commit comments