diff --git a/src/Filter.php b/src/Filter.php index 4d27d51..f68254e 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -81,19 +81,15 @@ public function var(mixed $value, int $filter = FILTER_DEFAULT, array|int $optio * Wrapper for filter_input_array * * @see https://www.php.net/manual/en/function.filter-input-array.php - * - * @codeCoverageIgnore */ public function inputArray(int $type, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null { - return $this->varArray(filter_input_array($type), $options, $add_empty); + return $this->varArray(filter_input_array($type) ?? [], $options, $add_empty); } /** * Wrapper for filter_input * * @see https://www.php.net/manual/en/function.filter-input.php - * - * @codeCoverageIgnore */ public function input(int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed { return $this->var(filter_input($type, $var_name), $filter, $options); diff --git a/tests/FilterTest.php b/tests/FilterTest.php index 88b6f21..39d0726 100644 --- a/tests/FilterTest.php +++ b/tests/FilterTest.php @@ -6,6 +6,29 @@ class FilterTest extends \PHPUnit\Framework\TestCase { + /** + * Test the input methods that they don't throw errors + */ + public function testInput() { + $f = Filter::init(); + $value = $f->input(INPUT_POST, 'foo', FILTER_VALIDATE_INT); + $this->assertFalse($value); + } + + /** + * Test the input methods that they don't throw errors + */ + public function testInputArray() { + $f = Filter::init(); + $value = $f->inputArray(INPUT_POST, ['foo' => FILTER_VALIDATE_INT]); + $this->assertSame( + [ + 'foo' => null + ], + $value + ); + } + /** * @dataProvider varArrayData */