Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoody committed Dec 1, 2024
1 parent 60840c0 commit 61e9c0c
Showing 1 changed file with 125 additions and 36 deletions.
161 changes: 125 additions & 36 deletions tests/integration/rules/keySet.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,131 @@

require 'vendor/autoload.php';

$input = ['foo' => 42, 'bar' => 'String'];

$missingKeys = v::create()
->keySet(
v::key('foo', v::intVal()),
v::key('bar', v::stringType()),
v::key('baz', v::boolType())
);
$extraKeys = v::create()
->keySet(
v::key('foo', v::intVal()),
v::key('bar', v::stringType()),
);
$correctStructure = v::create()
->keySet(
v::key('foo', v::stringType()),
v::key('bar', v::intType()),
);

exceptionMessage(static fn() => $missingKeys->assert(false));
exceptionMessage(static fn() => $missingKeys->assert($input));
exceptionMessage(static fn() => $extraKeys->assert($input + ['baz' => true]));
exceptionMessage(static fn() => $correctStructure->assert($input));
exceptionFullMessage(static fn() => $missingKeys->assert(false));
exceptionFullMessage(static fn() => $missingKeys->assert($input));
exceptionFullMessage(static fn() => $extraKeys->assert($input + ['baz' => true]));
exceptionFullMessage(static fn() => $correctStructure->assert($input));
run([
'one key() / missing key' => [v::keySet(v::key('foo', v::intType())), []],
'one key() / single extra key' => [v::keySet(v::key('foo', v::intType())), ['foo' => 42, 'bar' => 'string']],
'one key() / multiple extra keys' => [v::keySet(v::key('foo', v::intType())), ['foo' => 42, 'bar' => 'string', 'baz' => true]],
'one key() / failed validation' => [v::keySet(v::key('foo', v::intType())), ['foo' => 'string']],
'multiple key() / all missing keys' => [
v::keySet(v::key('foo', v::intType()), v::key('bar', v::intType())),
[]
],
'multiple key() / single missing key' => [
v::keySet(v::key('foo', v::intType()), v::key('bar', v::intType())),
['foo' => 42]
],
'multiple key() / single extra key' => [
v::keySet(v::key('foo', v::intType()), v::key('bar', v::intType())),
['foo' => 42, 'bar' => 'string', 'baz' => true]
],
'multiple key() / multiple extra keys' => [
v::keySet(v::key('foo', v::intType()), v::key('bar', v::intType())),
['foo' => 42, 'bar' => 'string', 'baz' => true, 'qux' => false]
],
'multiple key() / single failed validation' => [
v::keySet(v::key('foo', v::intType()), v::key('bar', v::intType()), v::key('baz', v::intType())),
['foo' => 42, 'bar' => 'string', 'baz' => 42]
],
'multiple key() / all failed validation' => [
v::keySet(v::key('foo', v::intType()), v::key('bar', v::intType()), v::key('baz', v::intType())),
['foo' => 42, 'bar' => 'string', 'baz' => true]
],
'multiple key() / single missing key / single failed validation' => [
v::keySet(v::key('foo', v::intType()), v::key('bar', v::intType()), v::key('baz', v::intType())),
['foo' => 42, 'bar' => 'string']
],
]);
?>
--EXPECT--
`false` must be of type array
Must have keys `["baz"]` in `["foo": 42, "bar": "String"]`
Must not have keys `["baz"]` in `["foo": 42, "bar": "String", "baz": true]`
foo must be of type string
- `false` must be of type array
- Must have keys `["baz"]` in `["foo": 42, "bar": "String"]`
- Must not have keys `["baz"]` in `["foo": 42, "bar": "String", "baz": true]`
- All of the required rules must pass for `["foo": 42, "bar": "String"]`
- foo must be of type string
one key() / missing key
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Must have keys `["foo"]` in foo
- Must have keys `["foo"]` in foo
[
'keySet' => 'Must have keys `["foo"]` in foo',
]

one key() / single extra key
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Must not have keys `["bar"]` in foo
- Must not have keys `["bar"]` in foo
[
'keySet' => 'Must not have keys `["bar"]` in foo',
]

one key() / multiple extra keys
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Must not have keys `["bar", "baz"]` in foo
- Must not have keys `["bar", "baz"]` in foo
[
'keySet' => 'Must not have keys `["bar", "baz"]` in foo',
]

one key() / failed validation
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
foo must be of type integer
- foo must be of type integer
[
'foo' => 'foo must be of type integer',
]

multiple key() / all missing keys
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Must have keys `["foo", "bar"]` in `[]`
- Must have keys `["foo", "bar"]` in `[]`
[
'keySet' => 'Must have keys `["foo", "bar"]` in `[]`',
]

multiple key() / single missing key
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Must have keys `["bar"]` in `["foo": 42]`
- Must have keys `["bar"]` in `["foo": 42]`
[
'keySet' => 'Must have keys `["bar"]` in `["foo": 42]`',
]

multiple key() / single extra key
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Must not have keys `["baz"]` in `["foo": 42, "bar": "string", "baz": true]`
- Must not have keys `["baz"]` in `["foo": 42, "bar": "string", "baz": true]`
[
'keySet' => 'Must not have keys `["baz"]` in `["foo": 42, "bar": "string", "baz": true]`',
]

multiple key() / multiple extra keys
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Must not have keys `["baz", "qux"]` in `["foo": 42, "bar": "string", "baz": true, "qux": false]`
- Must not have keys `["baz", "qux"]` in `["foo": 42, "bar": "string", "baz": true, "qux": false]`
[
'keySet' => 'Must not have keys `["baz", "qux"]` in `["foo": 42, "bar": "string", "baz": true, "qux": false]`',
]

multiple key() / single failed validation
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
bar must be of type integer
- These rules must pass for `["foo": 42, "bar": "string", "baz": 42]`
- bar must be of type integer
[
'bar' => 'bar must be of type integer',
]

multiple key() / all failed validation
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
bar must be of type integer
- These rules must pass for `["foo": 42, "bar": "string", "baz": true]`
- bar must be of type integer
- baz must be of type integer
[
'__root__' => 'These rules must pass for `["foo": 42, "bar": "string", "baz": true]`',
'bar' => 'bar must be of type integer',
'baz' => 'baz must be of type integer',
]

multiple key() / single missing key / single failed validation
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Must have keys `["baz"]` in `["foo": 42, "bar": "string"]`
- Must have keys `["baz"]` in `["foo": 42, "bar": "string"]`
[
'keySet' => 'Must have keys `["baz"]` in `["foo": 42, "bar": "string"]`',
]

0 comments on commit 61e9c0c

Please sign in to comment.