Skip to content

Commit

Permalink
chore: remove legacy code
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Jul 19, 2024
1 parent 1447560 commit 2488620
Show file tree
Hide file tree
Showing 321 changed files with 4,290 additions and 3,938 deletions.
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,19 @@ Only the first commit on a Pull Request need to use a conventional commit, other

### Tests

On `api-platform/core` there are two kinds of tests: unit (`phpunit` through `simple-phpunit`) and integration tests (`behat`).
On `api-platform/core` there are two kinds of tests: unit (`phpunit`) and integration tests (`behat`).

Note that we stopped using `prophesize` for new tests since 3.2, use `phpunit` stub system.

Both `simple-phpunit` and `behat` are development dependencies and should be available in the `vendor` directory.
Both `phpunit` and `behat` are development dependencies and should be available in the `vendor` directory.

Recommendations:

* don't change existing tests if possible
* always add a new `ApiResource` or a new `Entity/Document` to add a new test instead of changing an existing class
* as of API Platform 3 each component has it's own test directory, avoid the `tests/` directory except for functional tests
* dependencies between components must be kept at its minimal (`api-platform/metadata`, `api-platform/state`) except for bridges (Doctrine, Symfony, Laravel etc.)
* for functional testing with phpunit (see `tests/Functional`, add your ApiResource to `ApiPlatform\Tests\Fixtures\PhpUnitResourceNameCollectionFactory`)

Note that in most of the testing, you don't need Doctrine take a look at how we write fixtures at:

