Skip to content

Commit

Permalink
Merge branch 'api-platform:main' into feat/debug-resource-command
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelbigard committed Aug 31, 2021
2 parents df8143f + bdd8c9b commit edeefa5
Show file tree
Hide file tree
Showing 123 changed files with 3,824 additions and 750 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -767,6 +767,83 @@ jobs:
- name: Run Behat tests
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction

behat-rector-upgrade:
name: Behat (PHP ${{ matrix.php }}) (Rector)
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
php:
- '8.0'
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: pecl, composer
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite
ini-values: memory_limit=-1
- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Allow unstable project dependencies
run: composer config minimum-stability dev
- name: Require Symfony components and Rector dependencies
run: composer require symfony/intl symfony/uid rector/rector-src nikic/php-parser --dev --no-interaction --no-progress --ansi
- 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: rm -Rf tests/Fixtures/app/var/cache/*
- name: Convert annotations to attributes
run: |
tests/Fixtures/app/console api:rector:upgrade tests/Fixtures/TestBundle/Document --transform-apisubresource -s
tests/Fixtures/app/console api:rector:upgrade tests/Fixtures/TestBundle/Document --annotation-to-api-resource -s
tests/Fixtures/app/console api:rector:upgrade tests/Fixtures/TestBundle/Entity --transform-apisubresource -s
tests/Fixtures/app/console api:rector:upgrade tests/Fixtures/TestBundle/Entity --annotation-to-api-resource -s
- name: Run Behat tests
run: |
mkdir -p build/logs/behat
vendor/bin/behat --out=std --format=progress --format=junit --out=build/logs/behat/junit --profile=default --no-interaction
continue-on-error: true
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v1
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 --spec-version=2 -o build/out/openapi/swagger_v2.json
tests/Fixtures/app/console api:openapi:export --spec-version=2 --yaml -o build/out/openapi/swagger_v2.yaml
tests/Fixtures/app/console api:openapi:export --spec-version=3 -o build/out/openapi/openapi_v3.json
tests/Fixtures/app/console api:openapi:export --spec-version=3 --yaml -o build/out/openapi/openapi_v3.yaml
- name: Validate OpenAPI documents
run: |
npx swagger-cli validate build/out/openapi/swagger_v2.json
npx swagger-cli validate build/out/openapi/swagger_v2.yaml
npx swagger-cli validate build/out/openapi/openapi_v3.json
npx swagger-cli validate build/out/openapi/openapi_v3.yaml
- name: Upload OpenAPI artifacts
if: always()
uses: actions/upload-artifact@v1
with:
name: openapi-docs-php${{ matrix.php }}
path: build/out/openapi
continue-on-error: true

windows-phpunit:
name: Windows PHPUnit (PHP ${{ matrix.php }}) (SQLite)
runs-on: windows-latest
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -99,6 +99,7 @@
"phpdocumentor/reflection-docblock": "To support extracting metadata from PHPDoc.",
"psr/cache-implementation": "To use metadata caching.",
"ramsey/uuid": "To support Ramsey's UUID identifiers.",
"rector/rector-src": "To support converting PHP annotations to attributes.",
"symfony/cache": "To have metadata caching when using Symfony integration.",
"symfony/config": "To load XML configuration files.",
"symfony/expression-language": "To use authorization features.",
Expand Down
4 changes: 2 additions & 2 deletions features/hydra/docs.feature
Expand Up @@ -76,8 +76,8 @@ Feature: Documentation support
And the value of the node "@type" of the operation "GET" of the Hydra class "Dummy" contains "hydra:Operation"
And the value of the node "@type" of the operation "GET" of the Hydra class "Dummy" contains "schema:FindAction"
And the value of the node "hydra:method" of the operation "GET" of the Hydra class "Dummy" is "GET"
And the value of the node "hydra:title" of the operation "GET" of the Hydra class "Dummy" is "Retrieves Dummy resource."
And the value of the node "rdfs:label" of the operation "GET" of the Hydra class "Dummy" is "Retrieves Dummy resource."
And the value of the node "hydra:title" of the operation "GET" of the Hydra class "Dummy" is "Retrieves a Dummy resource."
And the value of the node "rdfs:label" of the operation "GET" of the Hydra class "Dummy" is "Retrieves a Dummy resource."
And the value of the node "returns" of the operation "GET" of the Hydra class "Dummy" is "#Dummy"
And the value of the node "hydra:title" of the operation "PUT" of the Hydra class "Dummy" is "Replaces the Dummy resource."
And the value of the node "hydra:title" of the operation "DELETE" of the Hydra class "Dummy" is "Deletes the Dummy resource."
Expand Down
9 changes: 7 additions & 2 deletions phpstan.neon.dist
Expand Up @@ -38,15 +38,20 @@ parameters:
- tests/Fixtures/TestBundle/Security/AbstractSecurityUser.php
# Templates for Maker
- src/Core/Bridge/Symfony/Maker/Resources/skeleton
- src/Bridge/Symfony/Maker/Resources/skeleton
# Rector because new API Platform 3.0 classes don't exist yet
- src/Core/Bridge/Rector
- src/Core/Bridge/Symfony/Bundle/Command/RectorCommand.php
- tests/Core/Bridge/Rector/Rules
earlyTerminatingMethodCalls:
PHPUnit\Framework\Constraint\Constraint:
- fail
ApiPlatform\Metadata\Resource\ResourceMetadataCollection:
- handleNotFound
- handleNotFound
ignoreErrors:
# False positives
- '#Parameter \#1 \$callback of function call_user_func expects callable\(\): mixed, non-empty-string given\.#'
-
-
message: '#Unreachable statement - code above always terminates.#'
paths:
- tests/GraphQl/Resolver/Stage/SecurityPostDenormalizeStageTest.php
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -32,6 +32,7 @@
<directory>src/Bridge/NelmioApiDoc</directory>
<directory>src/Bridge/FosUser</directory>
<directory>src/Bridge/Symfony/Maker/Resources/skeleton</directory>
<directory>src/Core/Bridge/Rector</directory>
<file>.php-cs-fixer.dist.php</file>
<file>src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php</file>
<file>src/Bridge/Symfony/Bundle/Test/Constraint/ArraySubsetLegacy.php</file>
Expand Down
2 changes: 1 addition & 1 deletion src/Api/IdentifiersExtractor.php
Expand Up @@ -113,6 +113,6 @@ private function resolveIdentifierValue($item, string $class, string $property)
}
}

throw new \RuntimeException('Not able to retrieve identifiers.');
throw new RuntimeException('Not able to retrieve identifiers.');
}
}
3 changes: 2 additions & 1 deletion src/Bridge/Symfony/Routing/IriConverter.php
Expand Up @@ -130,6 +130,7 @@ public function getIriFromItem($item, string $operationName = null, int $referen
($operation->getExtraProperties()['is_legacy_subresource'] ?? false) ||
($operation->getExtraProperties()['user_defined_uri_template'] ?? false) ||
($operation->getExtraProperties()['is_alternate_resource_metadata'] ?? false) ||
($operation->getExtraProperties()['legacy_subresource_behavior'] ?? false) ||
// When we want the Iri from an object, we don't want the collection uriTemplate, for this we use getIriFromResourceClass
$operation->isCollection()
) {
Expand Down Expand Up @@ -191,7 +192,7 @@ public function getIriFromResourceClass(string $resourceClass, string $operation
trigger_deprecation('api-platform/core', '2.7', 'The IRI will change and match the first operation of the resource. Switch to an alternate resource when possible instead of using subresources.');
$operationName = $operation->getExtraProperties()['legacy_subresource_operation_name'];
$operation = null;
} elseif ($operation->getExtraProperties()['user_defined_uri_template'] ?? false) {
} elseif (!($operation->getExtraProperties()['is_alternate_resource_metadata'] ?? false) && ($operation->getExtraProperties()['user_defined_uri_template'] ?? false)) {
$operation = null;
$operationName = null;
}
Expand Down
21 changes: 21 additions & 0 deletions src/Core/Annotation/TemporaryApiResource.php
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Annotation;

final class TemporaryApiResource
{
public function __construct()
{
}
}
Expand Up @@ -131,8 +131,7 @@ private function gatherResourceAndItemTags($entity, bool $purgeItem): void
if ($purgeItem) {
$this->addTagForItem($entity);
}
} catch (InvalidArgumentException $e) {
} catch (OperationNotFoundException $e) {
} catch (OperationNotFoundException|InvalidArgumentException $e) {
}
}

Expand Down Expand Up @@ -173,8 +172,7 @@ private function addTagForItem($value): void
//TODO: test if this is a resource class
$iri = $this->iriConverter->getIriFromItem($value);
$this->tags[$iri] = $iri;
} catch (InvalidArgumentException $e) {
} catch (RuntimeException $e) {
} catch (RuntimeException|InvalidArgumentException $e) {
}
}
}
Expand Up @@ -199,11 +199,9 @@ private function getPagination(QueryBuilder $queryBuilder, string $resourceClass
}

if (null === $request) {
if (!$this->pagination->isEnabled($resourceClass, $operationName, $context)) {
return null;
}
$enabled = isset($context['graphql_operation_name']) ? $this->pagination->isGraphQlEnabled($resourceClass, $operationName, $context) : $this->pagination->isEnabled($resourceClass, $operationName, $context);

if (($context['graphql_operation_name'] ?? false) && !$this->pagination->isGraphQlEnabled($resourceClass, $operationName, $context)) {
if (!$enabled) {
return null;
}

Expand Down

0 comments on commit edeefa5

Please sign in to comment.