diff --git a/app/Models/Validation/Validators/OkValidator.php b/app/Models/Validation/Validators/OkValidator.php new file mode 100644 index 0000000..cbdcad6 --- /dev/null +++ b/app/Models/Validation/Validators/OkValidator.php @@ -0,0 +1,13 @@ +value = $value; + $this->rangeLimit = $rangeLimit; + $this->nextValidator = $nextValidator; + } + + public function isCurrentValid(): bool + { + if($this->value > $this->rangeLimit) + return false; + + return true; + } + + public function isValid(): bool + { + return $this->isCurrentValid() && $this->nextValidator->isValid(); + } +} + diff --git a/app/Models/Validation/Validators/ValidationInterface.php b/app/Models/Validation/Validators/ValidationInterface.php new file mode 100644 index 0000000..1cbebc4 --- /dev/null +++ b/app/Models/Validation/Validators/ValidationInterface.php @@ -0,0 +1,8 @@ +assertTrue($validator->isValid()); + } +} diff --git a/tests/Unit/Validation/Validators/UpperRangeValidatorTest.php b/tests/Unit/Validation/Validators/UpperRangeValidatorTest.php new file mode 100644 index 0000000..b8d44b5 --- /dev/null +++ b/tests/Unit/Validation/Validators/UpperRangeValidatorTest.php @@ -0,0 +1,51 @@ + [ + 'value' => 10, + 'limit' => 10, + 'isValid' => true, + ], + 'Valid Case for 255' => [ + 'value' => 0, + 'limit' => 255, + 'isValid' => true, + ], + 'Invalid Case for 255' => [ + 'value' => 11, + 'limit' => 10, + 'isValid' => false, + ], + 'Invalid Case for 255' => [ + 'value' => 256, + 'limit' => 255, + 'isValid' => false, + ], + ]; + } + + public function setUpValidator(int $value, int $rangeLimit): UpperRangeValidator + { + return new UpperRangeValidator($value, $rangeLimit, new OkValidator()); + } + + /** + * @dataProvider dataProvider + */ + public function testGetMessage(int $value, int $limit, bool $isValid): void + { + $validator = $this->setUpValidator($value, $limit); + + $this->assertEquals($validator->isValid(), $isValid); + } +}