Skip to content

Commit

Permalink
refactor: use provider/processor instead of event listeners (#5657)
Browse files Browse the repository at this point in the history
* refactor: use provider/processor instead of event listeners

* tests
  • Loading branch information
soyuka committed Sep 2, 2023
1 parent 2efdc7d commit afb739b
Show file tree
Hide file tree
Showing 195 changed files with 5,220 additions and 610 deletions.
147 changes: 147 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,150 @@ jobs:
run: tests/Fixtures/app/console cache:clear --ansi
- name: Run Behat tests
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction

phpunit_legacy:
name: PHPUnit Legacy event listeners (PHP ${{ matrix.php }})
env:
EVENT_LISTENERS_BACKWARD_COMPATIBILITY_LAYER: 1
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
php:
- '8.2'
include:
- php: '8.2'
coverage: true
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: pecl, composer
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite
coverage: pcov
ini-values: memory_limit=-1
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Enable code coverage
if: matrix.coverage
run: echo "COVERAGE=1" >> $GITHUB_ENV
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Install PHPUnit
run: vendor/bin/simple-phpunit --version
- name: Clear test app cache
run: tests/Fixtures/app/console cache:clear --ansi
- name: Run PHPUnit tests
run: |
mkdir -p build/logs/phpunit
if [ "$COVERAGE" = '1' ]; then
vendor/bin/simple-phpunit --log-junit build/logs/phpunit/junit.xml --coverage-clover build/logs/phpunit/clover.xml
else
vendor/bin/simple-phpunit --log-junit build/logs/phpunit/junit.xml
fi
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: phpunit-logs-php${{ matrix.php }}
path: build/logs/phpunit
continue-on-error: true
- name: Upload coverage results to Codecov
if: matrix.coverage
uses: codecov/codecov-action@v3
with:
directory: build/logs/phpunit
name: phpunit-php${{ matrix.php }}
flags: phpunit
fail_ci_if_error: true
continue-on-error: true
- name: Upload coverage results to Coveralls
if: matrix.coverage
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require --prefer-dist --no-interaction --no-progress --ansi php-coveralls/php-coveralls
export PATH="$PATH:$HOME/.composer/vendor/bin"
php-coveralls --coverage_clover=build/logs/phpunit/clover.xml
continue-on-error: true

behat_legacy:
name: Behat Legacy event listeners (PHP ${{ matrix.php }})
env:
EVENT_LISTENERS_BACKWARD_COMPATIBILITY_LAYER: 1
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
php:
- '8.2'
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: pecl, composer
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite
coverage: pcov
ini-values: memory_limit=-1
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Install PHPUnit
run: vendor/bin/simple-phpunit --version
- name: Clear test app cache
run: tests/Fixtures/app/console cache:clear --ansi
- name: Run Behat tests (PHP 8)
run: |
mkdir -p build/logs/behat
vendor/bin/behat --out=std --format=progress --format=junit --out=build/logs/behat/junit --profile=legacy --no-interaction
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: behat-logs-php${{ matrix.php }}
path: build/logs/behat
continue-on-error: true
- name: Export OpenAPI documents
run: |
mkdir -p build/out/openapi
tests/Fixtures/app/console api:openapi:export -o build/out/openapi/openapi_v3.json
tests/Fixtures/app/console api:openapi:export --yaml -o build/out/openapi/openapi_v3.yaml
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '14'
- name: Validate OpenAPI documents
run: |
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.json
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.yaml
- name: Upload OpenAPI artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: openapi-docs-php${{ matrix.php }}
path: build/out/openapi
continue-on-error: true

40 changes: 38 additions & 2 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@postgres&&~@mongodb&&~@elasticsearch'
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@controller'
extensions:
'FriendsOfBehat\SymfonyExtension':
bootstrap: 'tests/Fixtures/app/bootstrap.php'
Expand Down Expand Up @@ -52,7 +52,7 @@ postgres:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@sqlite&&~@mongodb&&~@elasticsearch'
tags: '~@sqlite&&~@mongodb&&~@elasticsearch&&~@controller'

mongodb:
suites:
Expand Down Expand Up @@ -142,3 +142,39 @@ elasticsearch-coverage:
- 'ApiPlatform\Tests\Behat\CoverageContext'
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'

legacy:
suites:
default:
contexts:
- 'ApiPlatform\Tests\Behat\CommandContext'
- 'ApiPlatform\Tests\Behat\DoctrineContext'
- 'ApiPlatform\Tests\Behat\GraphqlContext'
- 'ApiPlatform\Tests\Behat\JsonContext'
- 'ApiPlatform\Tests\Behat\HydraContext'
- 'ApiPlatform\Tests\Behat\OpenApiContext'
- 'ApiPlatform\Tests\Behat\HttpCacheContext'
- 'ApiPlatform\Tests\Behat\JsonApiContext'
- 'ApiPlatform\Tests\Behat\JsonHalContext'
- 'ApiPlatform\Tests\Behat\MercureContext'
- 'ApiPlatform\Tests\Behat\XmlContext'
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@postgres&&~@mongodb&&~@elasticsearch'
extensions:
'FriendsOfBehat\SymfonyExtension':
bootstrap: 'tests/Fixtures/app/bootstrap.php'
kernel:
environment: 'test'
debug: true
class: AppKernel
path: 'tests/Fixtures/app/AppKernel.php'
'Behat\MinkExtension':
base_url: 'http://example.com/'
files_path: 'features/files'
sessions:
default:
symfony: ~
'Behatch\Extension': ~

3 changes: 3 additions & 0 deletions features/graphql/mutation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ Feature: GraphQL mutation support
And the JSON node "errors[0].extensions.violations[0].path" should be equal to "name"
And the JSON node "errors[0].extensions.violations[0].message" should be equal to "This value should not be blank."

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

@createSchema
Scenario: Execute a not persisted custom mutation (resolver returns null)
Given there are 1 dummyCustomMutation objects
When I send the following GraphQL request:
"""
mutation {
Expand Down
9 changes: 5 additions & 4 deletions features/hydra/error.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ Feature: Error handling
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the JSON node "@context" should be equal to "/contexts/Error"
And the JSON node "@type" should be equal to "hydra:Error"
And the JSON node "hydra:title" should be equal to "An error occurred"
And the JSON node "hydra:description" should be equal to 'Nested documents for attribute "relatedDummy" are not allowed. Use IRIs instead.'
And the JSON node "trace" should exist
And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'

Scenario: Get an error during deserialization of collection
When I add "Content-Type" header equal to "application/ld+json"
Expand All @@ -62,7 +63,7 @@ Feature: Error handling
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the JSON node "@context" should be equal to "/contexts/Error"
And the JSON node "@type" should be equal to "hydra:Error"
And the JSON node "hydra:title" should be equal to "An error occurred"
Expand All @@ -79,7 +80,7 @@ Feature: Error handling
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the JSON node "@context" should be equal to "/contexts/Error"
And the JSON node "@type" should be equal to "hydra:Error"
And the JSON node "hydra:title" should be equal to "An error occurred"
Expand All @@ -97,7 +98,7 @@ Feature: Error handling
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the JSON node "@context" should be equal to "/contexts/Error"
And the JSON node "@type" should be equal to "hydra:Error"
And the JSON node "hydra:title" should be equal to "An error occurred"
Expand Down
1 change: 1 addition & 0 deletions features/jsonld/non_resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Feature: JSON-LD non-resource handling
"""
And the JSON node "notAResource.@id" should exist

@createSchema
Scenario: Get a resource containing a raw object with selected properties
Given there are 1 dummy objects with relatedDummy and its thirdLevel
When I send a "GET" request to "/contain_non_resources/1?properties[]=id&properties[nested][notAResource][]=foo&properties[notAResource][]=bar"
Expand Down
3 changes: 2 additions & 1 deletion features/main/attribute_resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ Feature: Resource attributes
When I send a "GET" request to "/photos/1/resize/300/100"
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
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"'

Scenario: Uri variables with Post operation
Expand Down
6 changes: 3 additions & 3 deletions features/main/exception_to_status.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Using exception_to_status config
And I send a "GET" request to "/dummy_exception_to_statuses/123"
Then the response status code should be 404
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"

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

@!mongodb
Scenario: Configure status code via the config file to map FilterValidationException to 400
When I add "Content-Type" header equal to "application/ld+json"
And I send a "GET" request to "/dummy_exception_to_statuses"
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
5 changes: 4 additions & 1 deletion features/main/not_exposed.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
@v3
Feature: Expose only a collection of objects

Background:
Given I add "Accept" header equal to "application/ld+json"

# A NotExposed operation with "routeName: api_genid" is automatically added to this resource.
Scenario: Get a collection of objects without identifiers from a single resource with a single collection
When I send a "GET" request to "/chairs"
Expand Down Expand Up @@ -168,7 +171,7 @@ Feature: Expose only a collection of objects
When I send a "GET" request to "<uri>"
Then the response status code should be 404
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the JSON node "hydra:description" should be equal to "<hydra:description>"
Examples:
| uri | hydra:description |
Expand Down
8 changes: 4 additions & 4 deletions features/main/relation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ Feature: Relations support
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"

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

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

Scenario: Passing an invalid type to a relation
Expand All @@ -483,7 +483,7 @@ Feature: Relations support
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the JSON should be valid according to this schema:
"""
{
Expand Down
2 changes: 1 addition & 1 deletion features/main/union_intersect_types.feature
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ Feature: Union/Intersect types
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
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.'
6 changes: 3 additions & 3 deletions features/main/uuid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Feature: Using uuid identifier on resource
When I send a "GET" request to "/ramsey_uuid_dummies/41B29566-144B-E1D05DEFE78"
Then the response status code should be 404
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"

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

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

@!mongodb
@createSchema
Expand Down
Loading

0 comments on commit afb739b

Please sign in to comment.