From ae26d85606ecbf8b82ea4feec81e365904c155e2 Mon Sep 17 00:00:00 2001 From: Yoanm Date: Mon, 10 Apr 2023 18:55:55 +0200 Subject: [PATCH 1/4] Improve FTs --- .../blank-constraints.feature | 51 +++++++---- .../null-constraints.feature | 16 ++-- .../cidr-constraint.feature} | 16 ++-- .../css-color-constraint.feature | 51 +++++++++++ ...ression-language-syntax-constraint.feature | 49 +++++++++++ .../expression-syntax-constraint.feature | 49 +++++++++++ .../hostname-constraint.feature | 52 +++++++++++ .../json-constraint.feature | 52 +++++++++++ .../ulid-constraint.feature | 52 +++++++++++ .../url-constraint.feature | 1 - .../uuid-constraint.feature | 1 - .../divisibleBy-constraints.feature | 44 ++++++++++ .../range-constraints.feature | 17 ++-- ...nique-constraints_fully-configured.feature | 43 +++++++++ .../negative-constraints.feature | 88 +++++++++++++++++++ .../positive-constraints.feature | 88 +++++++++++++++++++ .../date-constraint.feature | 0 .../dateTime-constraint.feature | 0 .../time-constraint.feature | 0 .../timezone-constraint.feature | 50 +++++++++++ .../choice-constraint.feature | 0 .../country-constraint.feature | 0 .../language-constraint.feature | 0 .../locale-constraint.feature | 0 .../file-constraint.feature | 0 .../image-constraint.feature | 52 +++++++++++ .../bic-constraint.feature | 0 .../cardScheme-constraint.feature | 0 .../currency-constraint.feature | 0 .../iban-constraint.feature | 0 .../isbn-constraint.feature | 0 .../isin-constraint.feature | 51 +++++++++++ .../issn-constraint.feature | 0 .../luhn-constraint.feature | 0 .../all-constraint.feature | 4 +- .../callback-constraint.feature | 0 .../cascade-constraint.feature | 45 ++++++++++ .../collection-constraint.feature | 0 .../count-constraint.feature | 0 .../expression-constraint.feature | 0 .../traverse-constraint.feature | 45 ++++++++++ .../valid-constraint.feature | 45 ++++++++++ features/arrayDoc.feature | 3 +- 43 files changed, 922 insertions(+), 43 deletions(-) rename features/{06_file-constraints/url-constraint.feature => 02_string-constraints/cidr-constraint.feature} (83%) create mode 100644 features/02_string-constraints/css-color-constraint.feature create mode 100644 features/02_string-constraints/expression-language-syntax-constraint.feature create mode 100644 features/02_string-constraints/expression-syntax-constraint.feature create mode 100644 features/02_string-constraints/hostname-constraint.feature create mode 100644 features/02_string-constraints/json-constraint.feature create mode 100644 features/02_string-constraints/ulid-constraint.feature create mode 100644 features/03_comparaison-constraints/divisibleBy-constraints.feature create mode 100644 features/03_comparaison-constraints/unique-constraints_fully-configured.feature create mode 100644 features/04_number-constraints/negative-constraints.feature create mode 100644 features/04_number-constraints/positive-constraints.feature rename features/{04_date-constraints => 05_date-constraints}/date-constraint.feature (100%) rename features/{04_date-constraints => 05_date-constraints}/dateTime-constraint.feature (100%) rename features/{04_date-constraints => 05_date-constraints}/time-constraint.feature (100%) create mode 100644 features/05_date-constraints/timezone-constraint.feature rename features/{05_collection-constraints => 06-choice-constraints}/choice-constraint.feature (100%) rename features/{05_collection-constraints => 06-choice-constraints}/country-constraint.feature (100%) rename features/{05_collection-constraints => 06-choice-constraints}/language-constraint.feature (100%) rename features/{05_collection-constraints => 06-choice-constraints}/locale-constraint.feature (100%) rename features/{06_file-constraints => 07_file-constraints}/file-constraint.feature (100%) create mode 100644 features/07_file-constraints/image-constraint.feature rename features/{07_financial_and_other_number_constraints => 08_financial_and_other_number_constraints}/bic-constraint.feature (100%) rename features/{07_financial_and_other_number_constraints => 08_financial_and_other_number_constraints}/cardScheme-constraint.feature (100%) rename features/{07_financial_and_other_number_constraints => 08_financial_and_other_number_constraints}/currency-constraint.feature (100%) rename features/{07_financial_and_other_number_constraints => 08_financial_and_other_number_constraints}/iban-constraint.feature (100%) rename features/{07_financial_and_other_number_constraints => 08_financial_and_other_number_constraints}/isbn-constraint.feature (100%) create mode 100644 features/08_financial_and_other_number_constraints/isin-constraint.feature rename features/{07_financial_and_other_number_constraints => 08_financial_and_other_number_constraints}/issn-constraint.feature (100%) rename features/{07_financial_and_other_number_constraints => 08_financial_and_other_number_constraints}/luhn-constraint.feature (100%) rename features/{08_others-constraints => 09_others-constraints}/all-constraint.feature (97%) rename features/{08_others-constraints => 09_others-constraints}/callback-constraint.feature (100%) create mode 100644 features/09_others-constraints/cascade-constraint.feature rename features/{05_collection-constraints => 09_others-constraints}/collection-constraint.feature (100%) rename features/{05_collection-constraints => 09_others-constraints}/count-constraint.feature (100%) rename features/{08_others-constraints => 09_others-constraints}/expression-constraint.feature (100%) create mode 100644 features/09_others-constraints/traverse-constraint.feature create mode 100644 features/09_others-constraints/valid-constraint.feature diff --git a/features/01_basic-constraints/blank-constraints.feature b/features/01_basic-constraints/blank-constraints.feature index e5b0cc0..2c9a464 100644 --- a/features/01_basic-constraints/blank-constraints.feature +++ b/features/01_basic-constraints/blank-constraints.feature @@ -23,7 +23,12 @@ Feature: ConstraintToParamsDocTransformer - NotBlank & Blank constraints return new ConstraintNS\NotBlank([ 'payload' => [ 'documentation' => [ - 'type' => 'string' + 'type' => 'string', + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false ] ] ]); @@ -33,11 +38,11 @@ Feature: ConstraintToParamsDocTransformer - NotBlank & Blank constraints And constraint doc "getMinLength" should return the number 1 ## Check others properties And constraint doc "getName" should return null - And constraint doc "getDescription" should return null - And constraint doc "getDefault" should return null - And constraint doc "getExample" should return null - And constraint doc "isRequired" should return false - And constraint doc "isNullable" should return true + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isRequired" should return true + And constraint doc "isNullable" should return false And constraint doc "getAllowedValueList" should return an empty array And constraint doc "getFormat" should return null And constraint doc "getMaxLength" should return null @@ -49,7 +54,12 @@ Feature: ConstraintToParamsDocTransformer - NotBlank & Blank constraints return new ConstraintNS\NotBlank([ 'payload' => [ 'documentation' => [ - 'type' => 'array' + 'type' => 'array', + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false ] ] ]); @@ -59,11 +69,11 @@ Feature: ConstraintToParamsDocTransformer - NotBlank & Blank constraints And constraint doc "getMinItem" should return the number 1 ## Check others properties And constraint doc "getName" should return null - And constraint doc "getDescription" should return null - And constraint doc "getDefault" should return null - And constraint doc "getExample" should return null - And constraint doc "isRequired" should return false - And constraint doc "isNullable" should return true + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isRequired" should return true + And constraint doc "isNullable" should return false And constraint doc "getAllowedValueList" should return an empty array And constraint doc "getSiblingList" should return an empty array And constraint doc "getMaxItem" should return null @@ -78,7 +88,12 @@ Feature: ConstraintToParamsDocTransformer - NotBlank & Blank constraints return new ConstraintNS\Blank([ 'payload' => [ 'documentation' => [ - 'type' => 'string' + 'type' => 'string', + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false ] ] ]); @@ -88,11 +103,11 @@ Feature: ConstraintToParamsDocTransformer - NotBlank & Blank constraints And constraint doc "getMaxLength" should return the number 0 ## Check others properties And constraint doc "getName" should return null - And constraint doc "getDescription" should return null - And constraint doc "getDefault" should return null - And constraint doc "getExample" should return null - And constraint doc "isRequired" should return false - And constraint doc "isNullable" should return true + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isRequired" should return true + And constraint doc "isNullable" should return false And constraint doc "getAllowedValueList" should return an empty array And constraint doc "getFormat" should return null And constraint doc "getMinLength" should return null diff --git a/features/01_basic-constraints/null-constraints.feature b/features/01_basic-constraints/null-constraints.feature index d71d91e..4877039 100644 --- a/features/01_basic-constraints/null-constraints.feature +++ b/features/01_basic-constraints/null-constraints.feature @@ -27,7 +27,12 @@ Feature: ConstraintToParamsDocTransformer - NotNull & IsNull constraints return new ConstraintNS\NotNull([ 'payload' => [ 'documentation' => [ - 'type' => 'string' + 'type' => 'string', + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false ] ] ]); @@ -37,10 +42,11 @@ Feature: ConstraintToParamsDocTransformer - NotNull & IsNull constraints And constraint doc "isNullable" should return false ## Check others properties And constraint doc "getName" should return null - And constraint doc "getDescription" should return null - And constraint doc "getDefault" should return null - And constraint doc "getExample" should return null - And constraint doc "isRequired" should return false + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isRequired" should return true + And constraint doc "isNullable" should return false And constraint doc "getAllowedValueList" should return an empty array And constraint doc "getFormat" should return null And constraint doc "getMinLength" should return null diff --git a/features/06_file-constraints/url-constraint.feature b/features/02_string-constraints/cidr-constraint.feature similarity index 83% rename from features/06_file-constraints/url-constraint.feature rename to features/02_string-constraints/cidr-constraint.feature index 4dc6bb8..fc78624 100644 --- a/features/06_file-constraints/url-constraint.feature +++ b/features/02_string-constraints/cidr-constraint.feature @@ -1,14 +1,14 @@ -Feature: ConstraintToParamsDocTransformer - Url constraint +Feature: ConstraintToParamsDocTransformer - Cidr constraint - Scenario: Simple Url constraint + Scenario: Simple Cidr constraint Given I have the following Constraint: """ use Symfony\Component\Validator\Constraints as ConstraintNS; - return new ConstraintNS\Url(); + return new ConstraintNS\Cidr(); """ When I transform constraint Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" - And constraint doc "getFormat" should return the value "url" + And constraint doc "getFormat" should return the value "cidr" ## Check others properties And constraint doc "getName" should return null And constraint doc "getDescription" should return null @@ -20,12 +20,11 @@ Feature: ConstraintToParamsDocTransformer - Url constraint And constraint doc "getMinLength" should return null And constraint doc "getMaxLength" should return null - Scenario: Fully configured Url constraint + Scenario: Fully configured Cidr constraint Given I have the following Constraint: """ use Symfony\Component\Validator\Constraints as ConstraintNS; - return new ConstraintNS\Url([ - 'protocols' => ['http'], + return new ConstraintNS\Cidr([ 'payload' => [ 'documentation' => [ 'description' => 'description', @@ -39,7 +38,7 @@ Feature: ConstraintToParamsDocTransformer - Url constraint """ When I transform constraint Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" - And constraint doc "getFormat" should return the value "url" + And constraint doc "getFormat" should return the value "cidr" And constraint doc "getDescription" should return the value "description" And constraint doc "getDefault" should return the value "default" And constraint doc "getExample" should return the value "example" @@ -50,3 +49,4 @@ Feature: ConstraintToParamsDocTransformer - Url constraint And constraint doc "getAllowedValueList" should return an empty array And constraint doc "getMinLength" should return null And constraint doc "getMaxLength" should return null + diff --git a/features/02_string-constraints/css-color-constraint.feature b/features/02_string-constraints/css-color-constraint.feature new file mode 100644 index 0000000..23a7b11 --- /dev/null +++ b/features/02_string-constraints/css-color-constraint.feature @@ -0,0 +1,51 @@ +Feature: ConstraintToParamsDocTransformer - CssColor constraint + + Scenario: Simple CssColor constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\CssColor(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured CssColor constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\CssColor([ + 'formats' => ConstraintNS\CssColor::HEX_LONG, + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + diff --git a/features/02_string-constraints/expression-language-syntax-constraint.feature b/features/02_string-constraints/expression-language-syntax-constraint.feature new file mode 100644 index 0000000..f6141e5 --- /dev/null +++ b/features/02_string-constraints/expression-language-syntax-constraint.feature @@ -0,0 +1,49 @@ +Feature: ConstraintToParamsDocTransformer - ExpressionLanguageSyntax constraint + + Scenario: Simple ExpressionLanguageSyntax constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\ExpressionLanguageSyntax(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured ExpressionLanguageSyntax constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\ExpressionLanguageSyntax([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null diff --git a/features/02_string-constraints/expression-syntax-constraint.feature b/features/02_string-constraints/expression-syntax-constraint.feature new file mode 100644 index 0000000..2dba750 --- /dev/null +++ b/features/02_string-constraints/expression-syntax-constraint.feature @@ -0,0 +1,49 @@ +Feature: ConstraintToParamsDocTransformer - ExpressionSyntax constraint + + Scenario: Simple ExpressionSyntax constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\ExpressionSyntax(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured ExpressionSyntax constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\ExpressionSyntax([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null diff --git a/features/02_string-constraints/hostname-constraint.feature b/features/02_string-constraints/hostname-constraint.feature new file mode 100644 index 0000000..2e07eef --- /dev/null +++ b/features/02_string-constraints/hostname-constraint.feature @@ -0,0 +1,52 @@ +Feature: ConstraintToParamsDocTransformer - Hostname constraint + + Scenario: Simple Hostname constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Hostname(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "hostname" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured Hostname constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Hostname([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "hostname" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + diff --git a/features/02_string-constraints/json-constraint.feature b/features/02_string-constraints/json-constraint.feature new file mode 100644 index 0000000..4d42893 --- /dev/null +++ b/features/02_string-constraints/json-constraint.feature @@ -0,0 +1,52 @@ +Feature: ConstraintToParamsDocTransformer - Json constraint + + Scenario: Simple Json constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Json(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "json" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured Json constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Json([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "json" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + diff --git a/features/02_string-constraints/ulid-constraint.feature b/features/02_string-constraints/ulid-constraint.feature new file mode 100644 index 0000000..9e6d437 --- /dev/null +++ b/features/02_string-constraints/ulid-constraint.feature @@ -0,0 +1,52 @@ +Feature: ConstraintToParamsDocTransformer - Ulid constraint + + Scenario: Simple Ulid constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Ulid(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "ulid" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured Ulid constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Ulid([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "ulid" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + diff --git a/features/02_string-constraints/url-constraint.feature b/features/02_string-constraints/url-constraint.feature index 66ced99..1709e20 100644 --- a/features/02_string-constraints/url-constraint.feature +++ b/features/02_string-constraints/url-constraint.feature @@ -27,7 +27,6 @@ Feature: ConstraintToParamsDocTransformer - Url constraint return new ConstraintNS\Url([ 'payload' => [ 'documentation' => [ - 'type' => 'string', 'description' => 'description', 'default' => 'default', 'example' => 'example', diff --git a/features/02_string-constraints/uuid-constraint.feature b/features/02_string-constraints/uuid-constraint.feature index 344dc39..0b6eae9 100644 --- a/features/02_string-constraints/uuid-constraint.feature +++ b/features/02_string-constraints/uuid-constraint.feature @@ -29,7 +29,6 @@ Feature: ConstraintToParamsDocTransformer - Uuid constraint 'versions' => [3, 4, 5], 'payload' => [ 'documentation' => [ - 'type' => 'string', 'default' => 'default', 'example' => 'example', 'required' => true, diff --git a/features/03_comparaison-constraints/divisibleBy-constraints.feature b/features/03_comparaison-constraints/divisibleBy-constraints.feature new file mode 100644 index 0000000..10507b7 --- /dev/null +++ b/features/03_comparaison-constraints/divisibleBy-constraints.feature @@ -0,0 +1,44 @@ +Feature: ConstraintToParamsDocTransformer - DivisibleBy constraint + + Scenario: Simple DivisibleBy constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\DivisibleBy(0.25); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + + Scenario: Fully configured DivisibleBy constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\DivisibleBy([ + 'value' => 5, + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null diff --git a/features/03_comparaison-constraints/range-constraints.feature b/features/03_comparaison-constraints/range-constraints.feature index c70e7a9..552f40f 100644 --- a/features/03_comparaison-constraints/range-constraints.feature +++ b/features/03_comparaison-constraints/range-constraints.feature @@ -87,7 +87,12 @@ Feature: ConstraintToParamsDocTransformer - Range constraint 'max' => '2018-11-15', 'payload' => [ 'documentation' => [ - 'type' => 'string' + 'type' => 'string', + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false ] ] ]); @@ -97,11 +102,11 @@ Feature: ConstraintToParamsDocTransformer - Range constraint And constraint doc "getFormat" should return the value "datetime" ## Check others properties And constraint doc "getName" should return null - And constraint doc "getDescription" should return null - And constraint doc "getDefault" should return null - And constraint doc "getExample" should return null - And constraint doc "isNullable" should return true - And constraint doc "isRequired" should return false + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true And constraint doc "getAllowedValueList" should return an empty array And constraint doc "getMinLength" should return null And constraint doc "getMaxLength" should return null diff --git a/features/03_comparaison-constraints/unique-constraints_fully-configured.feature b/features/03_comparaison-constraints/unique-constraints_fully-configured.feature new file mode 100644 index 0000000..5e68e8b --- /dev/null +++ b/features/03_comparaison-constraints/unique-constraints_fully-configured.feature @@ -0,0 +1,43 @@ +Feature: ConstraintToParamsDocTransformer - Unique constraint + + Scenario: Simple Unique constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Unique(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\CollectionDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + + Scenario: Fully configured Unique constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Unique([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\CollectionDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null diff --git a/features/04_number-constraints/negative-constraints.feature b/features/04_number-constraints/negative-constraints.feature new file mode 100644 index 0000000..31c2fb9 --- /dev/null +++ b/features/04_number-constraints/negative-constraints.feature @@ -0,0 +1,88 @@ +Feature: ConstraintToParamsDocTransformer - Negative & NegativeOrZero constraint + + Scenario: Simple Negative constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Negative(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + + Scenario: Simple NegativeOrZero constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\NegativeOrZero(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + + + Scenario: Fully configured Negative constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Negative([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + + Scenario: Fully configured NegativeOrZero constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\NegativeOrZero([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array diff --git a/features/04_number-constraints/positive-constraints.feature b/features/04_number-constraints/positive-constraints.feature new file mode 100644 index 0000000..f04c604 --- /dev/null +++ b/features/04_number-constraints/positive-constraints.feature @@ -0,0 +1,88 @@ +Feature: ConstraintToParamsDocTransformer - Positive & PositiveOrZero constraint + + Scenario: Simple Positive constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Positive(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + + Scenario: Simple PositiveOrZero constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\PositiveOrZero(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + + + Scenario: Fully configured Positive constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Positive([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + + Scenario: Fully configured PositiveOrZero constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\PositiveOrZero([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\NumberDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array diff --git a/features/04_date-constraints/date-constraint.feature b/features/05_date-constraints/date-constraint.feature similarity index 100% rename from features/04_date-constraints/date-constraint.feature rename to features/05_date-constraints/date-constraint.feature diff --git a/features/04_date-constraints/dateTime-constraint.feature b/features/05_date-constraints/dateTime-constraint.feature similarity index 100% rename from features/04_date-constraints/dateTime-constraint.feature rename to features/05_date-constraints/dateTime-constraint.feature diff --git a/features/04_date-constraints/time-constraint.feature b/features/05_date-constraints/time-constraint.feature similarity index 100% rename from features/04_date-constraints/time-constraint.feature rename to features/05_date-constraints/time-constraint.feature diff --git a/features/05_date-constraints/timezone-constraint.feature b/features/05_date-constraints/timezone-constraint.feature new file mode 100644 index 0000000..7fb6cfd --- /dev/null +++ b/features/05_date-constraints/timezone-constraint.feature @@ -0,0 +1,50 @@ +Feature: ConstraintToParamsDocTransformer - Timezone constraint + + Scenario: Simple Timezone constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Timezone(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured Timezone constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Timezone([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + diff --git a/features/05_collection-constraints/choice-constraint.feature b/features/06-choice-constraints/choice-constraint.feature similarity index 100% rename from features/05_collection-constraints/choice-constraint.feature rename to features/06-choice-constraints/choice-constraint.feature diff --git a/features/05_collection-constraints/country-constraint.feature b/features/06-choice-constraints/country-constraint.feature similarity index 100% rename from features/05_collection-constraints/country-constraint.feature rename to features/06-choice-constraints/country-constraint.feature diff --git a/features/05_collection-constraints/language-constraint.feature b/features/06-choice-constraints/language-constraint.feature similarity index 100% rename from features/05_collection-constraints/language-constraint.feature rename to features/06-choice-constraints/language-constraint.feature diff --git a/features/05_collection-constraints/locale-constraint.feature b/features/06-choice-constraints/locale-constraint.feature similarity index 100% rename from features/05_collection-constraints/locale-constraint.feature rename to features/06-choice-constraints/locale-constraint.feature diff --git a/features/06_file-constraints/file-constraint.feature b/features/07_file-constraints/file-constraint.feature similarity index 100% rename from features/06_file-constraints/file-constraint.feature rename to features/07_file-constraints/file-constraint.feature diff --git a/features/07_file-constraints/image-constraint.feature b/features/07_file-constraints/image-constraint.feature new file mode 100644 index 0000000..8fdc8ee --- /dev/null +++ b/features/07_file-constraints/image-constraint.feature @@ -0,0 +1,52 @@ +Feature: ConstraintToParamsDocTransformer - Image constraint + + Scenario: Simple Image constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Image(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "image" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured Image constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Image([ + 'maxSize' => 2000, + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "image" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null diff --git a/features/07_financial_and_other_number_constraints/bic-constraint.feature b/features/08_financial_and_other_number_constraints/bic-constraint.feature similarity index 100% rename from features/07_financial_and_other_number_constraints/bic-constraint.feature rename to features/08_financial_and_other_number_constraints/bic-constraint.feature diff --git a/features/07_financial_and_other_number_constraints/cardScheme-constraint.feature b/features/08_financial_and_other_number_constraints/cardScheme-constraint.feature similarity index 100% rename from features/07_financial_and_other_number_constraints/cardScheme-constraint.feature rename to features/08_financial_and_other_number_constraints/cardScheme-constraint.feature diff --git a/features/07_financial_and_other_number_constraints/currency-constraint.feature b/features/08_financial_and_other_number_constraints/currency-constraint.feature similarity index 100% rename from features/07_financial_and_other_number_constraints/currency-constraint.feature rename to features/08_financial_and_other_number_constraints/currency-constraint.feature diff --git a/features/07_financial_and_other_number_constraints/iban-constraint.feature b/features/08_financial_and_other_number_constraints/iban-constraint.feature similarity index 100% rename from features/07_financial_and_other_number_constraints/iban-constraint.feature rename to features/08_financial_and_other_number_constraints/iban-constraint.feature diff --git a/features/07_financial_and_other_number_constraints/isbn-constraint.feature b/features/08_financial_and_other_number_constraints/isbn-constraint.feature similarity index 100% rename from features/07_financial_and_other_number_constraints/isbn-constraint.feature rename to features/08_financial_and_other_number_constraints/isbn-constraint.feature diff --git a/features/08_financial_and_other_number_constraints/isin-constraint.feature b/features/08_financial_and_other_number_constraints/isin-constraint.feature new file mode 100644 index 0000000..4d73080 --- /dev/null +++ b/features/08_financial_and_other_number_constraints/isin-constraint.feature @@ -0,0 +1,51 @@ +Feature: ConstraintToParamsDocTransformer - Isin constraint + + Scenario: Simple Isin constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Isin(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "isin" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null + + Scenario: Fully configured Isin constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Isin([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" + And constraint doc "getFormat" should return the value "isin" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array + And constraint doc "getMinLength" should return null + And constraint doc "getMaxLength" should return null diff --git a/features/07_financial_and_other_number_constraints/issn-constraint.feature b/features/08_financial_and_other_number_constraints/issn-constraint.feature similarity index 100% rename from features/07_financial_and_other_number_constraints/issn-constraint.feature rename to features/08_financial_and_other_number_constraints/issn-constraint.feature diff --git a/features/07_financial_and_other_number_constraints/luhn-constraint.feature b/features/08_financial_and_other_number_constraints/luhn-constraint.feature similarity index 100% rename from features/07_financial_and_other_number_constraints/luhn-constraint.feature rename to features/08_financial_and_other_number_constraints/luhn-constraint.feature diff --git a/features/08_others-constraints/all-constraint.feature b/features/09_others-constraints/all-constraint.feature similarity index 97% rename from features/08_others-constraints/all-constraint.feature rename to features/09_others-constraints/all-constraint.feature index a63eec5..d3504a8 100644 --- a/features/08_others-constraints/all-constraint.feature +++ b/features/09_others-constraints/all-constraint.feature @@ -7,7 +7,7 @@ Feature: ConstraintToParamsDocTransformer - All constraint return new ConstraintNS\All([new ConstraintNS\Type('string')]); """ When I transform constraint - Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ArrayDoc" + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\CollectionDoc" And constraint doc item validation should be of type "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" ## Check others properties And constraint doc "getName" should return null @@ -41,7 +41,7 @@ Feature: ConstraintToParamsDocTransformer - All constraint ]); """ When I transform constraint - Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ArrayDoc" + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\CollectionDoc" And constraint doc item validation should be of type "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" And constraint doc "getDescription" should return the value "description" And constraint doc "getDefault" should return the value "default" diff --git a/features/08_others-constraints/callback-constraint.feature b/features/09_others-constraints/callback-constraint.feature similarity index 100% rename from features/08_others-constraints/callback-constraint.feature rename to features/09_others-constraints/callback-constraint.feature diff --git a/features/09_others-constraints/cascade-constraint.feature b/features/09_others-constraints/cascade-constraint.feature new file mode 100644 index 0000000..49dae83 --- /dev/null +++ b/features/09_others-constraints/cascade-constraint.feature @@ -0,0 +1,45 @@ +Feature: ConstraintToParamsDocTransformer - Cascade constraint + + Scenario: Simple Cascade constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Cascade(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + + Scenario: Fully configured Cascade constraint with string type specified + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Cascade([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array diff --git a/features/05_collection-constraints/collection-constraint.feature b/features/09_others-constraints/collection-constraint.feature similarity index 100% rename from features/05_collection-constraints/collection-constraint.feature rename to features/09_others-constraints/collection-constraint.feature diff --git a/features/05_collection-constraints/count-constraint.feature b/features/09_others-constraints/count-constraint.feature similarity index 100% rename from features/05_collection-constraints/count-constraint.feature rename to features/09_others-constraints/count-constraint.feature diff --git a/features/08_others-constraints/expression-constraint.feature b/features/09_others-constraints/expression-constraint.feature similarity index 100% rename from features/08_others-constraints/expression-constraint.feature rename to features/09_others-constraints/expression-constraint.feature diff --git a/features/09_others-constraints/traverse-constraint.feature b/features/09_others-constraints/traverse-constraint.feature new file mode 100644 index 0000000..0775169 --- /dev/null +++ b/features/09_others-constraints/traverse-constraint.feature @@ -0,0 +1,45 @@ +Feature: ConstraintToParamsDocTransformer - Traverse constraint + + Scenario: Simple Traverse constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Traverse(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + + Scenario: Fully configured Traverse constraint with string type specified + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Traverse([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array diff --git a/features/09_others-constraints/valid-constraint.feature b/features/09_others-constraints/valid-constraint.feature new file mode 100644 index 0000000..5fef27c --- /dev/null +++ b/features/09_others-constraints/valid-constraint.feature @@ -0,0 +1,45 @@ +Feature: ConstraintToParamsDocTransformer - Valid constraint + + Scenario: Simple Valid constraint + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Valid(); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc" + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getDescription" should return null + And constraint doc "getDefault" should return null + And constraint doc "getExample" should return null + And constraint doc "isNullable" should return true + And constraint doc "isRequired" should return false + And constraint doc "getAllowedValueList" should return an empty array + + Scenario: Fully configured Valid constraint with string type specified + Given I have the following Constraint: + """ + use Symfony\Component\Validator\Constraints as ConstraintNS; + return new ConstraintNS\Valid([ + 'payload' => [ + 'documentation' => [ + 'description' => 'description', + 'default' => 'default', + 'example' => 'example', + 'required' => true, + 'nullable' => false + ] + ] + ]); + """ + When I transform constraint + Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc" + And constraint doc "getDescription" should return the value "description" + And constraint doc "getDefault" should return the value "default" + And constraint doc "getExample" should return the value "example" + And constraint doc "isNullable" should return false + And constraint doc "isRequired" should return true + ## Check others properties + And constraint doc "getName" should return null + And constraint doc "getAllowedValueList" should return an empty array diff --git a/features/arrayDoc.feature b/features/arrayDoc.feature index 7b48a60..b83d729 100644 --- a/features/arrayDoc.feature +++ b/features/arrayDoc.feature @@ -4,11 +4,10 @@ Feature: ConstraintToParamsDocTransformer - Special constraint Given I have the following Constraint: """ use Symfony\Component\Validator\Constraints as ConstraintNS; - return new ConstraintNS\All([new ConstraintNS\Type('string')]); + return new ConstraintNS\Type('array'); """ When I transform constraint Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ArrayDoc" - And constraint doc item validation should be of type "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc" ## Check others properties And constraint doc "getName" should return null And constraint doc "getDescription" should return null From 6e77fcb028bedad74de32b4ed8f98306e1e95b7b Mon Sep 17 00:00:00 2001 From: Yoanm Date: Mon, 10 Apr 2023 18:57:08 +0200 Subject: [PATCH 2/4] Fixes --- src/App/Helper/StringDocHelper.php | 6 ++ src/App/Helper/TypeGuesser.php | 89 ++++++++++++------- .../ConstraintToParamsDocTransformer.php | 6 +- 3 files changed, 68 insertions(+), 33 deletions(-) diff --git a/src/App/Helper/StringDocHelper.php b/src/App/Helper/StringDocHelper.php index 8a2580e..4030c53 100644 --- a/src/App/Helper/StringDocHelper.php +++ b/src/App/Helper/StringDocHelper.php @@ -33,6 +33,12 @@ class StringDocHelper Constraints\Time::class, Constraints\Url::class, Constraints\Uuid::class, + Constraints\Hostname::class, + Constraints\Cidr::class, + Constraints\Json::class, + Constraints\Ulid::class, + Constraints\Image::class, + Constraints\Isin::class, ]; const CONSTRAINT_WITH_FORMAT_FROM_PROPERTY = [ diff --git a/src/App/Helper/TypeGuesser.php b/src/App/Helper/TypeGuesser.php index 8a37d83..6818f16 100644 --- a/src/App/Helper/TypeGuesser.php +++ b/src/App/Helper/TypeGuesser.php @@ -38,11 +38,41 @@ class TypeGuesser Assert\Luhn::class, Assert\Url::class, Assert\Uuid::class, + Assert\ExpressionSyntax::class, + Assert\ExpressionLanguageSyntax::class, + Assert\Hostname::class, + Assert\Cidr::class, + Assert\Json::class, + Assert\Ulid::class, + Assert\CssColor::class, + Assert\Timezone::class, + Assert\Isin::class, + Assert\Blank::class, + ]; + const NUMBER_CONSTRAINT_CLASS_LIST = [ + Assert\DivisibleBy::class, + Assert\Positive::class, + Assert\PositiveOrZero::class, + Assert\Negative::class, + Assert\NegativeOrZero::class, ]; const BOOLEAN_CONSTRAINT_CLASS_LIST = [ Assert\IsTrue::class, Assert\IsFalse::class, ]; + const OBJECT_CONSTRAINT_CLASS_LIST = [ + Assert\Valid::class, + Assert\Cascade::class, + Assert\Traverse::class, + ]; + const COLLECTION_CONSTRAINT_CLASS_LIST = [ + // Count is primarily applied on array, but can also be used with an object implementing Countable + Assert\Count::class, + // All is primarily applied on array, but can also be used with an object implementing Traversable + Assert\All::class, + // Unique is primarily applied on array, but can also be used with an object implementing Traversable + Assert\Unique::class, + ]; /** * @param array $constraintList @@ -79,13 +109,15 @@ public function guessTypeFromConstraintList(array $constraintList) : ?TypeDoc */ protected function guessTypeFromConstraint(Constraint $constraint) : ?TypeDoc { - if (null !== ($type = $this->guessPrimaryTypeFromConstraint($constraint))) { + // Try to guess primary types + $type = $this->guessSimplePrimaryTypeFromConstraint($constraint); + if (null !== $type) { return $type; - } - - // If primary type is still not defined - $constraintClass = get_class($constraint); - if (Assert\Count::class == $constraintClass) { + } elseif ($constraint instanceof Assert\DateTime) { + return $this->guessDateTimeType($constraint); + } elseif ($constraint instanceof Assert\Collection) { + return $this->guessCollectionType($constraint); + } elseif ($this->isCollectionType($constraint)) { return new CollectionDoc(); } @@ -108,25 +140,6 @@ private function isAbstractType(TypeDoc $doc) : bool ; } - /** - * @param Constraint $constraint - * - * @return null|ArrayDoc|BooleanDoc|ObjectDoc|ScalarDoc|StringDoc - */ - private function guessPrimaryTypeFromConstraint(Constraint $constraint) : ?TypeDoc - { - // Try to guess primary types - if (null !== ($type = $this->guessSimplePrimaryTypeFromConstraint($constraint))) { - return $type; - } elseif ($constraint instanceof Assert\DateTime) { - return $this->guessDateTimeType($constraint); - } elseif ($constraint instanceof Assert\Collection) { - return $this->guestCollectionType($constraint); - } - - return null; - } - /** * @param Assert\DateTime $constraint * @@ -146,10 +159,10 @@ private function guessDateTimeType(Assert\DateTime $constraint) : TypeDoc * * @return ArrayDoc|ObjectDoc */ - private function guestCollectionType(Assert\Collection $constraint) : TypeDoc + private function guessCollectionType(Assert\Collection $constraint) : TypeDoc { - // If only integer => array, else object - $integerKeyList = array_filter(array_keys($constraint->fields), 'is_int'); + // If only integer keys (strict check) => array, else object + $integerKeyList = array_filter(array_keys($constraint->fields), fn ($v) => (int)$v === $v); if (count($constraint->fields) === count($integerKeyList)) { return new ArrayDoc(); } @@ -164,12 +177,24 @@ private function guestCollectionType(Assert\Collection $constraint) : TypeDoc */ private function isArrayConstraint(Constraint $constraint): bool { - return $constraint instanceof Assert\All // << Applied only on array - || ($constraint instanceof Assert\Choice + return ($constraint instanceof Assert\Choice && true === $constraint->multiple // << expect an array multiple choices ); } + private function isObjectType(Constraint $constraint): bool + { + return null !== $this->getMatchingClassNameIn($constraint, self::OBJECT_CONSTRAINT_CLASS_LIST); + } + + /** + * Must be called at the end in case all others checks failed ! + */ + private function isCollectionType(Constraint $constraint): bool + { + return null !== $this->getMatchingClassNameIn($constraint, self::COLLECTION_CONSTRAINT_CLASS_LIST); + } + /** * @param Constraint $constraint * @@ -181,10 +206,14 @@ private function guessSimplePrimaryTypeFromConstraint(Constraint $constraint) : return new StringDoc(); } elseif (null !== $this->getMatchingClassNameIn($constraint, self::BOOLEAN_CONSTRAINT_CLASS_LIST)) { return new BooleanDoc(); + } elseif (null !== $this->getMatchingClassNameIn($constraint, self::NUMBER_CONSTRAINT_CLASS_LIST)) { + return new NumberDoc(); } elseif ($constraint instanceof Assert\Regex) { return new ScalarDoc(); } elseif ($this->isArrayConstraint($constraint)) { return new ArrayDoc(); + } elseif ($this->isObjectType($constraint)) { + return new ObjectDoc(); } return null; diff --git a/src/Infra/Transformer/ConstraintToParamsDocTransformer.php b/src/Infra/Transformer/ConstraintToParamsDocTransformer.php index 7930c7a..5fd1da7 100644 --- a/src/Infra/Transformer/ConstraintToParamsDocTransformer.php +++ b/src/Infra/Transformer/ConstraintToParamsDocTransformer.php @@ -111,7 +111,7 @@ private function appendToDoc(TypeDoc $doc, Constraint $constraint) : void foreach ($callbackResultList as $subConstraint) { $this->appendToDoc($doc, $subConstraint); } - } elseif ($doc instanceof ArrayDoc && $constraint instanceof Assert\All) { + } elseif ($doc instanceof CollectionDoc && $constraint instanceof Assert\All) { $this->appendAllConstraintToDoc($doc, $constraint); } else { $this->basicAppendToDoc($doc, $constraint); @@ -171,12 +171,12 @@ private function appendValidItemListDoc(TypeDoc $doc, Constraint $constraint) : } /** - * @param ArrayDoc $doc + * @param CollectionDoc $doc * @param Assert\All $constraint * * @throws \ReflectionException */ - private function appendAllConstraintToDoc(ArrayDoc $doc, Assert\All $constraint) : void + private function appendAllConstraintToDoc(CollectionDoc $doc, Assert\All $constraint) : void { $itemDoc = $this->docTypeHelper->guess($constraint->constraints); foreach ($constraint->constraints as $subConstraint) { From 21ae6e2090c2aaa45d18541137e2d5494f250c41 Mon Sep 17 00:00:00 2001 From: Yoanm Date: Mon, 10 Apr 2023 19:03:44 +0200 Subject: [PATCH 3/4] Improve --- src/App/Helper/TypeGuesser.php | 21 ++++++++++++++++--- .../ConstraintToParamsDocTransformer.php | 3 --- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/App/Helper/TypeGuesser.php b/src/App/Helper/TypeGuesser.php index 6818f16..ab85681 100644 --- a/src/App/Helper/TypeGuesser.php +++ b/src/App/Helper/TypeGuesser.php @@ -170,6 +170,21 @@ private function guessCollectionType(Assert\Collection $constraint) : TypeDoc return new ObjectDoc(); } + private function isStringConstraint(Constraint $constraint): bool + { + return null !== $this->getMatchingClassNameIn($constraint, self::STRING_CONSTRAINT_CLASS_LIST); + } + + private function isBooleanConstraint(Constraint $constraint): bool + { + return null !== $this->getMatchingClassNameIn($constraint, self::BOOLEAN_CONSTRAINT_CLASS_LIST); + } + + private function isNumberConstraint(Constraint $constraint): bool + { + return null !== $this->getMatchingClassNameIn($constraint, self::NUMBER_CONSTRAINT_CLASS_LIST); + } + /** * @param Constraint $constraint * @@ -202,11 +217,11 @@ private function isCollectionType(Constraint $constraint): bool */ private function guessSimplePrimaryTypeFromConstraint(Constraint $constraint) : ?TypeDoc { - if (null !== $this->getMatchingClassNameIn($constraint, self::STRING_CONSTRAINT_CLASS_LIST)) { + if ($this->isStringConstraint($constraint)) { return new StringDoc(); - } elseif (null !== $this->getMatchingClassNameIn($constraint, self::BOOLEAN_CONSTRAINT_CLASS_LIST)) { + } elseif ($this->isBooleanConstraint($constraint)) { return new BooleanDoc(); - } elseif (null !== $this->getMatchingClassNameIn($constraint, self::NUMBER_CONSTRAINT_CLASS_LIST)) { + } elseif ($this->isNumberConstraint($constraint)) { return new NumberDoc(); } elseif ($constraint instanceof Assert\Regex) { return new ScalarDoc(); diff --git a/src/Infra/Transformer/ConstraintToParamsDocTransformer.php b/src/Infra/Transformer/ConstraintToParamsDocTransformer.php index 5fd1da7..0fac35b 100644 --- a/src/Infra/Transformer/ConstraintToParamsDocTransformer.php +++ b/src/Infra/Transformer/ConstraintToParamsDocTransformer.php @@ -171,9 +171,6 @@ private function appendValidItemListDoc(TypeDoc $doc, Constraint $constraint) : } /** - * @param CollectionDoc $doc - * @param Assert\All $constraint - * * @throws \ReflectionException */ private function appendAllConstraintToDoc(CollectionDoc $doc, Assert\All $constraint) : void From 7bd42fe33d36cc0addd24a1383456cb6710e1c64 Mon Sep 17 00:00:00 2001 From: Yoanm Date: Mon, 10 Apr 2023 19:05:12 +0200 Subject: [PATCH 4/4] Fix UTs --- tests/Functional/App/Helper/TypeGuesserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Functional/App/Helper/TypeGuesserTest.php b/tests/Functional/App/Helper/TypeGuesserTest.php index a3dbff3..3a3404f 100644 --- a/tests/Functional/App/Helper/TypeGuesserTest.php +++ b/tests/Functional/App/Helper/TypeGuesserTest.php @@ -152,9 +152,9 @@ public function provideConstraints() 'constraint' => new Assert\Choice(['multiple' => true]), 'expectedClass' => ArrayDoc::class, ], - 'All to Array' => [ + 'All to Collection' => [ 'constraint' => new Assert\All(['constraints' => []]), - 'expectedClass' => ArrayDoc::class, + 'expectedClass' => CollectionDoc::class, ], 'Count to Collection' => [ 'constraint' => new Assert\Count(['min' => 2]),