diff --git a/docs/book/v3/messages.md b/docs/book/v3/messages.md
index e0213517..cb4bc87e 100644
--- a/docs/book/v3/messages.md
+++ b/docs/book/v3/messages.md
@@ -7,15 +7,15 @@ validator could return to something different.
Validation messages are defined as constant/template pairs, with the constant
representing a translation key. Such constants are defined per-class. Let's
-look into `Laminas\Validator\GreaterThan` for a descriptive example:
+look into `Laminas\Validator\Digits` for a descriptive example:
```php
-protected $messageTemplates = [
- self::NOT_GREATER => "'%value%' is not greater than '%min%'",
+protected array $messageTemplates = [
+ self::NOT_DIGITS => 'The input must contain only digits',
];
```
-The constant `self::NOT_GREATER` refers to the failure and is used as the
+The constant `self::NOT_DIGITS` refers to the failure and is used as the
message key, and the message template itself is used as the value within the
message array.
@@ -24,7 +24,7 @@ You can retrieve all message templates from a validator by using the
messages a validator could return in the case of a failed validation.
```php
-$validator = new Laminas\Validator\GreaterThan();
+$validator = new Laminas\Validator\Digits();
$messages = $validator->getMessageTemplates();
```
@@ -32,10 +32,10 @@ Using the `setMessage()` method you can set another message to be returned in
case of the specified failure.
```php
-use Laminas\Validator\GreaterThan;
+use Laminas\Validator\Digits;
-$validator = new GreaterThan();
-$validator->setMessage('Please enter a lower value', GreaterThan::NOT_GREATER);
+$validator = new Digits();
+$validator->setMessage('Please enter some numbers', Digits::NOT_DIGITS);
```
The second parameter defines the failure which will be overridden. When you omit
diff --git a/docs/book/v3/set.md b/docs/book/v3/set.md
index 1bf8d5eb..d1af0a2d 100644
--- a/docs/book/v3/set.md
+++ b/docs/book/v3/set.md
@@ -3,7 +3,6 @@
The following validators come with the laminas-validator distribution.
- [Barcode](validators/barcode.md)
-- [Between](validators/between.md)
- [Callback](validators/callback.md)
- [CreditCard](validators/credit-card.md)
- [Date](validators/date.md)
@@ -11,7 +10,6 @@ The following validators come with the laminas-validator distribution.
- [EmailAddress](validators/email-address.md)
- [Explode](validators/explode.md)
- [File Validation Classes](validators/file/intro.md)
-- [GreaterThan](validators/greater-than.md)
- [Hex](validators/hex.md)
- [Hostname](validators/hostname.md)
- [HostWithPublicIPv4Address](validators/host-with-public-ipv4-address.md)
@@ -23,7 +21,6 @@ The following validators come with the laminas-validator distribution.
- [Isbn](validators/isbn.md)
- [IsCountable](validators/is-countable.md)
- [IsInstanceOf](validators/isinstanceof.md)
-- [LessThan](validators/less-than.md)
- [NotEmpty](validators/not-empty.md)
- [Regex](validators/regex.md)
- [Sitemap](validators/sitemap.md)
diff --git a/docs/book/v3/validators/between.md b/docs/book/v3/validators/between.md
deleted file mode 100644
index 1c033c0c..00000000
--- a/docs/book/v3/validators/between.md
+++ /dev/null
@@ -1,55 +0,0 @@
-# Between Validator
-
-`Laminas\Validator\Between` allows you to validate if a given value is between two
-other values.
-
-
-> ### Only supports number validation
->
-> `Laminas\Validator\Between` supports only the validation of numbers. Strings or
-> dates can not be validated with this validator.
-
-## Supported options
-
-The following options are supported for `Laminas\Validator\Between`:
-
-- `inclusive`: Defines if the validation is inclusive of the minimum and maximum
- border values, or exclusive. It defaults to `true`.
-- `max`: Sets the maximum border for the validation.
-- `min`: Sets the minimum border for the validation.
-
-## Default behaviour
-
-Per default, this validator checks if a value is between `min` and `max` where
-both border values are allowed as value.
-
-```php
-$valid = new Laminas\Validator\Between(['min' => 0, 'max' => 10]);
-$value = 10;
-$result = $valid->isValid($value);
-// returns true
-```
-
-In the above example, the result is `true` due to the reason that the default
-search is inclusive of the border values. This means in our case that any value
-from '0' to '10' is allowed; values like '-1' and '11' will return `false`.
-
-## Excluding border values
-
-Sometimes it is useful to validate a value by excluding the border values. See
-the following example:
-
-```php
-$valid = new Laminas\Validator\Between([
- 'min' => 0,
- 'max' => 10,
- 'inclusive' => false,
-]);
-$value = 10;
-$result = $valid->isValid($value);
-// returns false
-```
-
-The example above is almost identical to our first example, but we now exclue
-the border values; as such, the values '0' and '10' are no longer allowed and
-will return `false`.
diff --git a/docs/book/v3/validators/greater-than.md b/docs/book/v3/validators/greater-than.md
deleted file mode 100644
index dc6165fa..00000000
--- a/docs/book/v3/validators/greater-than.md
+++ /dev/null
@@ -1,49 +0,0 @@
-# GreaterThan Validator
-
-`Laminas\Validator\GreaterThan` allows you to validate if a given value is greater
-than a minimum border value.
-
-
-> ### Only supports numbers
->
-> `Laminas\Validator\GreaterThan` supports only the validation of numbers. Strings
-> or dates can not be validated with this validator.
-
-## Supported options
-
-The following options are supported for `Laminas\Validator\GreaterThan`:
-
-- `inclusive`: Defines if the validation is inclusive of the minimum value,
- or exclusive. It defaults to `false`.
-- `min`: Sets the minimum allowed value.
-
-## Basic usage
-
-To validate if a given value is greater than a defined minimum:
-
-```php
-$valid = new Laminas\Validator\GreaterThan(['min' => 10]);
-$value = 8;
-$return = $valid->isValid($value);
-// returns false
-```
-
-The above example returns `true` for all values which are greater than 10.
-
-## Inclusive validation
-
-Sometimes it is useful to validate a value by including the minimum value.
-
-```php
-$valid = new Laminas\Validator\GreaterThan([
- 'min' => 10,
- 'inclusive' => true,
-]);
-$value = 10;
-$result = $valid->isValid($value);
-// returns true
-```
-
-The example is identical to our first example, with the exception that we
-included the minimum value. Now the value '10' is allowed and will return
-`true`.
diff --git a/docs/book/v3/validators/less-than.md b/docs/book/v3/validators/less-than.md
deleted file mode 100644
index 50291a8f..00000000
--- a/docs/book/v3/validators/less-than.md
+++ /dev/null
@@ -1,48 +0,0 @@
-# LessThan Validator
-
-`Laminas\Validator\LessThan` allows you to validate if a given value is less than a
-maximum value.
-
-> Supports only number validation
->
-> `Laminas\Validator\LessThan` supports only the validation of numbers. Strings or
-> dates can not be validated with this validator.
-
-## Supported options
-
-The following options are supported for `Laminas\Validator\LessThan`:
-
-- `inclusive`: Defines if the validation is inclusive the maximum value or
- exclusive. It defaults to `false`.
-- `max`: Sets the maximum allowed value.
-
-## Basic usage
-
-To validate if a given value is less than a defined maximum:
-
-```php
-$valid = new Laminas\Validator\LessThan(['max' => 10]);
-$value = 12;
-$return = $valid->isValid($value);
-// returns false
-```
-
-The above example returns `true` for all values lower than 10.
-
-## Inclusive validation
-
-Sometimes it is useful to validate a value by including the maximum value:
-
-```php
-$valid = new Laminas\Validator\LessThan([
- 'max' => 10,
- 'inclusive' => true,
-]);
-$value = 10;
-$result = $valid->isValid($value);
-// returns true
-```
-
-The example is identical to our first example, with the exception that we've
-specified that the maximum is inclusive. Now the value '10' is allowed and will
-return `true`.
diff --git a/mkdocs.yml b/mkdocs.yml
index e3970b10..9517c665 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -11,7 +11,6 @@ nav:
- "Standard Validation Classes": v3/set.md
- Validators:
- Barcode: v3/validators/barcode.md
- - Between: v3/validators/between.md
- BIC: v3/validators/bic.md
- Callback: v3/validators/callback.md
- CreditCard: v3/validators/credit-card.md
@@ -19,7 +18,6 @@ nav:
- Digits: v3/validators/digits.md
- EmailAddress: v3/validators/email-address.md
- Explode: v3/validators/explode.md
- - GreaterThan: v3/validators/greater-than.md
- Hex: v3/validators/hex.md
- Hostname: v3/validators/hostname.md
- HostWithPublicIPv4Address: v3/validators/host-with-public-ipv4-address.md
@@ -32,7 +30,6 @@ nav:
- IsCountable: v3/validators/is-countable.md
- IsInstanceOf: v3/validators/isinstanceof.md
- IsJsonString: v3/validators/is-json-string.md
- - LessThan: v3/validators/less-than.md
- NotEmpty: v3/validators/not-empty.md
- Regex: v3/validators/regex.md
- Sitemap: v3/validators/sitemap.md
@@ -149,7 +146,7 @@ plugins:
messages.md: v3/messages.md
set.md: v3/set.md
validators/barcode.md: v3/validators/barcode.md
- validators/between.md: v3/validators/between.md
+ validators/between.md: v2/validators/between.md
validators/bic.md: v3/validators/bic.md
validators/callback.md: v3/validators/callback.md
validators/credit-card.md: v3/validators/credit-card.md
@@ -159,7 +156,7 @@ plugins:
validators/digits.md: v3/validators/digits.md
validators/email-address.md: v3/validators/email-address.md
validators/explode.md: v3/validators/explode.md
- validators/greater-than.md: v3/validators/greater-than.md
+ validators/greater-than.md: v2/validators/greater-than.md
validators/hex.md: v3/validators/hex.md
validators/hostname.md: v3/validators/hostname.md
validators/iban.md: v3/validators/iban.md
@@ -171,7 +168,7 @@ plugins:
validators/is-countable.md: v3/validators/is-countable.md
validators/isinstanceof.md: v3/validators/isinstanceof.md
validators/is-json-string.md: v3/validators/is-json-string.md
- validators/less-than.md: v3/validators/less-than.md
+ validators/less-than.md: v2/validators/less-than.md
validators/not-empty.md: v3/validators/not-empty.md
validators/regex.md: v3/validators/regex.md
validators/sitemap.md: v3/validators/sitemap.md
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 3f1c4dc1..8b61de10 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -66,8 +66,6 @@
options]]>
options]]>
options]]>
- options]]>
- options]]>
@@ -339,19 +337,6 @@
-
-
-
-
-
- options['inclusive']]]>
-
-
-
-
-
-
-
@@ -1250,24 +1235,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1426,24 +1393,6 @@
options['type']]]>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1628,21 +1577,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2001,25 +1935,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2151,22 +2066,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2250,9 +2149,6 @@
-
-
-
@@ -2305,9 +2201,6 @@
-
-
-
diff --git a/src/Between.php b/src/Between.php
deleted file mode 100644
index d9e7994b..00000000
--- a/src/Between.php
+++ /dev/null
@@ -1,217 +0,0 @@
-
- */
- protected $messageTemplates = [
- self::NOT_BETWEEN => "The input is not between '%min%' and '%max%', inclusively",
- self::NOT_BETWEEN_STRICT => "The input is not strictly between '%min%' and '%max%'",
- self::VALUE_NOT_NUMERIC => "The min ('%min%') and max ('%max%') values are numeric, but the input is not",
- self::VALUE_NOT_STRING => "The min ('%min%') and max ('%max%') values are non-numeric strings, "
- . 'but the input is not a string',
- ];
-
- /**
- * Additional variables available for validation failure messages
- *
- * @var array
- */
- protected $messageVariables = [
- 'min' => ['options' => 'min'],
- 'max' => ['options' => 'max'],
- ];
-
- /**
- * Options for the between validator
- *
- * @var array
- */
- protected $options = [
- 'inclusive' => true, // Whether to do inclusive comparisons, allowing equivalence to min and/or max
- 'min' => 0,
- 'max' => PHP_INT_MAX,
- ];
-
- /**
- * Sets validator options
- * Accepts the following option keys:
- * 'min' => scalar, minimum border
- * 'max' => scalar, maximum border
- * 'inclusive' => boolean, inclusive border values
- *
- * @param array|Traversable $options
- * @throws Exception\InvalidArgumentException
- */
- public function __construct($options = null)
- {
- if ($options instanceof Traversable) {
- $options = ArrayUtils::iteratorToArray($options);
- }
- if (! is_array($options)) {
- $temp = [];
- /** @psalm-var array $options */
- $options = func_get_args();
- $temp['min'] = array_shift($options);
- if (! empty($options)) {
- $temp['max'] = array_shift($options);
- }
-
- if (! empty($options)) {
- $temp['inclusive'] = array_shift($options);
- }
-
- $options = $temp;
- }
-
- if (! array_key_exists('min', $options) || ! array_key_exists('max', $options)) {
- throw new Exception\InvalidArgumentException("Missing option: 'min' and 'max' have to be given");
- }
-
- if (
- (isset($options['min']) && is_numeric($options['min']))
- && (isset($options['max']) && is_numeric($options['max']))
- ) {
- $this->numeric = true;
- } elseif (
- (isset($options['min']) && is_string($options['min']))
- && (isset($options['max']) && is_string($options['max']))
- ) {
- $this->numeric = false;
- } else {
- throw new Exception\InvalidArgumentException(
- "Invalid options: 'min' and 'max' should be of the same scalar type"
- );
- }
-
- parent::__construct($options);
- }
-
- /**
- * Returns the min option
- *
- * @return mixed
- */
- public function getMin()
- {
- return $this->options['min'];
- }
-
- /**
- * Sets the min option
- *
- * @return $this Provides a fluent interface
- */
- public function setMin(mixed $min)
- {
- $this->options['min'] = $min;
- return $this;
- }
-
- /**
- * Returns the max option
- *
- * @return mixed
- */
- public function getMax()
- {
- return $this->options['max'];
- }
-
- /**
- * Sets the max option
- *
- * @return $this Provides a fluent interface
- */
- public function setMax(mixed $max)
- {
- $this->options['max'] = $max;
- return $this;
- }
-
- /**
- * Returns the inclusive option
- *
- * @return bool
- */
- public function getInclusive()
- {
- return $this->options['inclusive'];
- }
-
- /**
- * Sets the inclusive option
- *
- * @param bool $inclusive
- * @return $this Provides a fluent interface
- */
- public function setInclusive($inclusive)
- {
- $this->options['inclusive'] = $inclusive;
- return $this;
- }
-
- /**
- * Returns true if and only if $value is between min and max options, inclusively
- * if inclusive option is true.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value)
- {
- $this->setValue($value);
-
- if ($this->numeric && ! is_numeric($value)) {
- $this->error(self::VALUE_NOT_NUMERIC);
- return false;
- }
- if (! $this->numeric && ! is_string($value)) {
- $this->error(self::VALUE_NOT_STRING);
- return false;
- }
-
- if ($this->getInclusive()) {
- if ($this->getMin() > $value || $value > $this->getMax()) {
- $this->error(self::NOT_BETWEEN);
- return false;
- }
- } else {
- if ($this->getMin() >= $value || $value >= $this->getMax()) {
- $this->error(self::NOT_BETWEEN_STRICT);
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/src/GreaterThan.php b/src/GreaterThan.php
deleted file mode 100644
index b2fbdc47..00000000
--- a/src/GreaterThan.php
+++ /dev/null
@@ -1,155 +0,0 @@
- "The input is not greater than '%min%'",
- self::NOT_GREATER_INCLUSIVE => "The input is not greater than or equal to '%min%'",
- ];
-
- /** @var array */
- protected $messageVariables = [
- 'min' => 'min',
- ];
-
- /**
- * Minimum value
- *
- * @var mixed
- */
- protected $min;
-
- /**
- * Whether to do inclusive comparisons, allowing equivalence to max
- *
- * If false, then strict comparisons are done, and the value may equal
- * the min option
- *
- * @var bool
- */
- protected $inclusive;
-
- /**
- * Sets validator options
- *
- * @param array|Traversable $options
- * @throws Exception\InvalidArgumentException
- */
- public function __construct($options = null)
- {
- if ($options instanceof Traversable) {
- $options = ArrayUtils::iteratorToArray($options);
- }
- if (! is_array($options)) {
- $options = func_get_args();
- $temp['min'] = array_shift($options);
-
- if (! empty($options)) {
- $temp['inclusive'] = array_shift($options);
- }
-
- $options = $temp;
- }
-
- if (! array_key_exists('min', $options)) {
- throw new Exception\InvalidArgumentException("Missing option 'min'");
- }
-
- if (! array_key_exists('inclusive', $options)) {
- $options['inclusive'] = false;
- }
-
- $this->setMin($options['min'])
- ->setInclusive($options['inclusive']);
-
- parent::__construct($options);
- }
-
- /**
- * Returns the min option
- *
- * @return mixed
- */
- public function getMin()
- {
- return $this->min;
- }
-
- /**
- * Sets the min option
- *
- * @return $this Provides a fluent interface
- */
- public function setMin(mixed $min)
- {
- $this->min = $min;
- return $this;
- }
-
- /**
- * Returns the inclusive option
- *
- * @return bool
- */
- public function getInclusive()
- {
- return $this->inclusive;
- }
-
- /**
- * Sets the inclusive option
- *
- * @param bool $inclusive
- * @return $this Provides a fluent interface
- */
- public function setInclusive($inclusive)
- {
- $this->inclusive = $inclusive;
- return $this;
- }
-
- /**
- * Returns true if and only if $value is greater than min option
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value)
- {
- $this->setValue($value);
-
- if ($this->inclusive) {
- if ($this->min > $value) {
- $this->error(self::NOT_GREATER_INCLUSIVE);
- return false;
- }
- } else {
- if ($this->min >= $value) {
- $this->error(self::NOT_GREATER);
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/src/LessThan.php b/src/LessThan.php
deleted file mode 100644
index 288da8b7..00000000
--- a/src/LessThan.php
+++ /dev/null
@@ -1,160 +0,0 @@
- "The input is not less than '%max%'",
- self::NOT_LESS_INCLUSIVE => "The input is not less or equal than '%max%'",
- ];
-
- /**
- * Additional variables available for validation failure messages
- *
- * @var array
- */
- protected $messageVariables = [
- 'max' => 'max',
- ];
-
- /**
- * Maximum value
- *
- * @var mixed
- */
- protected $max;
-
- /**
- * Whether to do inclusive comparisons, allowing equivalence to max
- *
- * If false, then strict comparisons are done, and the value may equal
- * the max option
- *
- * @var bool
- */
- protected $inclusive;
-
- /**
- * Sets validator options
- *
- * @param array|Traversable $options
- * @throws Exception\InvalidArgumentException
- */
- public function __construct($options = null)
- {
- if ($options instanceof Traversable) {
- $options = ArrayUtils::iteratorToArray($options);
- }
- if (! is_array($options)) {
- $options = func_get_args();
- $temp['max'] = array_shift($options);
-
- if (! empty($options)) {
- $temp['inclusive'] = array_shift($options);
- }
-
- $options = $temp;
- }
-
- if (! array_key_exists('max', $options)) {
- throw new Exception\InvalidArgumentException("Missing option 'max'");
- }
-
- if (! array_key_exists('inclusive', $options)) {
- $options['inclusive'] = false;
- }
-
- $this->setMax($options['max'])
- ->setInclusive($options['inclusive']);
-
- parent::__construct($options);
- }
-
- /**
- * Returns the max option
- *
- * @return mixed
- */
- public function getMax()
- {
- return $this->max;
- }
-
- /**
- * Sets the max option
- *
- * @return $this Provides a fluent interface
- */
- public function setMax(mixed $max)
- {
- $this->max = $max;
- return $this;
- }
-
- /**
- * Returns the inclusive option
- *
- * @return bool
- */
- public function getInclusive()
- {
- return $this->inclusive;
- }
-
- /**
- * Sets the inclusive option
- *
- * @param bool $inclusive
- * @return $this Provides a fluent interface
- */
- public function setInclusive($inclusive)
- {
- $this->inclusive = $inclusive;
- return $this;
- }
-
- /**
- * Returns true if and only if $value is less than max option, inclusively
- * when the inclusive option is true
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value)
- {
- $this->setValue($value);
-
- if ($this->inclusive) {
- if ($value > $this->max) {
- $this->error(self::NOT_LESS_INCLUSIVE);
- return false;
- }
- } else {
- if ($value >= $this->max) {
- $this->error(self::NOT_LESS);
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/src/ValidatorPluginManager.php b/src/ValidatorPluginManager.php
index c84aa50c..1f5688d7 100644
--- a/src/ValidatorPluginManager.php
+++ b/src/ValidatorPluginManager.php
@@ -29,8 +29,6 @@ final class ValidatorPluginManager extends AbstractPluginManager
protected $aliases = [
'barcode' => Barcode::class,
'Barcode' => Barcode::class,
- 'between' => Between::class,
- 'Between' => Between::class,
'BIC' => BusinessIdentifierCode::class,
'bic' => BusinessIdentifierCode::class,
'bitwise' => Bitwise::class,
@@ -114,9 +112,6 @@ final class ValidatorPluginManager extends AbstractPluginManager
'gpspoint' => GpsPoint::class,
'gpsPoint' => GpsPoint::class,
'GpsPoint' => GpsPoint::class,
- 'greaterthan' => GreaterThan::class,
- 'greaterThan' => GreaterThan::class,
- 'GreaterThan' => GreaterThan::class,
'hex' => Hex::class,
'Hex' => Hex::class,
'hostname' => Hostname::class,
@@ -139,9 +134,6 @@ final class ValidatorPluginManager extends AbstractPluginManager
'isinstanceof' => IsInstanceOf::class,
'isInstanceOf' => IsInstanceOf::class,
'IsInstanceOf' => IsInstanceOf::class,
- 'lessthan' => LessThan::class,
- 'lessThan' => LessThan::class,
- 'LessThan' => LessThan::class,
'notempty' => NotEmpty::class,
'notEmpty' => NotEmpty::class,
'NotEmpty' => NotEmpty::class,
@@ -179,7 +171,6 @@ final class ValidatorPluginManager extends AbstractPluginManager
*/
protected $factories = [
Barcode::class => InvokableFactory::class,
- Between::class => InvokableFactory::class,
Bitwise::class => InvokableFactory::class,
BusinessIdentifierCode::class => InvokableFactory::class,
Callback::class => InvokableFactory::class,
@@ -209,7 +200,6 @@ final class ValidatorPluginManager extends AbstractPluginManager
File\UploadFile::class => InvokableFactory::class,
File\WordCount::class => InvokableFactory::class,
GpsPoint::class => InvokableFactory::class,
- GreaterThan::class => InvokableFactory::class,
Hex::class => InvokableFactory::class,
Hostname::class => InvokableFactory::class,
HostWithPublicIPv4Address::class => InvokableFactory::class,
@@ -222,7 +212,6 @@ final class ValidatorPluginManager extends AbstractPluginManager
IsCountable::class => InvokableFactory::class,
IsInstanceOf::class => InvokableFactory::class,
IsJsonString::class => InvokableFactory::class,
- LessThan::class => InvokableFactory::class,
NotEmpty::class => InvokableFactory::class,
Regex::class => InvokableFactory::class,
Sitemap\Changefreq::class => InvokableFactory::class,
diff --git a/test/BetweenTest.php b/test/BetweenTest.php
deleted file mode 100644
index 3936a95d..00000000
--- a/test/BetweenTest.php
+++ /dev/null
@@ -1,336 +0,0 @@
-
- */
- public static function providerBasic(): array
- {
- return [
- 'inclusive-int-valid-floor' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => true,
- 'expected' => true,
- 'value' => 1,
- ],
- 'inclusive-int-valid-between' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => true,
- 'expected' => true,
- 'value' => 10,
- ],
- 'inclusive-int-valid-ceiling' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => true,
- 'expected' => true,
- 'value' => 100,
- ],
- 'inclusive-int-invaild-below' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => true,
- 'expected' => false,
- 'value' => 0,
- ],
- 'inclusive-int-invalid-below-fractional' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => true,
- 'expected' => false,
- 'value' => 0.99,
- ],
- 'inclusive-int-invalid-above-fractional' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => true,
- 'expected' => false,
- 'value' => 100.01,
- ],
- 'inclusive-int-invalid-above' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => true,
- 'expected' => false,
- 'value' => 101,
- ],
- 'exclusive-int-invalid-below' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => false,
- 'expected' => false,
- 'value' => 0,
- ],
- 'exclusive-int-invalid-floor' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => false,
- 'expected' => false,
- 'value' => 1,
- ],
- 'exclusive-int-invalid-ceiling' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => false,
- 'expected' => false,
- 'value' => 100,
- ],
- 'exclusive-int-invalid-above' => [
- 'min' => 1,
- 'max' => 100,
- 'inclusive' => false,
- 'expected' => false,
- 'value' => 101,
- ],
- 'inclusive-string-valid-floor' => [
- 'min' => 'a',
- 'max' => 'z',
- 'inclusive' => true,
- 'expected' => true,
- 'value' => 'a',
- ],
- 'inclusive-string-valid-between' => [
- 'min' => 'a',
- 'max' => 'z',
- 'inclusive' => true,
- 'expected' => true,
- 'value' => 'm',
- ],
- 'inclusive-string-valid-ceiling' => [
- 'min' => 'a',
- 'max' => 'z',
- 'inclusive' => true,
- 'expected' => true,
- 'value' => 'z',
- ],
- 'exclusive-string-invalid-out-of-range' => [
- 'min' => 'a',
- 'max' => 'z',
- 'inclusive' => false,
- 'expected' => false,
- 'value' => '!',
- ],
- 'exclusive-string-invalid-floor' => [
- 'min' => 'a',
- 'max' => 'z',
- 'inclusive' => false,
- 'expected' => false,
- 'value' => 'a',
- ],
- 'exclusive-string-invalid-ceiling' => [
- 'min' => 'a',
- 'max' => 'z',
- 'inclusive' => false,
- 'expected' => false,
- 'value' => 'z',
- ],
- 'inclusive-int-invalid-string' => [
- 'min' => 0,
- 'max' => 99_999_999,
- 'inclusive' => true,
- 'expected' => false,
- 'value' => 'asdasd',
- ],
- 'inclusive-int-invalid-char' => [
- 'min' => 0,
- 'max' => 99_999_999,
- 'inclusive' => true,
- 'expected' => false,
- 'value' => 'q',
- ],
- 'inclusive-string-invalid-zero' => [
- 'min' => 'a',
- 'max' => 'zzzzz',
- 'inclusive' => true,
- 'expected' => false,
- 'value' => 0,
- ],
- 'inclusive-string-invalid-non-zero' => [
- 'min' => 'a',
- 'max' => 'zzzzz',
- 'inclusive' => true,
- 'expected' => false,
- 'value' => 10,
- ],
- ];
- }
-
- /**
- * Ensures that the validator follows expected behavior
- *
- * @param int|float|string $min
- * @param int|float|string $max
- */
- #[DataProvider('providerBasic')]
- public function testBasic($min, $max, bool $inclusive, bool $expected, mixed $value): void
- {
- $validator = new Between(['min' => $min, 'max' => $max, 'inclusive' => $inclusive]);
-
- self::assertSame(
- $expected,
- $validator->isValid($value),
- 'Failed value: ' . $value . ':' . implode("\n", $validator->getMessages())
- );
- }
-
- /**
- * Ensures that getMessages() returns expected default value
- */
- public function testGetMessages(): void
- {
- $validator = new Between(['min' => 1, 'max' => 10]);
-
- self::assertSame([], $validator->getMessages());
- }
-
- /**
- * Ensures that getMin() returns expected value
- */
- public function testGetMin(): void
- {
- $validator = new Between(['min' => 1, 'max' => 10]);
-
- self::assertSame(1, $validator->getMin());
- }
-
- /**
- * Ensures that getMax() returns expected value
- */
- public function testGetMax(): void
- {
- $validator = new Between(['min' => 1, 'max' => 10]);
-
- self::assertSame(10, $validator->getMax());
- }
-
- /**
- * Ensures that getInclusive() returns expected default value
- */
- public function testGetInclusive(): void
- {
- $validator = new Between(['min' => 1, 'max' => 10]);
-
- self::assertSame(true, $validator->getInclusive());
- }
-
- public function testEqualsMessageTemplates(): void
- {
- $validator = new Between(['min' => 1, 'max' => 10]);
-
- self::assertSame(
- [
- Between::NOT_BETWEEN,
- Between::NOT_BETWEEN_STRICT,
- Between::VALUE_NOT_NUMERIC,
- Between::VALUE_NOT_STRING,
- ],
- array_keys($validator->getMessageTemplates())
- );
- self::assertSame($validator->getOption('messageTemplates'), $validator->getMessageTemplates());
- }
-
- public function testEqualsMessageVariables(): void
- {
- $validator = new Between(['min' => 1, 'max' => 10]);
- $messageVariables = [
- 'min' => ['options' => 'min'],
- 'max' => ['options' => 'max'],
- ];
-
- self::assertSame($messageVariables, $validator->getOption('messageVariables'));
- self::assertSame(array_keys($messageVariables), $validator->getMessageVariables());
- }
-
- #[DataProvider('constructBetweenValidatorInvalidDataProvider')]
- public function testMissingMinOrMax(array $args): void
- {
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessage("Missing option: 'min' and 'max' have to be given");
-
- new Between($args);
- }
-
- /**
- * @psalm-return array
- * }>
- */
- public static function constructBetweenValidatorInvalidDataProvider(): array
- {
- return [
- 'only-min' => [['min' => 1]],
- 'only-max' => [['max' => 5]],
- 'min-inclusive' => [['min' => 0, 'inclusive' => true]],
- 'max-inclusive' => [['max' => 5, 'inclusive' => true]],
- 'min-undefined' => [['min' => 0, 'foo' => 'bar']],
- 'max-undefined' => [['max' => 5, 'foo' => 'bar']],
- 'no-min-or-max' => [['bar' => 'foo', 'foo' => 'bar']],
- ];
- }
-
- public function testConstructorCanAcceptInclusiveParameter(): void
- {
- $validator = new Between(1, 10, false);
-
- self::assertFalse($validator->getInclusive());
- }
-
- public function testConstructWithTraversableOptions(): void
- {
- $options = new ArrayObject(['min' => 1, 'max' => 10, 'inclusive' => false]);
- $validator = new Between($options);
-
- self::assertTrue($validator->isValid(5));
- self::assertFalse($validator->isValid(10));
- }
-
- public function testStringValidatedAgainstNumericMinAndMaxIsInvalidAndReturnsAFailureMessage(): void
- {
- $validator = new Between(['min' => 1, 'max' => 10]);
-
- self::assertFalse($validator->isValid('a'));
-
- $messages = $validator->getMessages();
-
- self::assertContains(
- 'The min (\'1\') and max (\'10\') values are numeric, but the input is not',
- $messages
- );
- }
-
- public function testNumericValidatedAgainstStringMinAndMaxIsInvalidAndReturnsAFailureMessage(): void
- {
- $validator = new Between(['min' => 'a', 'max' => 'z']);
-
- self::assertFalse($validator->isValid(10));
-
- $messages = $validator->getMessages();
-
- self::assertContains(
- 'The min (\'a\') and max (\'z\') values are non-numeric strings, but the input is not a string',
- $messages
- );
- }
-}
diff --git a/test/GreaterThanTest.php b/test/GreaterThanTest.php
deleted file mode 100644
index 64358658..00000000
--- a/test/GreaterThanTest.php
+++ /dev/null
@@ -1,211 +0,0 @@
-isValid($input));
- }
-
- /**
- * @psalm-return array,
- * 1: int|float|string,
- * 2: bool
- * }>
- */
- public static function basicDataProvider(): array
- {
- return [
- // phpcs:disable
- 'valid; non inclusive; 0 < 0.01' => [[0], 0.01, true],
- 'valid; non inclusive; 0 < 1' => [[0], 1, true],
- 'valid; non inclusive; 0 < 100' => [[0], 100, true],
-
- 'invalid; non inclusive; 0 >= 0' => [[0], 0, false],
- 'invalid; non inclusive; 0 >= 0.00' => [[0], 0.00, false],
- 'invalid; non inclusive; 0 >= -0.01' => [[0], -0.01, false],
- 'invalid; non inclusive; 0 >= -1' => [[0], -1, false],
- 'invalid; non inclusive; 0 >= -100' => [[0], -100, false],
-
- 'valid; inclusive; 0 <= 0' => [[0, true], 0, true],
- 'valid; inclusive; 0 <= 0.00' => [[0, true], 0.00, true],
- 'valid; inclusive; 0 <= 0.01' => [[0, true], 0.01, true],
- 'valid; inclusive; 0 <= 1' => [[0, true], 1, true],
- 'valid; inclusive; 0 <= 100' => [[0, true], 100, true],
-
- 'invalid; inclusive; 0 >= -0.01' => [[0, true], -0.01, false],
- 'invalid; inclusive; 0 >= -1' => [[0, true], -1, false],
- 'invalid; inclusive; 0 >= -100' => [[0, true], -100, false],
-
- 'valid; non inclusive; a < b' => [['a'], 'b', true],
- 'valid; non inclusive; a < c' => [['a'], 'c', true],
- 'valid; non inclusive; a < d' => [['a'], 'd', true],
-
- 'valid; inclusive; a <= a' => [['a', true], 'a', true],
- 'valid; inclusive; a <= b' => [['a', true], 'b', true],
- 'valid; inclusive; a <= c' => [['a', true], 'c', true],
- 'valid; inclusive; a <= d' => [['a', true], 'd', true],
-
- 'invalid; non-inclusive; a >= a' => [['a', false], 'a', false],
-
- 'invalid; non inclusive; z >= x' => [['z'], 'x', false],
- 'invalid; non inclusive; z >= y' => [['z'], 'y', false],
- 'invalid; non inclusive; z >= z' => [['z'], 'z', false],
-
- 'invalid; inclusive; z > x' => [['z', true], 'x', false],
- 'invalid; inclusive; z > y' => [['z', true], 'y', false],
-
- 'valid; inclusive; 0 <= 0; array' => [[['min' => 0, 'inclusive' => true]], 0, true],
- 'valid; inclusive; 0 <= 0.00; array' => [[['min' => 0, 'inclusive' => true]], 0.00, true],
- 'valid; inclusive; 0 <= 0.01; array' => [[['min' => 0, 'inclusive' => true]], 0.01, true],
- 'valid; inclusive; 0 <= 1; array' => [[['min' => 0, 'inclusive' => true]], 1, true],
- 'valid; inclusive; 0 <= 100; array' => [[['min' => 0, 'inclusive' => true]], 100, true],
-
- 'invalid; inclusive; 0 >= -0.01; array' => [[['min' => 0, 'inclusive' => true]], -0.01, false],
- 'invalid; inclusive; 0 >= -1; array' => [[['min' => 0, 'inclusive' => true]], -1, false],
- 'invalid; inclusive; 0 >= -100; array' => [[['min' => 0, 'inclusive' => true]], -100, false],
-
- 'valid; non inclusive; 0 < 0.01; array' => [[['min' => 0, 'inclusive' => false]], 0.01, true],
- 'valid; non inclusive; 0 < 1; array' => [[['min' => 0, 'inclusive' => false]], 1, true],
- 'valid; non inclusive; 0 < 100; array' => [[['min' => 0, 'inclusive' => false]], 100, true],
-
- 'invalid; non inclusive; 0 >= 0; array' => [[['min' => 0, 'inclusive' => false]], 0, false],
- 'invalid; non inclusive; 0 >= 0.00; array' => [[['min' => 0, 'inclusive' => false]], 0.00, false],
- 'invalid; non inclusive; 0 >= -0.01; array' => [[['min' => 0, 'inclusive' => false]], -0.01, false],
- 'invalid; non inclusive; 0 >= -1; array' => [[['min' => 0, 'inclusive' => false]], -1, false],
- 'invalid; non inclusive; 0 >= -100; array' => [[['min' => 0, 'inclusive' => false]], -100, false],
- // phpcs:enable
- ];
- }
-
- /**
- * Ensures that getMessages() returns expected default value
- */
- public function testGetMessages(): void
- {
- $validator = new GreaterThan(10);
-
- self::assertSame([], $validator->getMessages());
- }
-
- /**
- * Ensures that getMin() returns expected value
- */
- public function testGetMin(): void
- {
- $validator = new GreaterThan(10);
-
- self::assertSame(10, $validator->getMin());
- }
-
- /**
- * Ensures that getInclusive() returns expected default value
- */
- public function testGetInclusive(): void
- {
- $validator = new GreaterThan(10);
-
- self::assertFalse($validator->getInclusive());
- }
-
- public function testEqualsMessageTemplates(): void
- {
- $validator = new GreaterThan(1);
-
- self::assertSame(
- [
- GreaterThan::NOT_GREATER,
- GreaterThan::NOT_GREATER_INCLUSIVE,
- ],
- array_keys($validator->getMessageTemplates())
- );
- self::assertSame($validator->getOption('messageTemplates'), $validator->getMessageTemplates());
- }
-
- public function testEqualsMessageVariables(): void
- {
- $validator = new GreaterThan(1);
- $messageVariables = [
- 'min' => 'min',
- ];
-
- self::assertSame($messageVariables, $validator->getOption('messageVariables'));
- self::assertSame(array_keys($messageVariables), $validator->getMessageVariables());
- }
-
- #[DataProvider('correctInclusiveMessageDataProvider')]
- public function testCorrectInclusiveMessageReturn(float $input): void
- {
- $validator = new GreaterThan(10);
- $validator->isValid($input);
- $message = $validator->getMessages();
-
- self::assertArrayHaskey('notGreaterThan', $message);
- self::assertSame($message['notGreaterThan'], "The input is not greater than '10'");
- }
-
- /**
- * @psalm-return array{0: array{0: 0}, '0.5': array{0: float}, 5: array{0: 5}, 10: array{0: 10}}
- * @return (float|int)[][]
- */
- public static function correctInclusiveMessageDataProvider(): array
- {
- return [
- '0' => [0],
- '0.5' => [0.5],
- '5' => [5],
- '10' => [10],
- ];
- }
-
- #[DataProvider('correctNotInclusiveMessageDataProvider')]
- public function testCorrectNotInclusiveMessageReturn(float $input): void
- {
- $validator = new GreaterThan(['min' => 10, 'inclusive' => true]);
- $validator->isValid($input);
- $message = $validator->getMessages();
-
- self::assertArrayHaskey('notGreaterThanInclusive', $message);
- self::assertSame($message['notGreaterThanInclusive'], "The input is not greater than or equal to '10'");
- }
-
- /**
- * @psalm-return array{0: array{0: 0}, '0.5': array{0: float}, 5: array{0: 5}, 9: array{0: 9}}
- * @return (float|int)[][]
- */
- public static function correctNotInclusiveMessageDataProvider(): array
- {
- return [
- '0' => [0],
- '0.5' => [0.5],
- '5' => [5],
- '9' => [9],
- ];
- }
-
- public function testConstructorCanAcceptInclusiveFlagAsAnArgument(): void
- {
- $validator = new GreaterThan(10, true);
-
- self::assertTrue($validator->getInclusive());
- }
-}
diff --git a/test/LessThanTest.php b/test/LessThanTest.php
deleted file mode 100644
index a9c62e88..00000000
--- a/test/LessThanTest.php
+++ /dev/null
@@ -1,158 +0,0 @@
-isValid($input));
- }
-
- /**
- * @psalm-return array
- */
- public static function basicDataProvider(): array
- {
- return [
- // phpcs:disable
- 'valid; non inclusive; 100 > -1' => [[100], -1, true],
- 'valid; non inclusive; 100 > 0' => [[100], 0, true],
- 'valid; non inclusive; 100 > 0.01' => [[100], 0.01, true],
- 'valid; non inclusive; 100 > 1' => [[100], 1, true],
- 'valid; non inclusive; 100 > 99.999' => [[100], 99.999, true],
-
- 'invalid; non inclusive; 100 <= 100' => [[100], 100, false],
- 'invalid; non inclusive; 100 <= 100.0' => [[100], 100.0, false],
- 'invalid; non inclusive; 100 <= 100.01' => [[100], 100.01, false],
-
- 'valid; inclusive; 100 >= -1' => [[100, true], -1, true],
- 'valid; inclusive; 100 >= 0' => [[100, true], 0, true],
- 'valid; inclusive; 100 >= 0.01' => [[100, true], 0.01, true],
- 'valid; inclusive; 100 >= 1' => [[100, true], 1, true],
- 'valid; inclusive; 100 >= 99.999' => [[100, true], 99.999, true],
- 'valid; inclusive; 100 >= 100' => [[100, true], 100, true],
- 'valid; inclusive; 100 >= 100.0' => [[100, true], 100.0, true],
-
- 'invalid; inclusive; 100 < 100.01' => [[100, true], 100.01, false],
-
- 'invalid; non inclusive; a >= a' => [['a'], 'a', false],
- 'invalid; non inclusive; a >= b' => [['a'], 'b', false],
- 'invalid; non inclusive; a >= c' => [['a'], 'c', false],
- 'invalid; non inclusive; a >= d' => [['a'], 'd', false],
-
- 'valid; inclusive; a <= a' => [['a', true], 'a', true],
-
- 'valid; non inclusive; z > x' => [['z'], 'x', true],
- 'valid; non inclusive; z > y' => [['z'], 'y', true],
-
- 'valid; inclusive; z >= x' => [['z', true], 'x', true],
- 'valid; inclusive; z >= y' => [['z', true], 'y', true],
- 'valid; inclusive; z >= z' => [['z', true], 'z', true],
-
- 'valid; inclusive; 100 >= -1; array' => [[['max' => 100, 'inclusive' => true]], -1, true],
- 'valid; inclusive; 100 >= 0; array' => [[['max' => 100, 'inclusive' => true]], 0, true],
- 'valid; inclusive; 100 >= 0.01; array' => [[['max' => 100, 'inclusive' => true]], 0.01, true],
- 'valid; inclusive; 100 >= 1; array' => [[['max' => 100, 'inclusive' => true]], 1, true],
- 'valid; inclusive; 100 >= 99.999; array' => [[['max' => 100, 'inclusive' => true]], 99.999, true],
- 'valid; inclusive; 100 >= 100; array' => [[['max' => 100, 'inclusive' => true]], 100, true],
- 'valid; inclusive; 100 >= 100.0; array' => [[['max' => 100, 'inclusive' => true]], 100.0, true],
-
- 'invalid; inclusive; 100 < 100.01; array' => [[['max' => 100, 'inclusive' => true]], 100.01, false],
-
- 'valid; non inclusive; 100 > -1; array' => [[['max' => 100, 'inclusive' => false]], -1, true],
- 'valid; non inclusive; 100 > 0; array' => [[['max' => 100, 'inclusive' => false]], 0, true],
- 'valid; non inclusive; 100 > 0.01; array' => [[['max' => 100, 'inclusive' => false]], 0.01, true],
- 'valid; non inclusive; 100 > 1; array' => [[['max' => 100, 'inclusive' => false]], 1, true],
- 'valid; non inclusive; 100 > 99.999; array' => [[['max' => 100, 'inclusive' => false]], 99.999, true],
-
- 'invalid; non inclusive; 100 <= 100; array' => [[['max' => 100, 'inclusive' => false]], 100, false],
- 'invalid; non inclusive; 100 <= 100.0; array' => [[['max' => 100, 'inclusive' => false]], 100.0, false],
- 'invalid; non inclusive; 100 <= 100.01; array' => [[['max' => 100, 'inclusive' => false]], 100.01, false],
- // phpcs:enable
- ];
- }
-
- /**
- * Ensures that getMessages() returns expected default value
- */
- public function testGetMessages(): void
- {
- $validator = new LessThan(10);
-
- self::assertSame([], $validator->getMessages());
- }
-
- /**
- * Ensures that getMax() returns expected value
- */
- public function testGetMax(): void
- {
- $validator = new LessThan(10);
-
- self::assertSame(10, $validator->getMax());
- }
-
- /**
- * Ensures that getInclusive() returns expected default value
- */
- public function testGetInclusive(): void
- {
- $validator = new LessThan(10);
-
- self::assertSame(false, $validator->getInclusive());
- }
-
- public function testEqualsMessageTemplates(): void
- {
- $validator = new LessThan(10);
-
- self::assertSame(
- [
- LessThan::NOT_LESS,
- LessThan::NOT_LESS_INCLUSIVE,
- ],
- array_keys($validator->getMessageTemplates())
- );
- self::assertSame($validator->getOption('messageTemplates'), $validator->getMessageTemplates());
- }
-
- public function testEqualsMessageVariables(): void
- {
- $validator = new LessThan(10);
- $messageVariables = [
- 'max' => 'max',
- ];
-
- self::assertSame($messageVariables, $validator->getOption('messageVariables'));
- self::assertSame(array_keys($messageVariables), $validator->getMessageVariables());
- }
-
- public function testConstructorAllowsSettingAllOptionsAsDiscreteArguments(): void
- {
- $validator = new LessThan(10, true);
-
- self::assertSame(10, $validator->getMax());
- self::assertTrue($validator->getInclusive());
- }
-}
diff --git a/test/StaticValidatorTest.php b/test/StaticValidatorTest.php
index e8e3d736..ed67979b 100644
--- a/test/StaticValidatorTest.php
+++ b/test/StaticValidatorTest.php
@@ -8,7 +8,7 @@
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Validator\AbstractValidator;
-use Laminas\Validator\Between;
+use Laminas\Validator\Digits;
use Laminas\Validator\StaticValidator;
use Laminas\Validator\StringLength;
use Laminas\Validator\ValidatorInterface;
@@ -107,9 +107,9 @@ public function testSetGetMessageLengthLimitation(): void
self::assertSame(5, AbstractValidator::getMessageLength());
- $valid = new Between(1, 10);
+ $valid = new Digits();
- self::assertFalse($valid->isValid(24));
+ self::assertFalse($valid->isValid('foo'));
$message = current($valid->getMessages());
@@ -153,7 +153,7 @@ public function testPassingNullWhenSettingPluginManagerResetsPluginManager(): vo
/**
* @psalm-return array,
* 2: array,
* 3: bool
@@ -162,10 +162,8 @@ public function testPassingNullWhenSettingPluginManagerResetsPluginManager(): vo
public static function parameterizedData(): array
{
return [
- 'valid-positive-range' => [5, Between::class, ['min' => 1, 'max' => 10], true],
- 'valid-negative-range' => [-5, Between::class, ['min' => -10, 'max' => -1], true],
- 'invalid-positive-range' => [-5, Between::class, ['min' => 1, 'max' => 10], false],
- 'invalid-negative-range' => [5, Between::class, ['min' => -10, 'max' => -1], false],
+ 'valid-length' => ['foo', StringLength::class, ['min' => 1, 'max' => 10], true],
+ 'invalid-length' => ['foo', StringLength::class, ['min' => 5, 'max' => 10], false],
];
}
@@ -174,7 +172,7 @@ public static function parameterizedData(): array
*/
#[DataProvider('parameterizedData')]
public function testExecuteValidWithParameters(
- int $value,
+ mixed $value,
string $validator,
array $options,
bool $expected
@@ -183,13 +181,12 @@ public function testExecuteValidWithParameters(
}
/**
- * @psalm-return array, 2: int[]}>
+ * @psalm-return array, 2: int[]}>
*/
public static function invalidParameterizedData(): array
{
return [
- 'positive-range' => [5, Between::class, [1, 10]],
- 'negative-range' => [-5, Between::class, [-10, -1]],
+ 'invalid-options' => ['foo', StringLength::class, [5, 10]],
];
}
@@ -198,7 +195,7 @@ public static function invalidParameterizedData(): array
*/
#[DataProvider('invalidParameterizedData')]
public function testExecuteRaisesExceptionForIndexedOptionsArray(
- int $value,
+ mixed $value,
string $validator,
array $options
): void {
diff --git a/test/ValidatorChainTest.php b/test/ValidatorChainTest.php
index 7477c479..f935f9f9 100644
--- a/test/ValidatorChainTest.php
+++ b/test/ValidatorChainTest.php
@@ -5,10 +5,10 @@
namespace LaminasTest\Validator;
use Laminas\Validator\AbstractValidator;
-use Laminas\Validator\Between;
use Laminas\Validator\Callback;
-use Laminas\Validator\GreaterThan;
+use Laminas\Validator\Digits;
use Laminas\Validator\NotEmpty;
+use Laminas\Validator\StringLength;
use Laminas\Validator\Timezone;
use Laminas\Validator\ValidatorChain;
use Laminas\Validator\ValidatorInterface;
@@ -46,7 +46,7 @@ protected function tearDown(): void
public function populateValidatorChain(): void
{
$this->validator->attach(new NotEmpty());
- $this->validator->attach(new Between(1, 5));
+ $this->validator->attach(new StringLength(['min' => 1, 'max' => 5]));
}
public function testValidatorChainIsEmptyByDefault(): void
@@ -300,9 +300,8 @@ public static function breakChainFlags(): array
#[DataProvider('breakChainFlags')]
public function testAttachByNameAllowsSpecifyingBreakChainOnFailureFlagViaOptions(string $option): void
{
- $this->validator->attachByName('GreaterThan', [
+ $this->validator->attachByName('Digits', [
$option => true,
- 'min' => 1,
]);
self::assertCount(1, $this->validator);
@@ -315,23 +314,23 @@ public function testAttachByNameAllowsSpecifyingBreakChainOnFailureFlagViaOption
$validator = $spec['instance'];
- self::assertInstanceOf(GreaterThan::class, $validator);
+ self::assertInstanceOf(Digits::class, $validator);
self::assertArrayHasKey('breakChainOnFailure', $spec);
self::assertTrue($spec['breakChainOnFailure']);
}
public function testGetValidatorsReturnsAnArrayOfQueueItems(): void
{
- $empty = new NotEmpty();
- $between = new Between(['min' => 10, 'max' => 20]);
- $expect = [
+ $empty = new NotEmpty();
+ $stringLength = new StringLength(['min' => 10, 'max' => 20]);
+ $expect = [
['instance' => $empty, 'breakChainOnFailure' => false],
- ['instance' => $between, 'breakChainOnFailure' => false],
+ ['instance' => $stringLength, 'breakChainOnFailure' => false],
];
$chain = new ValidatorChain();
$chain->attach($empty);
- $chain->attach($between);
+ $chain->attach($stringLength);
self::assertSame($expect, $chain->getValidators());
}
@@ -339,7 +338,7 @@ public function testGetValidatorsReturnsAnArrayOfQueueItems(): void
public function testMessagesAreASingleDimensionHash(): void
{
$timezone = new Timezone();
- $between = new Between(['min' => 10, 'max' => 20]);
+ $between = new StringLength(['min' => 10, 'max' => 20]);
$chain = new ValidatorChain();
$chain->attach($timezone);
$chain->attach($between);