Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 156 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
EXT_MONGODB_VERSION: '1.5.5'
EXT_PCOV_VERSION: '1.0.6'
LEGACY: '0'
SYMFONY_REQUIRE: ^3.4 || ^4.0
SYMFONY_REQUIRE: ^3.4 || ^4.0 || ^5.0

jobs:
phpunit:
Expand Down Expand Up @@ -173,7 +173,7 @@ jobs:
run: |
mkdir -p /tmp/api-platform/core/var
ln -s /tmp/api-platform/core/var tests/Fixtures/app/var
tests/Fixtures/app/console cache:clear --
tests/Fixtures/app/console cache:clear --ansi
- name: Enable code coverage
if: matrix.coverage
run: echo '::set-env name=COVERAGE::1'
Expand Down Expand Up @@ -1018,7 +1018,7 @@ jobs:
run: |
mkdir -p /tmp/api-platform/core/var
ln -s /tmp/api-platform/core/var tests/Fixtures/app/var
tests/Fixtures/app/console cache:clear --
tests/Fixtures/app/console cache:clear --ansi
- name: Enable code coverage
if: matrix.coverage
run: echo '::set-env name=COVERAGE::1'
Expand Down Expand Up @@ -1107,10 +1107,162 @@ jobs:
run: |
mkdir -p build/logs/phpunit
vendor/bin/phpunit --log-junit build/logs/phpunit/junit.xml --colors=always
continue-on-error: true
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v1
with:
name: phpunit-logs-php${{ matrix.php }}-no-deprecations
path: build/logs/phpunit

