Skip to content

Commit

Permalink
Create regression tests for a few issues
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoody committed Dec 13, 2024
1 parent 7cec227 commit ea29c2c
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/integration/issues/1334.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--FILE--
<?php

require 'vendor/autoload.php';

exceptionAll('https://github.com/Respect/Validation/issues/1334', static function (): void {
v::notEmpty()->iterableType()->each(
v::key('street', v::stringType()->notEmpty())
->key('region', v::stringType()->notEmpty())
->key('country', v::stringType()->notEmpty())
->keyOptional('other', v::nullOr(v::notEmpty()->stringType()))
)->assert(
[
['region' => 'Oregon', 'country' => 'USA', 'other' => 123],
['street' => '', 'region' => 'Oregon', 'country' => 'USA'],
['street' => 123, 'region' => 'Oregon', 'country' => 'USA'],
]
);
});

?>
--EXPECT--
https://github.com/Respect/Validation/issues/1334
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
street must be present
- Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid
- These rules must pass for `["region": "Oregon", "country": "USA", "other": 123]`
- street must be present
- These rules must pass for other
- other must be a string or must be null
- These rules must pass for `["street": "", "region": "Oregon", "country": "USA"]`
- street must not be empty
- These rules must pass for `["street": 123, "region": "Oregon", "country": "USA"]`
- street must be a string
[
'each' => [
'__root__' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid',
'allOf.1' => [
'__root__' => 'These rules must pass for `["region": "Oregon", "country": "USA", "other": 123]`',
'street' => 'street must be present',
'other' => 'other must be a string or must be null',
],
'allOf.2' => 'street must not be empty',
'allOf.3' => 'street must be a string',
],
]
50 changes: 50 additions & 0 deletions tests/integration/issues/1469.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--FILE--
<?php

require 'vendor/autoload.php';

exceptionAll('https://github.com/Respect/Validation/issues/1469', static function (): void {
$data = [
'order_items' => [
[
'product_title' => 'test',
'quantity' => 'test',
],
[
'product_title2' => 'test',
],
],
];

v::arrayVal()->keySet(
v::key('order_items', v::arrayVal()->each(v::keySet(
v::key('product_title', v::stringVal()->notEmpty()),
v::key('quantity', v::intVal()->notEmpty()),
))->notEmpty()),
)->assert($data);
});

?>
--EXPECT--
https://github.com/Respect/Validation/issues/1469
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
quantity must be an integer value
- Each item in order_items must be valid
- order_items validation failed
- quantity must be an integer value
- order_items contains both missing and extra keys
- product_title must be present
- quantity must be present
- product_title2 must not be present
[
'keySet' => [
'__root__' => 'Each item in order_items must be valid',
'keySet.1' => 'quantity must be an integer value',
'keySet.2' => [
'__root__' => 'order_items contains both missing and extra keys',
'product_title' => 'product_title must be present',
'quantity' => 'quantity must be present',
'product_title2' => 'product_title2 must not be present',
],
],
]
28 changes: 28 additions & 0 deletions tests/integration/issues/1477.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--FILE--
<?php

use Respect\Validation\Rules\Core\Simple;

require 'vendor/autoload.php';

exceptionAll('https://github.com/Respect/Validation/issues/1477', static function (): void {
v::key(
'Address',
(new class extends Simple {
protected function isValid(mixed $input): bool
{
return false;
}
})->setTemplate('{{name}} is not good!')
)->assert(['Address' => 'cvejvn']);
});

?>
--EXPECT--
https://github.com/Respect/Validation/issues/1477
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Address is not good!
- Address is not good!
[
'Address' => 'Address is not good!',
]

0 comments on commit ea29c2c

Please sign in to comment.