Skip to content

Commit

Permalink
Merge f2f4241 into 2625c81
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Nov 5, 2021
2 parents 2625c81 + f2f4241 commit ccdaf29
Show file tree
Hide file tree
Showing 43 changed files with 3,864 additions and 35 deletions.
51 changes: 47 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERAGE: '0'
SYMFONY_DEPRECATIONS_HELPER: disabled=1
# SYMFONY_PHPUNIT_DIR: vendor/bin/.phpunit

jobs:
php-cs-fixer:
Expand Down Expand Up @@ -132,12 +133,12 @@ jobs:
run: |
composer remove --dev --no-interaction --no-progress --no-update --ansi \
doctrine/mongodb-odm \
doctrine/mongodb-odm-bundle \
doctrine/mongodb-odm-bundle
- name: Remove ElasticSearch
if: startsWith(matrix.php, '7.1') || startsWith(matrix.php, '7.2')
run: |
composer remove --dev --no-interaction --no-progress --no-update --ansi \
elasticsearch/elasticsearch \
elasticsearch/elasticsearch
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Require Symfony components
Expand Down Expand Up @@ -228,12 +229,12 @@ jobs:
run: |
composer remove --dev --no-interaction --no-progress --no-update --ansi \
doctrine/mongodb-odm \
doctrine/mongodb-odm-bundle \
doctrine/mongodb-odm-bundle
- name: Remove ElasticSearch
if: startsWith(matrix.php, '7.1') || startsWith(matrix.php, '7.2')
run: |
composer remove --dev --no-interaction --no-progress --no-update --ansi \
elasticsearch/elasticsearch \
elasticsearch/elasticsearch
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Require Symfony components
Expand Down Expand Up @@ -402,6 +403,48 @@ jobs:
# @TODO remove the tag "@symfony/uid" in 3.0
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction --tags='~@symfony/uid&&~php8'

behat-orm-v3:
name: Behat (PHP ${{ matrix.php }}) (ORM v3)
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
coverage: none
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: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Require Symfony components
run: composer require symfony/intl symfony/uid --dev --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
env:
APP_ENV: orm_v3
run: vendor/bin/behat --out=std --format=progress --profile=orm_v3 --no-interaction

postgresql:
name: Behat (PHP ${{ matrix.php }}) (PostgreSQL)
runs-on: ubuntu-latest
Expand Down
15 changes: 10 additions & 5 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&&~@orm_v3'
extensions:
'FriendsOfBehat\SymfonyExtension':
bootstrap: 'tests/Fixtures/app/bootstrap.php'
Expand All @@ -33,6 +33,12 @@ default:
symfony: ~
'Behatch\Extension': ~

orm_v3:
suites:
default:
filters:
tags: '@orm_v3'

postgres:
suites:
default: false
Expand All @@ -52,7 +58,7 @@ postgres:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@sqlite&&~@mongodb&&~@elasticsearch'
tags: '~@sqlite&&~@mongodb&&~@elasticsearch&&~@orm_v3'

mongodb:
suites:
Expand All @@ -73,7 +79,7 @@ mongodb:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@sqlite&&~@elasticsearch&&~@!mongodb'
tags: '~@sqlite&&~@elasticsearch&&~@!mongodb&&~@orm_v3'

elasticsearch:
suites:
Expand All @@ -89,7 +95,7 @@ elasticsearch:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '@elasticsearch'
tags: '@elasticsearch&&~@orm_v3'

default-coverage:
suites:
Expand Down Expand Up @@ -143,4 +149,3 @@ elasticsearch-coverage:
- 'ApiPlatform\Core\Tests\Behat\CoverageContext'
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'

129 changes: 129 additions & 0 deletions features/main/crud_v3.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
@orm_v3
Feature: Create-Retrieve-Update-Delete
In order to use an hypermedia API
As a client software developer
I need to be able to retrieve, create, update and delete JSON-LD encoded resources.

