99
1010class IntegerFieldTest extends TestCase
1111{
12+ public function setUp ()
13+ {
14+ $ this ->field = new IntegerField (["min_value " => 10 , "max_value " => 40 ]);
15+ }
16+
1217 public function testConstruct ()
1318 {
14- $ field = new IntegerField ();
15- $ this ->assertInstanceOf (NumberInput::class, $ field ->getWidget ());
19+ $ this ->assertInstanceOf (NumberInput::class, $ this ->field ->getWidget ());
1620 }
1721
1822 public function testConstructWithValidators ()
1923 {
20- $ args = array ("min_value " => 10 , "max_value " => 40 );
21- $ field = new IntegerField ($ args );
22- $ this ->assertAttributeEquals (10 , "min_value " , $ field );
23- $ this ->assertAttributeEquals (40 , "max_value " , $ field );
24+ $ this ->assertAttributeEquals (10 , "min_value " , $ this ->field );
25+ $ this ->assertAttributeEquals (40 , "max_value " , $ this ->field );
2426 }
2527
2628 public function testValidatorNoException ()
2729 {
28- $ args = array ("min_value " => 10 , "max_value " => 40 );
29- $ field = new IntegerField ($ args );
30- $ this ->assertEquals ($ field ->clean ("25 " ), 25 );
30+ $ this ->assertEquals ($ this ->field ->clean ("25 " ), 25 );
3131 }
3232
3333 /**
3434 * @expectedException PHPForm\Exceptions\ValidationError
3535 */
3636 public function testMinValidatorError ()
3737 {
38- $ args = array ("min_value " => 10 , "max_value " => 40 );
39- $ field = new IntegerField ($ args );
40- $ field ->clean ("1 " );
38+ $ this ->field ->clean ("1 " );
4139 }
4240
4341 /**
4442 * @expectedException PHPForm\Exceptions\ValidationError
4543 */
4644 public function testMaxValidatorError ()
4745 {
48- $ args = array ("min_value " => 10 , "max_value " => 20 );
49- $ field = new IntegerField ($ args );
50- $ field ->clean ("100 " );
46+ $ this ->field ->clean ("100 " );
5147 }
5248
5349 /**
@@ -56,16 +52,12 @@ public function testMaxValidatorError()
5652 */
5753 public function testInvalidValue ()
5854 {
59- $ field = new IntegerField ();
60- $ field ->clean ("aa " );
55+ $ this ->field ->clean ("aa " );
6156 }
6257
6358 public function testWidgetAttrs ()
6459 {
65- $ args = array ("min_value " => 10 , "max_value " => 40 );
66- $ field = new IntegerField ($ args );
67-
6860 $ expected = array ("min " => 10 , "max " => 40 );
69- $ this ->assertEquals ($ field ->widgetAttrs (null ), $ expected );
61+ $ this ->assertEquals ($ this -> field ->widgetAttrs (null ), $ expected );
7062 }
7163}
0 commit comments