Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guilliamxavier committed Jun 23, 2021
1 parent 3827aa8 commit 3423667
Showing 1 changed file with 74 additions and 30 deletions.
Expand Up @@ -77,44 +77,88 @@ public function createProvider(): \Generator
{
yield 'empty' => [new Collection(['fields' => []]), new PropertyMetadata(), ['type' => 'object', 'properties' => [], 'additionalProperties' => false]];

$fields = [
'name' => new Required([
new NotBlank(),
]),
'email' => [
new NotNull(),
new Length(['min' => 2, 'max' => 255]),
new Email(['mode' => Email::VALIDATION_MODE_LOOSE]),
],
'phone' => new Optional([
new \Symfony\Component\Validator\Constraints\Type(['type' => 'string']),
new Regex(['pattern' => '/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/']),
]),
'age' => new Optional([
new \Symfony\Component\Validator\Constraints\Type(['type' => 'int']),
]),
'social' => new Collection([
'fields' => [
'githubUsername' => new NotNull(),
],
]),
];
$properties = [
'name' => [],
'email' => ['format' => 'email'],
'phone' => ['pattern' => '^([+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*)$'],
'age' => [],
'social' => ['type' => 'object', 'properties' => ['githubUsername' => []], 'additionalProperties' => false, 'required' => ['githubUsername']],
];
$required = ['name', 'email', 'social'];

yield 'with fields' => [
new Collection([
'fields' => $fields,
]),
new PropertyMetadata(),
[
'type' => 'object',
'properties' => $properties,
'additionalProperties' => false,
'required' => $required,
],
];

yield 'with fields + allowExtraFields' => [
new Collection([
'fields' => $fields,
'allowExtraFields' => true,
'fields' => [
'name' => new Required([
new NotBlank(),
]),
'email' => [
new NotNull(),
new Length(['min' => 2, 'max' => 255]),
new Email(['mode' => Email::VALIDATION_MODE_LOOSE]),
],
'phone' => new Optional([
new \Symfony\Component\Validator\Constraints\Type(['type' => 'string']),
new Regex(['pattern' => '/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/']),
]),
'age' => new Optional([
new \Symfony\Component\Validator\Constraints\Type(['type' => 'int']),
]),
'social' => new Collection([
'fields' => [
'githubUsername' => new NotNull(),
],
]),
],
]),
new PropertyMetadata(),
[
'type' => 'object',
'properties' => [
'name' => [],
'email' => ['format' => 'email'],
'phone' => ['pattern' => '^([+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*)$'],
'age' => [],
'social' => ['type' => 'object', 'properties' => ['githubUsername' => []], 'additionalProperties' => false, 'required' => ['githubUsername']],
],
'properties' => $properties,
'additionalProperties' => true,
'required' => $required,
],
];

yield 'with fields + allowMissingFields' => [
new Collection([
'fields' => $fields,
'allowMissingFields' => true,
]),
new PropertyMetadata(),
[
'type' => 'object',
'properties' => $properties,
'additionalProperties' => false,
],
];

yield 'with fields + allowExtraFields + allowMissingFields' => [
new Collection([
'fields' => $fields,
'allowExtraFields' => true,
'allowMissingFields' => true,
]),
new PropertyMetadata(),
[
'type' => 'object',
'properties' => $properties,
'additionalProperties' => true,
'required' => ['name', 'email', 'social'],
],
];
}
Expand Down

0 comments on commit 3423667

Please sign in to comment.