phpunit-symfony-next:
name: PHPUnit (PHP ${{ matrix.php }}) (Symfony ${{ matrix.symfony }})
runs-on: ubuntu-latest
container:
image: php:${{ matrix.php }}-alpine
options: >-
--tmpfs /tmp:exec
strategy:
matrix:
php:
- '7.3'
symfony:
- '4.4'
fail-fast: false
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install system packages
run: |
apk add \
jq \
moreutils \
unzip \
- name: Install mongodb PHP extension
run: |
apk add $PHPIZE_DEPS
pecl install mongodb-$EXT_MONGODB_VERSION
docker-php-ext-enable mongodb
- name: Disable PHP memory limit
run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini
- name: Install Composer
run: wget -qO - https://raw.githubusercontent.com/composer/getcomposer.org/$COMPOSER_INSTALLER_COMMIT/web/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
- name: Install Symfony Flex
run: |
composer global require --prefer-dist --no-progress --no-suggest --ansi \
symfony/flex
- name: Allow unstable project dependencies
run: |
jq '. + {"minimum-stability": "dev"}' composer.json | sponge composer.json
- name: Update project dependencies
run: |
mkdir -p /tmp/api-platform/core/vendor
ln -s /tmp/api-platform/core/vendor vendor
composer update --no-progress --no-suggest --ansi
- name: Flag held back Symfony packages
env:
symfony_version: ${{ matrix.symfony }}
run: |
version_pattern=$symfony_version.x-dev
if [ "${symfony_version%.4}" != "$symfony_version" ]; then
current_major=${symfony_version%.4}
next_major=$((current_major + 1))
version_pattern=$version_pattern'|'$next_major.0.x-dev'|'dev-master
fi
version_pattern=$(echo "$version_pattern" | sed -r 's/\./\\./g')
symfony_packages=$(composer show symfony/* | tr -s ' ' '\t' | cut -f1-2 | grep -vE 'polyfill|contracts|mercure')
! echo "$symfony_packages" | grep -vE "$version_pattern"
continue-on-error: true
- name: Clear test app cache
run: |
mkdir -p /tmp/api-platform/core/var
ln -s /tmp/api-platform/core/var tests/Fixtures/app/var
tests/Fixtures/app/console cache:clear --ansi
- name: Run PHPUnit tests
run: |
mkdir -p build/logs/phpunit
vendor/bin/phpunit --log-junit build/logs/phpunit/junit.xml --colors=always
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v1
with:
name: phpunit-logs-php${{ matrix.php }}-symfony${{ matrix.symfony }}
path: build/logs/phpunit

behat-symfony-next:
name: Behat (PHP ${{ matrix.php }}) (Symfony ${{ matrix.symfony }})
runs-on: ubuntu-latest
container:
image: php:${{ matrix.php }}-alpine
options: >-
--tmpfs /tmp:exec
strategy:
matrix:
php:
- '7.3'
symfony:
- '4.4'
fail-fast: false
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install system packages
run: |
apk add \
jq \
moreutils \
unzip \
- name: Install mongodb PHP extension
run: |
apk add $PHPIZE_DEPS
pecl install mongodb-$EXT_MONGODB_VERSION
docker-php-ext-enable mongodb
- name: Disable PHP memory limit
run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini
- name: Install Composer
run: wget -qO - https://raw.githubusercontent.com/composer/getcomposer.org/$COMPOSER_INSTALLER_COMMIT/web/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
- name: Install Symfony Flex
run: |
composer global require --prefer-dist --no-progress --no-suggest --ansi \
symfony/flex
- name: Allow unstable project dependencies
run: |
jq '. + {"minimum-stability": "dev"}' composer.json | sponge composer.json
- name: Update project dependencies
run: |
mkdir -p /tmp/api-platform/core/vendor
ln -s /tmp/api-platform/core/vendor vendor
composer update --no-progress --no-suggest --ansi
- name: Flag held back Symfony packages
env:
symfony_version: ${{ matrix.symfony }}
run: |
version_pattern=$symfony_version.x-dev
if [ "${symfony_version%.4}" != "$symfony_version" ]; then
current_major=${symfony_version%.4}
next_major=$((current_major + 1))
version_pattern=$version_pattern'|'$next_major.0.x-dev'|'dev-master
fi
version_pattern=$(echo "$version_pattern" | sed -r 's/\./\\./g')
symfony_packages=$(composer show symfony/* | tr -s ' ' '\t' | cut -f1-2 | grep -vE 'polyfill|contracts|mercure')
! echo "$symfony_packages" | grep -vE "$version_pattern"
continue-on-error: true
- name: Enable legacy integrations
if: startsWith(matrix.php, '7.3')
run: echo '::set-env name=LEGACY::1'
- name: Clear test app cache
run: |
mkdir -p /tmp/api-platform/core/var
ln -s /tmp/api-platform/core/var tests/Fixtures/app/var
tests/Fixtures/app/console cache:clear --ansi
- name: Run Behat tests
run: |
mkdir -p build/logs/behat
vendor/bin/behat --format=progress --out=std --format=junit --out=build/logs/behat/junit --profile="$(if [ "$LEGACY" = '1' ]; then echo 'default-legacy'; else echo 'default'; fi)" --no-interaction --colors
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v1
with:
name: behat-logs-php${{ matrix.php }}-symfony${{ matrix.symfony }}
path: build/logs/behat
65 changes: 33 additions & 32 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
"require": {
"php": ">=7.1",
"doctrine/inflector": "^1.0",
"fig/link-util": "^1.0",
"psr/cache": "^1.0",
"psr/container": "^1.0",
"symfony/http-foundation": "^3.4 || ^4.0",
"symfony/http-kernel": "^3.4 || ^4.0",
"symfony/property-access": "^3.4 || ^4.0",
"symfony/property-info": "^3.4 || ^4.0",
"symfony/serializer": "^4.3",
"symfony/web-link": "^4.1",
"symfony/http-foundation": "^4.3.6 || ^5.0",
"symfony/http-kernel": "^4.3 || ^5.0",
"symfony/property-access": "^3.4 || ^4.0 || ^5.0",
"symfony/property-info": "^3.4 || ^4.0 || ^5.0",
"symfony/serializer": "^4.3 || ^5.0",
"symfony/web-link": "^4.1 || ^5.0",
"willdurand/negotiation": "^2.0.3"
},
"require-dev": {
Expand All @@ -35,7 +36,7 @@
"doctrine/annotations": "^1.7",
"doctrine/common": "^2.11",
"doctrine/data-fixtures": "^1.2.2",
"doctrine/doctrine-bundle": "^1.8",
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/doctrine-cache-bundle": "^1.3.5",
"doctrine/mongodb-odm": "^2.0",
"doctrine/mongodb-odm-bundle": "^4.0",
Expand All @@ -59,32 +60,32 @@
"ramsey/uuid": "^3.7",
"ramsey/uuid-doctrine": "^1.4",
"sebastian/object-enumerator": "^3.0.3",
"symfony/asset": "^3.4 || ^4.0",
"symfony/browser-kit": "^4.3",
"symfony/cache": "^3.4 || ^4.0",
"symfony/config": "^3.4 || ^4.0",
"symfony/console": "^3.4 || ^4.0",
"symfony/css-selector": "^3.4 || ^4.0",
"symfony/debug": "^3.4 || ^4.0",
"symfony/dependency-injection": "^3.4 || ^4.0",
"symfony/doctrine-bridge": "^3.4 || ^4.0",
"symfony/dom-crawler": "^3.4 || ^4.0",
"symfony/event-dispatcher": "^3.4 || ^4.0",
"symfony/expression-language": "^3.4 || ^4.0",
"symfony/finder": "^3.4 || ^4.0",
"symfony/form": "^3.4 || ^4.0",
"symfony/framework-bundle": "^4.3.2",
"symfony/http-client": "^4.3",
"symfony/asset": "^3.4 || ^4.0 || ^5.0",
"symfony/browser-kit": "^4.3 || ^5.0",
"symfony/cache": "^3.4 || ^4.0 || ^5.0",
"symfony/config": "^3.4 || ^4.0 || ^5.0",
"symfony/console": "^3.4 || ^4.0 || ^5.0",
"symfony/css-selector": "^3.4 || ^4.0 || ^5.0",
"symfony/debug": "^3.4 || ^4.0 || ^5.0",
"symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0",
"symfony/doctrine-bridge": "^3.4 || ^4.0 || ^5.0",
"symfony/dom-crawler": "^3.4 || ^4.0 || ^5.0",
"symfony/event-dispatcher": "^3.4 || ^4.0 || ^5.0",
"symfony/expression-language": "^3.4 || ^4.0 || ^5.0",
"symfony/finder": "^3.4 || ^4.0 || ^5.0",
"symfony/form": "^3.4 || ^4.0 || ^5.0",
"symfony/framework-bundle": "^4.3.2 || ^5.0",
"symfony/http-client": "^4.3 || ^5.0",
"symfony/mercure-bundle": "*",
"symfony/messenger": "^4.3",
"symfony/phpunit-bridge": "^4.3@dev",
"symfony/routing": "^3.4 || ^4.3",
"symfony/security-bundle": "^3.4 || ^4.0",
"symfony/security-core": "^4.3",
"symfony/twig-bundle": "^3.4 || ^4.0",
"symfony/validator": "^3.4 || ^4.0",
"symfony/web-profiler-bundle": "^4.2",
"symfony/yaml": "^3.4 || ^4.0",
"symfony/messenger": "^4.3 || ^5.0",
"symfony/phpunit-bridge": "^4.3 || ^5.0",
"symfony/routing": "^3.4 || ^4.3 || ^5.0",
"symfony/security-bundle": "^3.4 || ^4.0 || ^5.0",
"symfony/security-core": "^4.3 || ^5.0",
"symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0",
"symfony/validator": "^3.4 || ^4.0 || ^5.0",
"symfony/web-profiler-bundle": "^4.2 || ^5.0",
"symfony/yaml": "^3.4 || ^4.0 || ^5.0",
"twig/twig": "^1.42.3 || ^2.12",
"webonyx/graphql-php": ">=0.13.1 <1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion features/main/content_negotiation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Feature: Content Negotiation support
Then the response status code should be 406
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"

Scenario: Post an CSV body allowed on a single resource
Scenario: Post CSV body allowed on a single resource
When I add "Accept" header equal to "application/xml"
And I add "Content-Type" header equal to "text/csv"
And I send a "POST" request to "/dummy_custom_formats" with body:
Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,14 @@ parameters:
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\(Abstract|Exists|Order)Filter::filterProperty\(\) invoked with 7 parameters, 5-6 required\.#'
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\(AbstractFilter|FilterInterface)::apply\(\) invoked with 5 parameters, 3-4 required\.#'
- '#Method ApiPlatform\\Core\\PathResolver\\OperationPathResolverInterface::resolveOperationPath\(\) invoked with 4 parameters, 3 required\.#'

# Expected, due to forward compatibility
-
message: '#Class Symfony\\Component\\ErrorRenderer\\ErrorRenderer not found\.#'
path: %currentWorkingDirectory%/tests/Fixtures/app/AppKernel.php
-
message: '#Parameter \$exception of method ApiPlatform\\Core\\Action\\ExceptionAction::__invoke\(\) has invalid typehint type Symfony\\Component\\ErrorRenderer\\Exception\\FlattenException\.#'
path: %currentWorkingDirectory%/src/Action/ExceptionAction.php
-
message: '#Call to method get(Class|Headers|StatusCode)\(\) on an unknown class Symfony\\Component\\ErrorRenderer\\Exception\\FlattenException\.#'
path: %currentWorkingDirectory%/src/Action/ExceptionAction.php
25 changes: 7 additions & 18 deletions src/Action/ExceptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,14 @@
namespace ApiPlatform\Core\Action;

use ApiPlatform\Core\Util\ErrorFormatGuesser;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\SerializerInterface;

/**
* Renders a normalized exception for a given {@see \Symfony\Component\Debug\Exception\FlattenException}.
*
* Usage:
*
* $exceptionAction = new ExceptionAction(
* new Serializer(),
* [
* 'jsonproblem' => ['application/problem+json'],
* 'jsonld' => ['application/ld+json'],
* ],
* [
* ExceptionInterface::class => Response::HTTP_BAD_REQUEST,
* InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
* ]
* );
* Renders a normalized exception for a given {@see FlattenException} or {@see LegacyFlattenException}.
*
* @author Baptiste Meyer <baptiste.meyer@gmail.com>
* @author Kévin Dunglas <dunglas@gmail.com>
Expand All @@ -46,7 +33,7 @@ final class ExceptionAction
private $exceptionToStatus;

/**
* @param array $errorFormats A list of enabled formats, the first one will be the default
* @param array $errorFormats A list of enabled error formats
* @param array $exceptionToStatus A list of exceptions mapped to their HTTP status code
*/
public function __construct(SerializerInterface $serializer, array $errorFormats, array $exceptionToStatus = [])
Expand All @@ -58,8 +45,10 @@ public function __construct(SerializerInterface $serializer, array $errorFormats

/**
* Converts an exception to a JSON response.
*
* @param FlattenException|LegacyFlattenException $exception
*/
public function __invoke(FlattenException $exception, Request $request): Response
public function __invoke($exception, Request $request): Response
{
$exceptionClass = $exception->getClass();
$statusCode = $exception->getStatusCode();
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/Doctrine/EventListener/WriteListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use ApiPlatform\Core\EventListener\WriteListener as BaseWriteListener;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;

/**
* Bridges Doctrine and the API system.
Expand All @@ -39,10 +39,10 @@ public function __construct(ManagerRegistry $managerRegistry)
/**
* Persists, updates or delete data return by the controller if applicable.
*/
public function onKernelView(GetResponseForControllerResultEvent $event): void
public function onKernelView(ViewEvent $event): void
{
$request = $event->getRequest();
if ($request->isMethodSafe(false)) {
if ($request->isMethodSafe()) {
return;
}

Expand Down
5 changes: 1 addition & 4 deletions src/Bridge/Doctrine/Orm/ItemDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null
$id = $this->normalizeIdentifiers($id, $manager, $resourceClass);
}
if (!\is_array($id)) {
throw new \InvalidArgumentException(sprintf(
'$id must be array when "%s" key is set to true in the $context',
IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER
));
throw new \InvalidArgumentException(sprintf('$id must be array when "%s" key is set to true in the $context', IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER));
}
$identifiers = $id;

Expand Down
Loading