9
9
10
10
class IntegerFieldTest extends TestCase
11
11
{
12
+ public function setUp ()
13
+ {
14
+ $ this ->field = new IntegerField (["min_value " => 10 , "max_value " => 40 ]);
15
+ }
16
+
12
17
public function testConstruct ()
13
18
{
14
- $ field = new IntegerField ();
15
- $ this ->assertInstanceOf (NumberInput::class, $ field ->getWidget ());
19
+ $ this ->assertInstanceOf (NumberInput::class, $ this ->field ->getWidget ());
16
20
}
17
21
18
22
public function testConstructWithValidators ()
19
23
{
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 );
24
26
}
25
27
26
28
public function testValidatorNoException ()
27
29
{
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 );
31
31
}
32
32
33
33
/**
34
34
* @expectedException PHPForm\Exceptions\ValidationError
35
35
*/
36
36
public function testMinValidatorError ()
37
37
{
38
- $ args = array ("min_value " => 10 , "max_value " => 40 );
39
- $ field = new IntegerField ($ args );
40
- $ field ->clean ("1 " );
38
+ $ this ->field ->clean ("1 " );
41
39
}
42
40
43
41
/**
44
42
* @expectedException PHPForm\Exceptions\ValidationError
45
43
*/
46
44
public function testMaxValidatorError ()
47
45
{
48
- $ args = array ("min_value " => 10 , "max_value " => 20 );
49
- $ field = new IntegerField ($ args );
50
- $ field ->clean ("100 " );
46
+ $ this ->field ->clean ("100 " );
51
47
}
52
48
53
49
/**
@@ -56,16 +52,12 @@ public function testMaxValidatorError()
56
52
*/
57
53
public function testInvalidValue ()
58
54
{
59
- $ field = new IntegerField ();
60
- $ field ->clean ("aa " );
55
+ $ this ->field ->clean ("aa " );
61
56
}
62
57
63
58
public function testWidgetAttrs ()
64
59
{
65
- $ args = array ("min_value " => 10 , "max_value " => 40 );
66
- $ field = new IntegerField ($ args );
67
-
68
60
$ expected = array ("min " => 10 , "max " => 40 );
69
- $ this ->assertEquals ($ field ->widgetAttrs (null ), $ expected );
61
+ $ this ->assertEquals ($ this -> field ->widgetAttrs (null ), $ expected );
70
62
}
71
63
}
0 commit comments