Skip to content

Commit 26d5cbb

Browse files
authored
feat: deprecate query parameter validator (#6454)
1 parent e223921 commit 26d5cbb

18 files changed

+422
-107
lines changed

.github/workflows/ci.yml

+49
Original file line numberDiff line numberDiff line change
@@ -1333,3 +1333,52 @@ jobs:
13331333
name: openapi-docs-php${{ matrix.php }}
13341334
path: build/out/openapi
13351335
continue-on-error: true
1336+
1337+
behat_legacy_query_parameter_validator:
1338+
name: Behat query parameter validator (PHP ${{ matrix.php }})
1339+
env:
1340+
QUERY_PARAMETER_VALIDATOR: 1
1341+
runs-on: ubuntu-latest
1342+
timeout-minutes: 20
1343+
strategy:
1344+
matrix:
1345+
php:
1346+
- '8.3'
1347+
fail-fast: false
1348+
steps:
1349+
- name: Checkout
1350+
uses: actions/checkout@v4
1351+
- name: Setup PHP
1352+
uses: shivammathur/setup-php@v2
1353+
with:
1354+
php-version: ${{ matrix.php }}
1355+
tools: pecl, composer
1356+
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite
1357+
coverage: pcov
1358+
ini-values: memory_limit=-1
1359+
- name: Get composer cache directory
1360+
id: composercache
1361+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
1362+
- name: Cache dependencies
1363+
uses: actions/cache@v4
1364+
with:
1365+
path: ${{ steps.composercache.outputs.dir }}
1366+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
1367+
restore-keys: ${{ runner.os }}-composer-
1368+
- name: Update project dependencies
1369+
run: composer update --no-interaction --no-progress --ansi
1370+
- name: Install PHPUnit
1371+
run: vendor/bin/simple-phpunit --version
1372+
- name: Clear test app cache
1373+
run: tests/Fixtures/app/console cache:clear --ansi
1374+
- name: Run Behat tests (PHP 8)
1375+
run: |
1376+
mkdir -p build/logs/behat
1377+
vendor/bin/behat --out=std --format=progress --format=junit --out=build/logs/behat/junit --tags=query_parameter_validator
1378+
- name: Upload test artifacts
1379+
if: always()
1380+
uses: actions/upload-artifact@v4
1381+
with:
1382+
name: behat-logs-php${{ matrix.php }}
1383+
path: build/logs/behat
1384+
continue-on-error: true

behat.yml.dist

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ default:
1616
- 'Behat\MinkExtension\Context\MinkContext'
1717
- 'behatch:context:rest'
1818
filters:
19-
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@controller&&~@mercure'
19+
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@controller&&~@mercure&&~@query_parameter_validator'
2020
extensions:
2121
'FriendsOfBehat\SymfonyExtension':
2222
bootstrap: 'tests/Fixtures/app/bootstrap.php'
@@ -52,7 +52,7 @@ postgres:
5252
- 'Behat\MinkExtension\Context\MinkContext'
5353
- 'behatch:context:rest'
5454
filters:
55-
tags: '~@sqlite&&~@mongodb&&~@elasticsearch&&~@controller&&~@mercure'
55+
tags: '~@sqlite&&~@mongodb&&~@elasticsearch&&~@controller&&~@mercure&&~@query_parameter_validator'
5656

5757
mongodb:
5858
suites:
@@ -73,7 +73,7 @@ mongodb:
7373
- 'Behat\MinkExtension\Context\MinkContext'
7474
- 'behatch:context:rest'
7575
filters:
76-
tags: '~@sqlite&&~@elasticsearch&&~@!mongodb&&~@mercure&&~@controller'
76+
tags: '~@sqlite&&~@elasticsearch&&~@!mongodb&&~@mercure&&~@controller&&~@query_parameter_validator'
7777

7878
mercure:
7979
suites:
@@ -109,7 +109,7 @@ elasticsearch:
109109
- 'Behat\MinkExtension\Context\MinkContext'
110110
- 'behatch:context:rest'
111111
filters:
112-
tags: '@elasticsearch&&~@mercure'
112+
tags: '@elasticsearch&&~@mercure&&~@query_parameter_validator'
113113

114114
default-coverage:
115115
suites:
@@ -203,7 +203,7 @@ legacy:
203203
- 'Behat\MinkExtension\Context\MinkContext'
204204
- 'behatch:context:rest'
205205
filters:
206-
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@link_security&&~@use_listener'
206+
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@link_security&&~@use_listener&&~@query_parameter_validator'
207207
extensions:
208208
'FriendsOfBehat\SymfonyExtension':
209209
bootstrap: 'tests/Fixtures/app/bootstrap.php'
@@ -238,7 +238,7 @@ symfony_listeners:
238238
- 'Behat\MinkExtension\Context\MinkContext'
239239
- 'behatch:context:rest'
240240
filters:
241-
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@mercure'
241+
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@mercure&&~@query_parameter_validator'
242242
extensions:
243243
'FriendsOfBehat\SymfonyExtension':
244244
bootstrap: 'tests/Fixtures/app/bootstrap.php'

features/filter/filter_validation.feature

+28-89
Original file line numberDiff line numberDiff line change
@@ -10,161 +10,100 @@ Feature: Validate filters based upon filter description
1010

1111
Scenario: Required filter that does not allow empty value should throw an error if empty
1212
When I am on "/filter_validators?required=&required-allow-empty=&arrayRequired[foo]="
13-
Then the response status code should be 400
14-
And the JSON node "detail" should be equal to 'Query parameter "required" does not allow empty value'
13+
Then the response status code should be 422
14+
And the JSON node "detail" should be equal to 'required: This value should not be blank.'
1515

1616
Scenario: Required filter should throw an error if not set
1717
When I am on "/filter_validators"
18-
Then the response status code should be 400
19-
And the JSON node "detail" should match '/^Query parameter "required" is required\nQuery parameter "required-allow-empty" is required$/'
18+
Then the response status code should be 422
19+
And the JSON node "detail" should be equal to 'required: This value should not be blank.\nrequired-allow-empty: The parameter "required-allow-empty" is required.'
2020

2121
Scenario: Required filter should not throw an error if set
2222
When I am on "/array_filter_validators?arrayRequired[]=foo&indexedArrayRequired[foo]=foo"
2323
Then the response status code should be 200
2424

2525
Scenario: Required filter should throw an error if not set
2626
When I am on "/array_filter_validators"
27-
Then the response status code should be 400
28-
And the JSON node "detail" should match '/^Query parameter "arrayRequired\[\]" is required\nQuery parameter "indexedArrayRequired\[foo\]" is required$/'
29-
30-
When I am on "/array_filter_validators?arrayRequired=foo&indexedArrayRequired[foo]=foo"
31-
Then the response status code should be 400
32-
And the JSON node "detail" should be equal to 'Query parameter "arrayRequired[]" is required'
27+
Then the response status code should be 422
28+
And the JSON node "detail" should be equal to 'arrayRequired: This value should not be blank.\nindexedArrayRequired: This value should not be blank.'
3329

3430
When I am on "/array_filter_validators?arrayRequired[foo]=foo"
35-
Then the response status code should be 400
36-
And the JSON node "detail" should match '/^Query parameter "arrayRequired\[\]" is required\nQuery parameter "indexedArrayRequired\[foo\]" is required$/'
31+
Then the response status code should be 422
32+
And the JSON node "detail" should be equal to 'indexedArrayRequired: This value should not be blank.'
3733

3834
When I am on "/array_filter_validators?arrayRequired[]=foo"
39-
Then the response status code should be 400
40-
And the JSON node "detail" should be equal to 'Query parameter "indexedArrayRequired[foo]" is required'
41-
42-
When I am on "/array_filter_validators?arrayRequired[]=foo&indexedArrayRequired[bar]=bar"
43-
Then the response status code should be 400
44-
And the JSON node "detail" should be equal to 'Query parameter "indexedArrayRequired[foo]" is required'
35+
Then the response status code should be 422
36+
And the JSON node "detail" should be equal to 'indexedArrayRequired: This value should not be blank.'
4537

4638
Scenario: Test filter bounds: maximum
4739
When I am on "/filter_validators?required=foo&required-allow-empty&maximum=10"
4840
Then the response status code should be 200
4941

5042
When I am on "/filter_validators?required=foo&required-allow-empty&maximum=11"
51-
Then the response status code should be 400
52-
And the JSON node "detail" should be equal to 'Query parameter "maximum" must be less than or equal to 10'
43+
Then the response status code should be 422
44+
And the JSON node "detail" should be equal to 'maximum: This value should be less than or equal to 10.'
5345

5446
Scenario: Test filter bounds: exclusiveMaximum
5547
When I am on "/filter_validators?required=foo&required-allow-empty&exclusiveMaximum=9"
5648
Then the response status code should be 200
5749

5850
When I am on "/filter_validators?required=foo&required-allow-empty&exclusiveMaximum=10"
59-
Then the response status code should be 400
60-
And the JSON node "detail" should be equal to 'Query parameter "exclusiveMaximum" must be less than 10'
51+
Then the response status code should be 422
52+
And the JSON node "detail" should be equal to 'maximum: This value should be less than 10.'
6153

6254
Scenario: Test filter bounds: minimum
6355
When I am on "/filter_validators?required=foo&required-allow-empty&minimum=5"
6456
Then the response status code should be 200
6557

6658
When I am on "/filter_validators?required=foo&required-allow-empty&minimum=0"
67-
Then the response status code should be 400
68-
And the JSON node "detail" should be equal to 'Query parameter "minimum" must be greater than or equal to 5'
59+
Then the response status code should be 422
60+
And the JSON node "detail" should be equal to 'minimum: This value should be greater than or equal to 5.'
6961

7062
Scenario: Test filter bounds: exclusiveMinimum
7163
When I am on "/filter_validators?required=foo&required-allow-empty&exclusiveMinimum=6"
7264
Then the response status code should be 200
7365

7466
When I am on "/filter_validators?required=foo&required-allow-empty&exclusiveMinimum=5"
75-
Then the response status code should be 400
76-
And the JSON node "detail" should be equal to 'Query parameter "exclusiveMinimum" must be greater than 5'
67+
Then the response status code should be 422
68+
And the JSON node "detail" should be equal to 'exclusiveMinimum: This value should be greater than 5.'
7769

7870
Scenario: Test filter bounds: max length
7971
When I am on "/filter_validators?required=foo&required-allow-empty&max-length-3=123"
8072
Then the response status code should be 200
8173

8274
When I am on "/filter_validators?required=foo&required-allow-empty&max-length-3=1234"
83-
Then the response status code should be 400
84-
And the JSON node "detail" should be equal to 'Query parameter "max-length-3" length must be lower than or equal to 3'
85-
86-
Scenario: Do not throw an error if value is not an array
87-
When I am on "/filter_validators?required=foo&required-allow-empty&max-length-3[]=12345"
88-
Then the response status code should be 200
75+
Then the response status code should be 422
76+
And the JSON node "detail" should be equal to 'max-length-3: This value is too long. It should have 3 characters or less.'
8977

9078
Scenario: Test filter bounds: min length
9179
When I am on "/filter_validators?required=foo&required-allow-empty&min-length-3=123"
9280
Then the response status code should be 200
9381

9482
When I am on "/filter_validators?required=foo&required-allow-empty&min-length-3=12"
95-
Then the response status code should be 400
96-
And the JSON node "detail" should be equal to 'Query parameter "min-length-3" length must be greater than or equal to 3'
83+
Then the response status code should be 422
84+
And the JSON node "detail" should be equal to 'min-length-3: This value is too short. It should have 3 characters or more.'
9785

9886
Scenario: Test filter pattern
9987
When I am on "/filter_validators?required=foo&required-allow-empty&pattern=pattern"
10088
When I am on "/filter_validators?required=foo&required-allow-empty&pattern=nrettap"
10189
Then the response status code should be 200
10290

10391
When I am on "/filter_validators?required=foo&required-allow-empty&pattern=not-pattern"
104-
Then the response status code should be 400
105-
And the JSON node "detail" should be equal to 'Query parameter "pattern" must match pattern /^(pattern|nrettap)$/'
92+
Then the response status code should be 422
93+
And the JSON node "detail" should be equal to 'pattern: This value is not valid.'
10694

10795
Scenario: Test filter enum
10896
When I am on "/filter_validators?required=foo&required-allow-empty&enum=in-enum"
10997
Then the response status code should be 200
11098

11199
When I am on "/filter_validators?required=foo&required-allow-empty&enum=not-in-enum"
112-
Then the response status code should be 400
113-
And the JSON node "detail" should be equal to 'Query parameter "enum" must be one of "in-enum, mune-ni"'
100+
Then the response status code should be 422
101+
And the JSON node "detail" should be equal to 'enum: The value you selected is not a valid choice.'
114102

115103
Scenario: Test filter multipleOf
116104
When I am on "/filter_validators?required=foo&required-allow-empty&multiple-of=4"
117105
Then the response status code should be 200
118106

119107
When I am on "/filter_validators?required=foo&required-allow-empty&multiple-of=3"
120-
Then the response status code should be 400
121-
And the JSON node "detail" should be equal to 'Query parameter "multiple-of" must multiple of 2'
122-
123-
Scenario: Test filter array items csv format minItems
124-
When I am on "/filter_validators?required=foo&required-allow-empty&csv-min-2=a,b"
125-
Then the response status code should be 200
126-
127-
When I am on "/filter_validators?required=foo&required-allow-empty&csv-min-2=a"
128-
Then the response status code should be 400
129-
And the JSON node "detail" should be equal to 'Query parameter "csv-min-2" must contain more than 2 values'
130-
131-
Scenario: Test filter array items csv format maxItems
132-
When I am on "/filter_validators?required=foo&required-allow-empty&csv-max-3=a,b,c"
133-
Then the response status code should be 200
134-
135-
When I am on "/filter_validators?required=foo&required-allow-empty&csv-max-3=a,b,c,d"
136-
Then the response status code should be 400
137-
And the JSON node "detail" should be equal to 'Query parameter "csv-max-3" must contain less than 3 values'
138-
139-
Scenario: Test filter array items tsv format minItems
140-
When I am on "/filter_validators?required=foo&required-allow-empty&tsv-min-2=a\tb"
141-
Then the response status code should be 200
142-
143-
When I am on "/filter_validators?required=foo&required-allow-empty&tsv-min-2=a,b"
144-
Then the response status code should be 400
145-
And the JSON node "detail" should be equal to 'Query parameter "tsv-min-2" must contain more than 2 values'
146-
147-
Scenario: Test filter array items pipes format minItems
148-
When I am on "/filter_validators?required=foo&required-allow-empty&pipes-min-2=a|b"
149-
Then the response status code should be 200
150-
151-
When I am on "/filter_validators?required=foo&required-allow-empty&pipes-min-2=a,b"
152-
Then the response status code should be 400
153-
And the JSON node "detail" should be equal to 'Query parameter "pipes-min-2" must contain more than 2 values'
154-
155-
Scenario: Test filter array items ssv format minItems
156-
When I am on "/filter_validators?required=foo&required-allow-empty&ssv-min-2=a b"
157-
Then the response status code should be 200
158-
159-
When I am on "/filter_validators?required=foo&required-allow-empty&ssv-min-2=a,b"
160-
Then the response status code should be 400
161-
And the JSON node "detail" should be equal to 'Query parameter "ssv-min-2" must contain more than 2 values'
162-
163-
@dropSchema
164-
Scenario: Test filter array items unique items
165-
When I am on "/filter_validators?required=foo&required-allow-empty&csv-uniques=a,b"
166-
Then the response status code should be 200
167-
168-
When I am on "/filter_validators?required=foo&required-allow-empty&csv-uniques=a,a"
169-
Then the response status code should be 400
170-
And the JSON node "detail" should be equal to 'Query parameter "csv-uniques" must contain unique values'
108+
Then the response status code should be 422
109+
And the JSON node "detail" should be equal to 'multiple-of: This value should be a multiple of 2.'

0 commit comments

Comments
 (0)