File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,11 @@ public function getIdentifier() {
2626 * @return array
2727 */
2828 public function validate ($ value ) {
29- if (($ value === null && ! $ this -> allowNull ) || ! is_numeric ($ value )) {
30- return array (" Campo não é numérico. " );
29+ if (($ this -> allowNull && $ value === null ) || is_numeric ($ value )) {
30+ return array ();
3131 }
3232
33- return array ();
33+ return array (" Campo não é numérico. " );
3434 }
3535
3636 /**
Original file line number Diff line number Diff line change @@ -37,4 +37,18 @@ public function testInvalidValues() {
3737 $ this ->assertNotEmpty ($ validation ->validate (array ()));
3838 $ this ->assertNotEmpty ($ validation ->validate (AttributeNotExists::instance ()));
3939 }
40+
41+ public function testNullableParam () {
42+ $ validation = new NumericValidation ();
43+ $ validation ->setParams (["nullable " ]);
44+
45+ $ this ->assertEmpty ($ validation ->validate (null ));
46+ $ this ->assertEmpty ($ validation ->validate (1 ));
47+ $ this ->assertEmpty ($ validation ->validate (0 ));
48+
49+ $ validation ->setParams ([]);
50+ $ this ->assertNotEmpty ($ validation ->validate (null ));
51+ $ this ->assertEmpty ($ validation ->validate (1 ));
52+ $ this ->assertEmpty ($ validation ->validate (0 ));
53+ }
4054}
You can’t perform that action at this time.
0 commit comments