Skip to content

Commit afb739b

Browse files
authored
refactor: use provider/processor instead of event listeners (#5657)
* refactor: use provider/processor instead of event listeners * tests
1 parent 2efdc7d commit afb739b

File tree

195 files changed

+5220
-610
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+5220
-610
lines changed

.github/workflows/ci.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,150 @@ jobs:
841841
run: tests/Fixtures/app/console cache:clear --ansi
842842
- name: Run Behat tests
843843
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction
844+
845+
phpunit_legacy:
846+
name: PHPUnit Legacy event listeners (PHP ${{ matrix.php }})
847+
env:
848+
EVENT_LISTENERS_BACKWARD_COMPATIBILITY_LAYER: 1
849+
runs-on: ubuntu-latest
850+
timeout-minutes: 20
851+
strategy:
852+
matrix:
853+
php:
854+
- '8.2'
855+
include:
856+
- php: '8.2'
857+
coverage: true
858+
fail-fast: false
859+
steps:
860+
- name: Checkout
861+
uses: actions/checkout@v3
862+
- name: Setup PHP
863+
uses: shivammathur/setup-php@v2
864+
with:
865+
php-version: ${{ matrix.php }}
866+
tools: pecl, composer
867+
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite
868+
coverage: pcov
869+
ini-values: memory_limit=-1
870+
- name: Get composer cache directory
871+
id: composercache
872+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
873+
- name: Cache dependencies
874+
uses: actions/cache@v3
875+
with:
876+
path: ${{ steps.composercache.outputs.dir }}
877+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
878+
restore-keys: ${{ runner.os }}-composer-
879+
- name: Enable code coverage
880+
if: matrix.coverage
881+
run: echo "COVERAGE=1" >> $GITHUB_ENV
882+
- name: Update project dependencies
883+
run: composer update --no-interaction --no-progress --ansi
884+
- name: Install PHPUnit
885+
run: vendor/bin/simple-phpunit --version
886+
- name: Clear test app cache
887+
run: tests/Fixtures/app/console cache:clear --ansi
888+
- name: Run PHPUnit tests
889+
run: |
890+
mkdir -p build/logs/phpunit
891+
if [ "$COVERAGE" = '1' ]; then
892+
vendor/bin/simple-phpunit --log-junit build/logs/phpunit/junit.xml --coverage-clover build/logs/phpunit/clover.xml
893+
else
894+
vendor/bin/simple-phpunit --log-junit build/logs/phpunit/junit.xml
895+
fi
896+
- name: Upload test artifacts
897+
if: always()
898+
uses: actions/upload-artifact@v3
899+
with:
900+
name: phpunit-logs-php${{ matrix.php }}
901+
path: build/logs/phpunit
902+
continue-on-error: true
903+
- name: Upload coverage results to Codecov
904+
if: matrix.coverage
905+
uses: codecov/codecov-action@v3
906+
with:
907+
directory: build/logs/phpunit
908+
name: phpunit-php${{ matrix.php }}
909+
flags: phpunit
910+
fail_ci_if_error: true
911+
continue-on-error: true
912+
- name: Upload coverage results to Coveralls
913+
if: matrix.coverage
914+
env:
915+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
916+
run: |
917+
composer global require --prefer-dist --no-interaction --no-progress --ansi php-coveralls/php-coveralls
918+
export PATH="$PATH:$HOME/.composer/vendor/bin"
919+
php-coveralls --coverage_clover=build/logs/phpunit/clover.xml
920+
continue-on-error: true
921+
922+
behat_legacy:
923+
name: Behat Legacy event listeners (PHP ${{ matrix.php }})
924+
env:
925+
EVENT_LISTENERS_BACKWARD_COMPATIBILITY_LAYER: 1
926+
runs-on: ubuntu-latest
927+
timeout-minutes: 20
928+
strategy:
929+
matrix:
930+
php:
931+
- '8.2'
932+
fail-fast: false
933+
steps:
934+
- name: Checkout
935+
uses: actions/checkout@v3
936+
- name: Setup PHP
937+
uses: shivammathur/setup-php@v2
938+
with:
939+
php-version: ${{ matrix.php }}
940+
tools: pecl, composer
941+
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite
942+
coverage: pcov
943+
ini-values: memory_limit=-1
944+
- name: Get composer cache directory
945+
id: composercache
946+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
947+
- name: Cache dependencies
948+
uses: actions/cache@v3
949+
with:
950+
path: ${{ steps.composercache.outputs.dir }}
951+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
952+
restore-keys: ${{ runner.os }}-composer-
953+
- name: Update project dependencies
954+
run: composer update --no-interaction --no-progress --ansi
955+
- name: Install PHPUnit
956+
run: vendor/bin/simple-phpunit --version
957+
- name: Clear test app cache
958+
run: tests/Fixtures/app/console cache:clear --ansi
959+
- name: Run Behat tests (PHP 8)
960+
run: |
961+
mkdir -p build/logs/behat
962+
vendor/bin/behat --out=std --format=progress --format=junit --out=build/logs/behat/junit --profile=legacy --no-interaction
963+
- name: Upload test artifacts
964+
if: always()
965+
uses: actions/upload-artifact@v3
966+
with:
967+
name: behat-logs-php${{ matrix.php }}
968+
path: build/logs/behat
969+
continue-on-error: true
970+
- name: Export OpenAPI documents
971+
run: |
972+
mkdir -p build/out/openapi
973+
tests/Fixtures/app/console api:openapi:export -o build/out/openapi/openapi_v3.json
974+
tests/Fixtures/app/console api:openapi:export --yaml -o build/out/openapi/openapi_v3.yaml
975+
- name: Setup node
976+
uses: actions/setup-node@v3
977+
with:
978+
node-version: '14'
979+
- name: Validate OpenAPI documents
980+
run: |
981+
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.json
982+
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.yaml
983+
- name: Upload OpenAPI artifacts
984+
if: always()
985+
uses: actions/upload-artifact@v3
986+
with:
987+
name: openapi-docs-php${{ matrix.php }}
988+
path: build/out/openapi
989+
continue-on-error: true
990+

behat.yml.dist

Lines changed: 38 additions & 2 deletions
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'
19+
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@controller'
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'
55+
tags: '~@sqlite&&~@mongodb&&~@elasticsearch&&~@controller'
5656

5757
mongodb:
5858
suites:
@@ -142,3 +142,39 @@ elasticsearch-coverage:
142142
- 'ApiPlatform\Tests\Behat\CoverageContext'
143143
- 'Behat\MinkExtension\Context\MinkContext'
144144
- 'behatch:context:rest'
145+
146+
legacy:
147+
suites:
148+
default:
149+
contexts:
150+
- 'ApiPlatform\Tests\Behat\CommandContext'
151+
- 'ApiPlatform\Tests\Behat\DoctrineContext'
152+
- 'ApiPlatform\Tests\Behat\GraphqlContext'
153+
- 'ApiPlatform\Tests\Behat\JsonContext'
154+
- 'ApiPlatform\Tests\Behat\HydraContext'
155+
- 'ApiPlatform\Tests\Behat\OpenApiContext'
156+
- 'ApiPlatform\Tests\Behat\HttpCacheContext'
157+
- 'ApiPlatform\Tests\Behat\JsonApiContext'
158+
- 'ApiPlatform\Tests\Behat\JsonHalContext'
159+
- 'ApiPlatform\Tests\Behat\MercureContext'
160+
- 'ApiPlatform\Tests\Behat\XmlContext'
161+
- 'Behat\MinkExtension\Context\MinkContext'
162+
- 'behatch:context:rest'
163+
filters:
164+
tags: '~@postgres&&~@mongodb&&~@elasticsearch'
165+
extensions:
166+
'FriendsOfBehat\SymfonyExtension':
167+
bootstrap: 'tests/Fixtures/app/bootstrap.php'
168+
kernel:
169+
environment: 'test'
170+
debug: true
171+
class: AppKernel
172+
path: 'tests/Fixtures/app/AppKernel.php'
173+
'Behat\MinkExtension':
174+
base_url: 'http://example.com/'
175+
files_path: 'features/files'
176+
sessions:
177+
default:
178+
symfony: ~
179+
'Behatch\Extension': ~
180+

features/graphql/mutation.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ Feature: GraphQL mutation support
794794
And the JSON node "errors[0].extensions.violations[0].path" should be equal to "name"
795795
And the JSON node "errors[0].extensions.violations[0].message" should be equal to "This value should not be blank."
796796

797+
@createSchema
797798
Scenario: Execute a custom mutation
798799
Given there are 1 dummyCustomMutation objects
799800
When I send the following GraphQL request:
@@ -812,7 +813,9 @@ Feature: GraphQL mutation support
812813
And the header "Content-Type" should be equal to "application/json"
813814
And the JSON node "data.sumDummyCustomMutation.dummyCustomMutation.result" should be equal to "8"
814815

816+
@createSchema
815817
Scenario: Execute a not persisted custom mutation (resolver returns null)
818+
Given there are 1 dummyCustomMutation objects
816819
When I send the following GraphQL request:
817820
"""
818821
mutation {

features/hydra/error.feature

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ Feature: Error handling
4242
"""
4343
Then the response status code should be 400
4444
And the response should be in JSON
45-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
45+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
4646
And the JSON node "@context" should be equal to "/contexts/Error"
4747
And the JSON node "@type" should be equal to "hydra:Error"
4848
And the JSON node "hydra:title" should be equal to "An error occurred"
4949
And the JSON node "hydra:description" should be equal to 'Nested documents for attribute "relatedDummy" are not allowed. Use IRIs instead.'
5050
And the JSON node "trace" should exist
51+
And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
5152

5253
Scenario: Get an error during deserialization of collection
5354
When I add "Content-Type" header equal to "application/ld+json"
@@ -62,7 +63,7 @@ Feature: Error handling
6263
"""
6364
Then the response status code should be 400
6465
And the response should be in JSON
65-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
66+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
6667
And the JSON node "@context" should be equal to "/contexts/Error"
6768
And the JSON node "@type" should be equal to "hydra:Error"
6869
And the JSON node "hydra:title" should be equal to "An error occurred"
@@ -79,7 +80,7 @@ Feature: Error handling
7980
"""
8081
Then the response status code should be 400
8182
And the response should be in JSON
82-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
83+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
8384
And the JSON node "@context" should be equal to "/contexts/Error"
8485
And the JSON node "@type" should be equal to "hydra:Error"
8586
And the JSON node "hydra:title" should be equal to "An error occurred"
@@ -97,7 +98,7 @@ Feature: Error handling
9798
"""
9899
Then the response status code should be 400
99100
And the response should be in JSON
100-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
101+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
101102
And the JSON node "@context" should be equal to "/contexts/Error"
102103
And the JSON node "@type" should be equal to "hydra:Error"
103104
And the JSON node "hydra:title" should be equal to "An error occurred"

features/jsonld/non_resource.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Feature: JSON-LD non-resource handling
4040
"""
4141
And the JSON node "notAResource.@id" should exist
4242

43+
@createSchema
4344
Scenario: Get a resource containing a raw object with selected properties
4445
Given there are 1 dummy objects with relatedDummy and its thirdLevel
4546
When I send a "GET" request to "/contain_non_resources/1?properties[]=id&properties[nested][notAResource][]=foo&properties[notAResource][]=bar"

features/main/attribute_resource.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ Feature: Resource attributes
9898
When I send a "GET" request to "/photos/1/resize/300/100"
9999
Then the response status code should be 400
100100
And the response should be in JSON
101-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
101+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
102+
And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
102103
And the JSON node "hydra:description" should be equal to 'Unable to generate an IRI for the item of type "ApiPlatform\Tests\Fixtures\TestBundle\Entity\IncompleteUriVariableConfigured"'
103104

104105
Scenario: Uri variables with Post operation

features/main/exception_to_status.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Feature: Using exception_to_status config
99
And I send a "GET" request to "/dummy_exception_to_statuses/123"
1010
Then the response status code should be 404
1111
And the response should be in JSON
12-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
12+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
1313

1414
@!mongodb
1515
Scenario: Configure status code via the resource exceptionToStatus to map custom NotFound error to 400
@@ -22,12 +22,12 @@ Feature: Using exception_to_status config
2222
"""
2323
Then the response status code should be 400
2424
And the response should be in JSON
25-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
25+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
2626

2727
@!mongodb
2828
Scenario: Configure status code via the config file to map FilterValidationException to 400
2929
When I add "Content-Type" header equal to "application/ld+json"
3030
And I send a "GET" request to "/dummy_exception_to_statuses"
3131
Then the response status code should be 400
3232
And the response should be in JSON
33-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
33+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"

features/main/not_exposed.feature

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
@v3
33
Feature: Expose only a collection of objects
44

5+
Background:
6+
Given I add "Accept" header equal to "application/ld+json"
7+
58
# A NotExposed operation with "routeName: api_genid" is automatically added to this resource.
69
Scenario: Get a collection of objects without identifiers from a single resource with a single collection
710
When I send a "GET" request to "/chairs"
@@ -168,7 +171,7 @@ Feature: Expose only a collection of objects
168171
When I send a "GET" request to "<uri>"
169172
Then the response status code should be 404
170173
And the response should be in JSON
171-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
174+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
172175
And the JSON node "hydra:description" should be equal to "<hydra:description>"
173176
Examples:
174177
| uri | hydra:description |

features/main/relation.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Feature: Relations support
351351
"""
352352
Then the response status code should be 400
353353
And the response should be in JSON
354-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
354+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
355355

356356
Scenario: Post a relation with a not existing IRI
357357
When I add "Content-Type" header equal to "application/ld+json"
@@ -363,7 +363,7 @@ Feature: Relations support
363363
"""
364364
Then the response status code should be 400
365365
And the response should be in JSON
366-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
366+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
367367

368368
Scenario: Update an embedded relation
369369
When I add "Content-Type" header equal to "application/ld+json"
@@ -470,7 +470,7 @@ Feature: Relations support
470470
"""
471471
Then the response status code should be 400
472472
And the response should be in JSON
473-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
473+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
474474
And the JSON node "hydra:description" should contain 'Invalid IRI "certainly not an IRI".'
475475

476476
Scenario: Passing an invalid type to a relation
@@ -483,7 +483,7 @@ Feature: Relations support
483483
"""
484484
Then the response status code should be 400
485485
And the response should be in JSON
486-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
486+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
487487
And the JSON should be valid according to this schema:
488488
"""
489489
{

features/main/union_intersect_types.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ Feature: Union/Intersect types
117117
"""
118118
Then the response status code should be 400
119119
And the response should be in JSON
120-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
120+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
121121
And the JSON node "hydra:description" should be equal to 'Could not denormalize object of type "ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5452\ActivableInterface", no supporting normalizer found.'

features/main/uuid.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Feature: Using uuid identifier on resource
127127
When I send a "GET" request to "/ramsey_uuid_dummies/41B29566-144B-E1D05DEFE78"
128128
Then the response status code should be 404
129129
And the response should be in JSON
130-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
130+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
131131

132132
@!mongodb
133133
@createSchema
@@ -180,7 +180,7 @@ Feature: Using uuid identifier on resource
180180
"""
181181
Then the response status code should be 400
182182
And the response should be in JSON
183-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
183+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
184184

185185
@!mongodb
186186
Scenario: Update a resource with a bad Ramsey\Uuid\Uuid non-id field
@@ -193,7 +193,7 @@ Feature: Using uuid identifier on resource
193193
"""
194194
Then the response status code should be 400
195195
And the response should be in JSON
196-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
196+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
197197

198198
@!mongodb
199199
@createSchema

0 commit comments

Comments
 (0)