diff --git a/module/Core/src/Validation/ShortUrlMetaInputFilter.php b/module/Core/src/Validation/ShortUrlMetaInputFilter.php index 0663a760..9e8b1c7a 100644 --- a/module/Core/src/Validation/ShortUrlMetaInputFilter.php +++ b/module/Core/src/Validation/ShortUrlMetaInputFilter.php @@ -43,7 +43,7 @@ class ShortUrlMetaInputFilter extends InputFilter $this->add($customSlug); $this->add($this->createPositiveNumberInput(self::MAX_VISITS)); - $this->add($this->createPositiveNumberInput(self::SHORT_CODE_LENGTH)); + $this->add($this->createPositiveNumberInput(self::SHORT_CODE_LENGTH, 4)); $this->add($this->createBooleanInput(self::FIND_IF_EXISTS, false)); @@ -52,11 +52,11 @@ class ShortUrlMetaInputFilter extends InputFilter $this->add($domain); } - private function createPositiveNumberInput(string $name): Input + private function createPositiveNumberInput(string $name, int $min = 1): Input { $input = $this->createInput($name, false); $input->getValidatorChain()->attach(new Validator\Digits()) - ->attach(new Validator\GreaterThan(['min' => 1, 'inclusive' => true])); + ->attach(new Validator\GreaterThan(['min' => $min, 'inclusive' => true])); return $input; } diff --git a/module/Core/test/Entity/ShortUrlTest.php b/module/Core/test/Entity/ShortUrlTest.php index 21c869aa..e410dedb 100644 --- a/module/Core/test/Entity/ShortUrlTest.php +++ b/module/Core/test/Entity/ShortUrlTest.php @@ -72,6 +72,6 @@ class ShortUrlTest extends TestCase public function provideLengths(): iterable { yield [null, DEFAULT_SHORT_CODES_LENGTH]; - yield from map(range(1, 10), fn (int $value) => [$value, $value]); + yield from map(range(4, 10), fn (int $value) => [$value, $value]); } } diff --git a/module/Core/test/Model/ShortUrlMetaTest.php b/module/Core/test/Model/ShortUrlMetaTest.php index 13c5ae14..fed2c662 100644 --- a/module/Core/test/Model/ShortUrlMetaTest.php +++ b/module/Core/test/Model/ShortUrlMetaTest.php @@ -44,6 +44,9 @@ class ShortUrlMetaTest extends TestCase ShortUrlMetaInputFilter::VALID_UNTIL => 500, ShortUrlMetaInputFilter::DOMAIN => 4, ]]; + yield [[ + ShortUrlMetaInputFilter::SHORT_CODE_LENGTH => 3, + ]]; } /** @test */