@createSchema
Scenario: Get a resource in v3 configured in YAML
Given there is a Program
When I send a "GET" request to "/programs/1"
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/Program",
"@id": "/programs/1",
"@type": "Program",
"id": 1,
"name": "Lorem ipsum 1",
"date": "2015-03-01T10:00:00+00:00",
"author": "/users/1"
}
"""

Scenario: Get a collection resource in v3 configured in YAML
Given there are 3 Programs
When I send a "GET" request to "/users/1/programs"
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/Program",
"@id": "/users/1/programs",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "/programs/1",
"@type": "Program",
"id": 1,
"name": "Lorem ipsum 1",
"date": "2015-03-01T10:00:00+00:00",
"author": "/users/1"
},
{
"@id": "/programs/2",
"@type": "Program",
"id": 2,
"name": "Lorem ipsum 2",
"date": "2015-03-02T10:00:00+00:00",
"author": "/users/1"
},
{
"@id": "/programs/3",
"@type": "Program",
"id": 3,
"name": "Lorem ipsum 3",
"date": "2015-03-03T10:00:00+00:00",
"author": "/users/1"
}
],
"hydra:totalItems": 3
}
"""

Scenario: Get a resource in v3 configured in XML
Given there is a Comment
When I send a "GET" request to "/comments/1"
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/Comment",
"@id": "/comments/1",
"@type": "Comment",
"id": 1,
"comment": "Lorem ipsum dolor sit amet 1",
"date": "2015-03-01T10:00:00+00:00",
"author": "/users/1"
}
"""

@dropSchema
Scenario: Get a collection resource in v3 configured in XML
Given there are 3 Comments
When I send a "GET" request to "/users/1/comments"
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/Comment",
"@id": "/users/1/comments",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "/comments/1",
"@type": "Comment",
"id": 1,
"comment": "Lorem ipsum dolor sit amet 1",
"date": "2015-03-01T10:00:00+00:00",
"author": "/users/1"
},
{
"@id": "/comments/2",
"@type": "Comment",
"id": 2,
"comment": "Lorem ipsum dolor sit amet 2",
"date": "2015-03-02T10:00:00+00:00",
"author": "/users/1"
},
{
"@id": "/comments/3",
"@type": "Comment",
"id": 3,
"comment": "Lorem ipsum dolor sit amet 3",
"date": "2015-03-03T10:00:00+00:00",
"author": "/users/1"
}
],
"hydra:totalItems": 3
}
"""
2 changes: 0 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<ini name="error_reporting" value="-1" />
<ini name="memory_limit" value="-1" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
<!-- This is necessary for GitHub Actions to work properly -->
<server name="SYMFONY_PHPUNIT_DIR" value="vendor/bin/.phpunit" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml" />
<server name="KERNEL_DIR" value="tests/Fixtures/app/" />
<server name="KERNEL_CLASS" value="AppKernel" />
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Bridge/Doctrine/Orm/Util/QueryBuilderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Doctrine\Persistence\ManagerRegistry;

