public function testValidateInt() { $this->assertEquals(5, RestValidatorHelper::validate_int(['int' => 5], 'int')); $this->assertEquals(null, RestValidatorHelper::validate_int([], 'int', ['required' => false])); TestHelper::assertException(function () { RestValidatorHelper::validate_int([], 'int'); }, 'ValidationException'); TestHelper::assertException(function () { RestValidatorHelper::validate_int(['int' => 'foo bar'], 'int'); }, 'ValidationException'); TestHelper::assertException(function () { RestValidatorHelper::validate_int(['int' => 5], 'int', ['max' => 4]); }, 'ValidationException'); $this->assertEquals(-5, RestValidatorHelper::validate_int(['int' => -5], 'int', ['max' => 0])); TestHelper::assertException(function () { RestValidatorHelper::validate_int(['int' => 1], 'int', ['min' => 3, 'max' => 4]); }, 'ValidationException'); $this->assertEquals(2, RestValidatorHelper::validate_int(['int' => 2], 'int', ['min' => 2, 'max' => 4])); $this->assertEquals(4, RestValidatorHelper::validate_int(['int' => 4], 'int', ['min' => 2, 'max' => 4])); }