Expand Down
41 changes: 18 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"symfony/serializer": "^6.4 || ^7.1",
"symfony/translation-contracts": "^3.3",
"symfony/web-link": "^6.4 || ^7.1",
"willdurand/negotiation": "^3.0"
"willdurand/negotiation": "^3.1"
},
"require-dev": {
"behat/behat": "^3.11",
Expand All @@ -47,35 +47,34 @@
"doctrine/mongodb-odm": "^2.2",
"doctrine/mongodb-odm-bundle": "^4.0 || ^5.0",
"doctrine/orm": "^2.14 || ^3.0",
"elasticsearch/elasticsearch": "^7.11 || ^8.4",
"elasticsearch/elasticsearch": "^8.4",
"friends-of-behat/mink-browserkit-driver": "^1.3.1",
"friends-of-behat/mink-extension": "^2.2",
"friends-of-behat/symfony-extension": "^2.1",
"guzzlehttp/guzzle": "^6.0 || ^7.1",
"illuminate/config": "^10.0||^11.0",
"illuminate/contracts": "^10.0||^11.0",
"illuminate/database": "^10.0||^11.0",
"illuminate/http": "^10.0||^11.0",
"illuminate/pagination": "^10.0||^11.0",
"illuminate/routing": "^10.0||^11.0",
"illuminate/support": "^10.0||^11.0",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"illuminate/config": "^11.0",
"illuminate/contracts": "^11.0",
"illuminate/database": "^11.0",
"illuminate/http": "^11.0",
"illuminate/pagination": "^11.0",
"illuminate/routing": "^11.0",
"illuminate/support": "^11.0",
"jangregor/phpstan-prophecy": "^1.0",
"justinrainbow/json-schema": "^5.2.1",
"laravel/framework": "^10.0||^11.0",
"orchestra/testbench": "^8.18",
"justinrainbow/json-schema": "^5.2.11",
"laravel/framework": "^11.0",
"orchestra/testbench": "^9.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpdoc-parser": "^1.13",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^11.2",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"ramsey/uuid": "^3.9.7 || ^4.0",
"ramsey/uuid-doctrine": "^1.4 || ^2.0 || ^3.0",
"sebastian/comparator": "<5.0",
"soyuka/contexts": "v3.3.9",
"soyuka/contexts": "^3.3.10",
"soyuka/pmu": "^0.0.4",
"soyuka/stubs-mongodb": "^1.0",
"symfony/asset": "^6.4 || ^7.1",
Expand All @@ -85,7 +84,7 @@
"symfony/console": "^6.4 || ^7.1",
"symfony/css-selector": "^6.4 || ^7.1",
"symfony/dependency-injection": "^6.4 || ^7.1",
"symfony/doctrine-bridge": "^6.4 || ^7.1",
"symfony/doctrine-bridge": "^6.4.2 || ^7.1.2",
"symfony/dom-crawler": "^6.4 || ^7.1",
"symfony/error-handler": "^6.4 || ^7.1",
"symfony/event-dispatcher": "^6.4 || ^7.1",
Expand All @@ -98,7 +97,6 @@
"symfony/maker-bundle": "^1.24",
"symfony/mercure-bundle": "*",
"symfony/messenger": "^6.4 || ^7.1",
"symfony/phpunit-bridge": "^6.4.1 || ^7.1",
"symfony/routing": "^6.4 || ^7.1",
"symfony/security-bundle": "^6.4 || ^7.1",
"symfony/security-core": "^6.4 || ^7.1",
Expand All @@ -110,7 +108,7 @@
"symfony/web-profiler-bundle": "^6.4 || ^7.1",
"symfony/yaml": "^6.4 || ^7.1",
"twig/twig": "^1.42.3 || ^2.12 || ^3.0",
"webonyx/graphql-php": "^14.0 || ^15.0"
"webonyx/graphql-php": "^15.0"
},
"conflict": {
"doctrine/common": "<3.2.2",
Expand All @@ -121,8 +119,7 @@
"symfony/framework-bundle": "6.4.6 || 7.1.6",
"symfony/var-exporter": "<6.1.1",
"phpunit/phpunit": "<9.5",
"phpspec/prophecy": "<1.15",
"elasticsearch/elasticsearch": ">=8.0,<8.4"
"phpspec/prophecy": "<1.15"
},
"suggest": {
"doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.",
Expand Down Expand Up @@ -189,7 +186,6 @@
"api-platform/graphql",
"api-platform/http-cache",
"api-platform/documentation",
"api-platform/parameter-validator",
"api-platform/ramsey-uuid",
"api-platform/serializer",
"api-platform/state",
Expand All @@ -212,7 +208,6 @@
{"type": "path", "url": "./src/GraphQl"},
{"type": "path", "url": "./src/HttpCache"},
{"type": "path", "url": "./src/Documentation"},
{"type": "path", "url": "./src/ParameterValidator"},
{"type": "path", "url": "./src/RamseyUuid"},
{"type": "path", "url": "./src/Serializer"},
{"type": "path", "url": "./src/State"},
Expand Down
8 changes: 3 additions & 5 deletions docs/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ api_platform:
json: ['application/json']
docs_formats:
jsonopenapi: ['application/vnd.openapi+json']
keep_legacy_inflector: false
http_cache:
invalidation:
enabled: true
public: true
invalidation:
enabled: true
public: true
use_symfony_listeners: false
defaults:
extra_properties:
rfc_7807_compliant_errors: true
standard_put: true
8 changes: 0 additions & 8 deletions docs/guides/error-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
// tags: design, state
// ---

// Note that we use the following configuration:
// ```
// api_platform:
// defaults:
// rfc_7807_compliant_errors: true
// ```
// To customize the API Platform response, replace the api_platform.state.error_provider with your own provider:

namespace App\ApiResource {
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
Expand Down
7 changes: 0 additions & 7 deletions docs/guides/error-resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
// tags: design, state
// ---

// Note that we use the following configuration:
// ```
// api_platform:
// defaults:
// rfc_7807_compliant_errors: true
// ```

namespace App\ApiResource {
use ApiPlatform\Metadata\ErrorResource;
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
Expand Down
11 changes: 6 additions & 5 deletions features/hydra/error.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Error handling
And the JSON node "hydra:description" should exist
And the JSON node "trace" should exist
And the JSON node "status" should exist
And the JSON node "@context" should not exist
And the JSON node "@context" should exist

Scenario: Get validation constraint violations
When I add "Content-Type" header equal to "application/ld+json"
Expand All @@ -36,6 +36,7 @@ Feature: Error handling
And the JSON should be equal to:
"""
{
"@context": "/contexts/ConstraintViolationList",
"@id": "/validation_errors/c1051bb4-d103-4f74-8988-acbcafc7fdc3",
"@type": "ConstraintViolationList",
"status": 422,
Expand Down Expand Up @@ -64,7 +65,7 @@ Feature: Error handling
And the response should be in JSON
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 "@context" should not exist
And the JSON node "@context" should exist
And the JSON node "type" should exist
And the JSON node "title" should be equal to "An error occurred"
And the JSON node "detail" should exist
Expand All @@ -79,7 +80,7 @@ Feature: Error handling
And the response should be in JSON
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 "@context" should not exist
And the JSON node "@context" should exist
And the JSON node "type" should exist
And the JSON node "title" should be equal to "An error occurred"
And the JSON node "hydra:title" should be equal to "An error occurred"
Expand All @@ -97,7 +98,7 @@ Feature: Error handling
And the response should be in JSON
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 "@context" should not exist
And the JSON node "@context" should exist
And the JSON node "type" should exist
And the JSON node "title" should be equal to "An error occurred"
And the JSON node "hydra:title" should be equal to "An error occurred"
Expand All @@ -115,7 +116,7 @@ Feature: Error handling
And the response should be in JSON
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 "@context" should not exist
And the JSON node "@context" should exist
And the JSON node "type" should exist
And the JSON node "title" should be equal to "An error occurred"
And the JSON node "detail" should exist
Expand Down
6 changes: 3 additions & 3 deletions features/jsonld/interface_as_resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Feature: JSON-LD using interface as resource
"code": "WONDERFUL_TAXON"
}
"""
When I send a "GET" request to "/taxons/WONDERFUL_TAXON"
When I send a "GET" request to "/taxa/WONDERFUL_TAXON"
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/Taxon",
"@id": "/taxons/WONDERFUL_TAXON",
"@id": "/taxa/WONDERFUL_TAXON",
"@type": "Taxon",
"code": "WONDERFUL_TAXON"
}
Expand All @@ -49,7 +49,7 @@ Feature: JSON-LD using interface as resource
"@type": "Product",
"code": "GREAT_PRODUCT",
"mainTaxon": {
"@id": "/taxons/WONDERFUL_TAXON",
"@id": "/taxa/WONDERFUL_TAXON",
"@type": "Taxon",
"code": "WONDERFUL_TAXON"
}
Expand Down
12 changes: 6 additions & 6 deletions features/main/validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Feature: Using validations groups
"""
Then the response status code should be 422
And the response should be in JSON
And the JSON should be equal to:
And the JSON should be a superset of:
"""
{
"@context": "/contexts/ConstraintViolationList",
Expand All @@ -42,7 +42,7 @@ Feature: Using validations groups
]
}
"""
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"

@createSchema
Scenario: Create a resource with validation group sequence
Expand All @@ -55,7 +55,7 @@ Feature: Using validations groups
"""
Then the response status code should be 422
And the response should be in JSON
And the JSON should be equal to:
And the JSON should be a superset of:
"""
{
"@context": "/contexts/ConstraintViolationList",
Expand All @@ -71,7 +71,7 @@ Feature: Using validations groups
]
}
"""
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"

@createSchema
Scenario: Create a resource with serializedName property
Expand Down Expand Up @@ -107,8 +107,8 @@ Feature: Using validations groups
"""
Then the response status code should be 422
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the JSON should be a superset of:
"""
{
"@context": "/contexts/ConstraintViolationList",
Expand Down
4 changes: 2 additions & 2 deletions features/mongodb/filters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Filters on collections
When I send a "GET" request to "/dummies?relatedDummy.thirdLevel.badFourthLevel.level=4"
Then the response status code should be 500
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 @@ -21,7 +21,7 @@ Feature: Filters on collections
When I send a "GET" request to "/dummies?relatedDummy.thirdLevel.fourthLevel.badThirdLevel.level=3"
Then the response status code should be 500
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
2 changes: 1 addition & 1 deletion features/security/send_security_headers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Feature: Send security header
{"name": ""}
"""
Then the response status code should be 422
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 "X-Content-Type-Options" should be equal to "nosniff"
And the header "X-Frame-Options" should be equal to "deny"
12 changes: 6 additions & 6 deletions features/security/strong_typing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Feature: Handle properly invalid data submitted to the API
"""
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 @@ -69,7 +69,7 @@ Feature: Handle properly invalid data submitted to the API
"""
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 @@ -87,7 +87,7 @@ Feature: Handle properly invalid data submitted to the API
"""
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: Send non-array data when an array is expected
When I add "Content-Type" header equal to "application/ld+json"
Expand All @@ -100,7 +100,7 @@ Feature: Handle properly invalid data submitted to the API
"""
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 @@ -118,7 +118,7 @@ Feature: Handle properly invalid data submitted to the API
"""
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 @@ -134,7 +134,7 @@ Feature: Handle properly invalid data submitted to the API
"""
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
2 changes: 1 addition & 1 deletion features/security/validate_incoming_content-types.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ Feature: Validate incoming content type
something
"""
Then the response status code should be 415
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 'The content-type "text/plain" is not supported. Supported MIME types are "application/ld+json", "application/hal+json", "application/vnd.api+json", "application/xml", "text/xml", "application/json", "text/html", "application/graphql", "multipart/form-data".'
Loading

0 comments on commit 2488620

Please sign in to comment.