diff --git a/src/Parameter/Format/BooleanCheck.php b/src/Parameter/Format/BooleanCheck.php index dc44025..da8590e 100644 --- a/src/Parameter/Format/BooleanCheck.php +++ b/src/Parameter/Format/BooleanCheck.php @@ -12,7 +12,7 @@ class BooleanCheck */ public function check(array $param) { - if (!is_bool($param['value'])) { + if ($param['value'] !== 'true' && $param['value'] !== 'false') { throw new ValidationException('Value is not a boolean'); } } diff --git a/src/Parameter/Format/IntegerCheck.php b/src/Parameter/Format/IntegerCheck.php index bb212b2..ff8263d 100644 --- a/src/Parameter/Format/IntegerCheck.php +++ b/src/Parameter/Format/IntegerCheck.php @@ -12,7 +12,7 @@ class IntegerCheck */ public function check(array $param) { - if (!is_int($param['value'])) { + if (!filter_var($param['value'], FILTER_VALIDATE_INT)) { throw new ValidationException('Value is not an integer'); } if (!isset($param['format'])) { diff --git a/src/Parameter/Format/NumberCheck.php b/src/Parameter/Format/NumberCheck.php index 030e998..7a2cc41 100644 --- a/src/Parameter/Format/NumberCheck.php +++ b/src/Parameter/Format/NumberCheck.php @@ -12,7 +12,7 @@ class NumberCheck */ public function check(array $param) { - if (!is_int($param['value']) && !is_float($param['value'])) { + if (!filter_var($param['value'], FILTER_VALIDATE_FLOAT)) { throw new ValidationException('Value is not a number'); } diff --git a/tests/unit/src/Parameter/Format/BooleanCheckTest.php b/tests/unit/src/Parameter/Format/BooleanCheckTest.php index 1ad5cca..d953fee 100644 --- a/tests/unit/src/Parameter/Format/BooleanCheckTest.php +++ b/tests/unit/src/Parameter/Format/BooleanCheckTest.php @@ -24,7 +24,7 @@ public function testCheckThrowsExceptionIfNotABoolean() public function testCheckContinuesNormallyIfOkay() { $mockParam = [ - 'value' => false, + 'value' => 'false', ]; $booleanCheck = new BooleanCheck; diff --git a/tests/unit/src/Parameter/Format/IntegerCheckTest.php b/tests/unit/src/Parameter/Format/IntegerCheckTest.php index eb4eb76..701b810 100644 --- a/tests/unit/src/Parameter/Format/IntegerCheckTest.php +++ b/tests/unit/src/Parameter/Format/IntegerCheckTest.php @@ -24,7 +24,7 @@ public function testCheckThrowsExceptionIfNotAnInteger() public function testCheckIgnoresFormatIfNotDefined() { $mockParam = [ - 'value' => 2147483647 + 1, + 'value' => (string) 2147483647 + 1, ]; $integerCheck = new IntegerCheck; @@ -38,7 +38,7 @@ public function testCheckIgnoresFormatIfNotDefined() public function testCheckThrowsExceptionIfExceedsInt32Bounds() { $mockParam = [ - 'value' => 2147483647 + 1, + 'value' => (string) 2147483647 + 1, 'format' => 'int32', ]; @@ -49,7 +49,7 @@ public function testCheckThrowsExceptionIfExceedsInt32Bounds() public function testCheckPassesIfWithinInt32Bounds() { $mockParam = [ - 'value' => -2147483647 + 1, + 'value' => (string) -2147483647 + 1, 'format' => 'int32', ]; @@ -64,7 +64,7 @@ public function testCheckPassesIfWithinInt32Bounds() public function testCheckThrowsExceptionIfExceedsInt64Bounds() { $mockParam = [ - 'value' => -9223372036854775807 - 1, + 'value' => (string) -9223372036854775807 - 1, 'format' => 'int64', ]; @@ -75,7 +75,7 @@ public function testCheckThrowsExceptionIfExceedsInt64Bounds() public function testCheckPassesIfWithinInt64Bounds() { $mockParam = [ - 'value' => 9223372036854775807 - 1, + 'value' => (string) 9223372036854775807 - 1, ]; $integerCheck = new IntegerCheck; diff --git a/tests/unit/src/Parameter/Format/NumberCheckTest.php b/tests/unit/src/Parameter/Format/NumberCheckTest.php index 219d375..88fa420 100644 --- a/tests/unit/src/Parameter/Format/NumberCheckTest.php +++ b/tests/unit/src/Parameter/Format/NumberCheckTest.php @@ -28,7 +28,7 @@ public function testCheckThrowsExceptionIfNotANumber() public function testCheckCallsToRangeCheckIfOkay() { $mockParam = [ - 'value' => 512.123, + 'value' => (string) 512.123, ]; $numberCheck = $this->getMockBuilder(NumberCheck::class) @@ -51,7 +51,7 @@ public function testCheckRangeFailsIfValueIsExceedsMaximum() $mockParam = [ 'maximum' => 5, 'minimum' => 2, - 'value' => 6, + 'value' => (string) 6, ]; $reflectedNumberCheck = new ReflectionClass(NumberCheck::class); @@ -72,7 +72,7 @@ public function testCheckRangeFailsIfValueIsExceedsExclusiveMaximum() { $mockParam = [ 'exclusiveMaximum' => 5, - 'value' => 5, + 'value' => (string) 5, ]; $reflectedNumberCheck = new ReflectionClass(NumberCheck::class); @@ -94,7 +94,7 @@ public function testCheckRangeFailsIfValueIsExceedsMinimum() $mockParam = [ 'minimum' => 5, 'minimum' => 2, - 'value' => 1, + 'value' => (string) 1, ]; $reflectedNumberCheck = new ReflectionClass(NumberCheck::class); @@ -115,7 +115,7 @@ public function testCheckRangeFailsIfValueIsExceedsExclusiveMinimum() { $mockParam = [ 'exclusiveMinimum' => 2, - 'value' => 2, + 'value' => (string) 2, ]; $reflectedNumberCheck = new ReflectionClass(NumberCheck::class); @@ -133,7 +133,7 @@ public function testCheckRangePassesIfWithinRange() $mockParam = [ 'maximum' => 5, 'minimum' => 2, - 'value' => 4, + 'value' => (string) 4, ]; $reflectedNumberCheck = new ReflectionClass(NumberCheck::class);