/**
* @author Vincent Chalamon <vincent@les-tilleuls.coop>
* @author Vincent Chalamon <vincentchalamon@gmail.com>
*
* @internal
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory.legacy_subresource_metadata.inner" />
</service>

<service id="api_platform.metadata.resource.metadata_collection_factory.extractor.xml" class="ApiPlatform\Metadata\Resource\Factory\ExtractorResourceMetadataCollectionFactory" decorates="api_platform.metadata.resource.metadata_collection_factory" decoration-priority="800" public="false">
<argument type="service" id="api_platform.metadata.extractor.xml" />
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory.extractor.xml.inner" />
<argument>%api_platform.defaults%</argument>
</service>

<service id="api_platform.metadata.resource.metadata_collection_factory.uri_template" class="ApiPlatform\Metadata\Resource\Factory\UriTemplateResourceMetadataCollectionFactory" decorates="api_platform.metadata.resource.metadata_collection_factory" decoration-priority="500" public="false">
<argument type="service" id="api_platform.path_segment_name_generator" />
<argument type="service" id="api_platform.metadata.property.name_collection_factory" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="api_platform.metadata.extractor.xml" class="ApiPlatform\Core\Metadata\Extractor\XmlExtractor" public="false">
<service id="api_platform.metadata.extractor.xml" class="ApiPlatform\Metadata\Extractor\XmlExtractor" public="false">
<argument type="collection" />
<argument type="service" id="service_container" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="api_platform.metadata.extractor.yaml" class="ApiPlatform\Core\Metadata\Extractor\YamlExtractor" public="false">
<service id="api_platform.metadata.extractor.yaml" class="ApiPlatform\Metadata\Extractor\YamlExtractor" public="false">
<argument type="collection" />
<argument type="service" id="service_container" />
</service>
Expand All @@ -30,6 +30,12 @@
<argument type="service" id="api_platform.metadata.extractor.yaml" />
<argument type="service" id="api_platform.metadata.property.metadata_factory.yaml.inner" />
</service>

<service id="api_platform.metadata.resource.metadata_collection_factory.extractor.yaml" class="ApiPlatform\Metadata\Resource\Factory\ExtractorResourceMetadataCollectionFactory" decorates="api_platform.metadata.resource.metadata_collection_factory" decoration-priority="800" public="false">
<argument type="service" id="api_platform.metadata.extractor.yaml" />
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory.extractor.yaml.inner" />
<argument>%api_platform.defaults%</argument>
</service>
</services>

</container>
3 changes: 3 additions & 0 deletions src/Core/Metadata/Extractor/XmlExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace ApiPlatform\Core\Metadata\Extractor;

use ApiPlatform\Exception\InvalidArgumentException;
use ApiPlatform\Metadata\Extractor\AbstractExtractor;
use Symfony\Component\Config\Util\XmlUtils;

/**
Expand All @@ -22,6 +23,8 @@
* @author Kévin Dunglas <dunglas@gmail.com>
* @author Antoine Bluchet <soyuka@gmail.com>
* @author Baptiste Meyer <baptiste.meyer@gmail.com>
*
* @deprecated since 2.7, to remove in 3.0 (replaced by ApiPlatform\Metadata\Extractor\XmlExtractor)
*/
final class XmlExtractor extends AbstractExtractor
{
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Metadata/Extractor/YamlExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace ApiPlatform\Core\Metadata\Extractor;

use ApiPlatform\Exception\InvalidArgumentException;
use ApiPlatform\Metadata\Extractor\AbstractExtractor;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;

Expand All @@ -23,6 +24,8 @@
* @author Antoine Bluchet <soyuka@gmail.com>
* @author Baptiste Meyer <baptiste.meyer@gmail.com>
* @author Kévin Dunglas <dunglas@gmail.com>
*
* @deprecated since 2.7, to remove in 3.0 (replaced by ApiPlatform\Metadata\Extractor\YamlExtractor)
*/
final class YamlExtractor extends AbstractExtractor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace ApiPlatform\Core\Metadata\Resource\Factory;

use ApiPlatform\Core\Metadata\Extractor\ExtractorInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use ApiPlatform\Exception\ResourceClassNotFoundException;
use ApiPlatform\Metadata\Extractor\ExtractorInterface;

/**
* Creates resource's metadata using an extractor.
Expand Down Expand Up @@ -60,7 +60,7 @@ public function create(string $resourceClass): ResourceMetadata
$resource['collectionOperations'] = $resource['collectionOperations'] ?? $this->defaults['collection_operations'] ?? null;
$resource['graphql'] = $resource['graphql'] ?? $this->defaults['graphql'] ?? null;

if (null !== $resource['attributes'] || [] !== $this->defaults['attributes']) {
if (\array_key_exists('attributes', $resource) && (null !== $resource['attributes'] || [] !== $this->defaults['attributes'])) {
$resource['attributes'] = (array) $resource['attributes'];
foreach ($this->defaults['attributes'] as $key => $value) {
if (!isset($resource['attributes'][$key])) {
Expand Down Expand Up @@ -92,7 +92,7 @@ private function handleNotFound(?ResourceMetadata $parentPropertyMetadata, strin
private function update(ResourceMetadata $resourceMetadata, array $metadata): ResourceMetadata
{
foreach (['shortName', 'description', 'iri', 'itemOperations', 'collectionOperations', 'subresourceOperations', 'graphql', 'attributes'] as $property) {
if (null === $metadata[$property] || null !== $resourceMetadata->{'get'.ucfirst($property)}()) {
if (!\array_key_exists($property, $metadata) || null === $metadata[$property] || null !== $resourceMetadata->{'get'.ucfirst($property)}()) {
continue;
}

Expand Down

0 comments on commit ccdaf29

Please sign in to comment.