Skip to content

Commit c550dbe

Browse files
Merge pull request #1839 from meyerbaptiste/merge_2.2
Merge 2.2
2 parents 342b92a + 7efe1ff commit c550dbe

File tree

13 files changed

+151
-97
lines changed

13 files changed

+151
-97
lines changed

.travis.yml

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ matrix:
1616
include:
1717
- php: '7.0'
1818
- php: '7.1'
19+
- php: '7.2'
20+
- php: '7.2'
21+
env: coverage=1
1922
- php: '7.2'
2023
env: lint=1
2124
- php: '7.2'
@@ -24,36 +27,84 @@ matrix:
2427
env: SYMFONY_DEPRECATIONS_HELPER=0
2528
- php: '7.2'
2629
services:
27-
- postgresql
30+
- postgresql
2831
before_script:
29-
- psql -c 'create database api_platform_test;' -U postgres
32+
- psql -c 'create database api_platform_test;' -U postgres
3033
env: APP_ENV=postgres
3134
- php: '7.2'
3235
services:
33-
- mysql
36+
- mysql
3437
before_script:
35-
- mysql -e 'CREATE DATABASE api_platform_test;'
38+
- mysql -e 'CREATE DATABASE api_platform_test;'
3639
env: APP_ENV=mysql
3740
allow_failures:
3841
env: SYMFONY_DEPRECATIONS_HELPER=0
3942

4043
before_install:
4144
- phpenv config-rm xdebug.ini || echo "xdebug not available"
4245
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
43-
- npm install -g swagger-cli
44-
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.10.0/php-cs-fixer.phar; fi
45-
- if [[ $lint = 1 ]]; then composer global require --dev 'phpstan/phpstan:^0.8'; fi
46+
- if [[ $coverage != 1 && $lint != 1 ]]; then
47+
npm install -g swagger-cli;
48+
fi
49+
- if [[ $coverage = 1 ]]; then
50+
mkdir -p build/logs build/cov;
51+
fi
52+
- if [[ $coverage = 1 ]]; then
53+
wget https://phar.phpunit.de/phpcov.phar;
54+
fi
55+
- if [[ $coverage = 1 ]]; then
56+
wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar;
57+
fi
58+
- if [[ $lint = 1 ]]; then
59+
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.8.4/php-cs-fixer.phar;
60+
fi
61+
- if [[ $lint = 1 ]]; then
62+
composer global require --dev 'phpstan/phpstan:^0.8';
63+
fi
4664
- export PATH="$PATH:$HOME/.composer/vendor/bin"
4765

4866
install:
49-
- if [[ $deps != 'low' ]]; then composer update --prefer-dist --no-progress --no-suggest --ansi; fi
50-
- if [[ $deps = 'low' ]]; then composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi; fi
67+
- if [[ $coverage = 1 ]]; then
68+
composer require --dev --no-update 'phpunit/php-code-coverage:^5.2.2';
69+
fi
70+
- if [[ $deps = 'low' ]]; then
71+
composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi;
72+
else
73+
composer update --prefer-dist --no-progress --no-suggest --ansi;
74+
fi
5175

5276
script:
53-
- vendor/bin/phpunit
54-
- if [[ $APP_ENV != 'postgres' ]]; then vendor/bin/behat --suite=default --format=progress; fi
55-
- if [[ $APP_ENV = 'postgres' ]]; then vendor/bin/behat --suite=postgres --format=progress; fi
56-
- tests/Fixtures/app/console api:swagger:export > swagger.json && swagger-cli validate swagger.json && rm swagger.json
57-
- tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml
58-
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
59-
- if [[ $lint = 1 ]]; then phpstan analyse -c phpstan.neon -l5 --ansi src tests; fi
77+
- if [[ $coverage = 1 ]]; then
78+
APP_ENV=test_phpunit phpdbg -qrr vendor/bin/phpunit --coverage-php build/cov/coverage-phpunit.cov;
79+
elif [[ $lint != 1 ]]; then
80+
APP_ENV=test_phpunit vendor/bin/phpunit;
81+
fi
82+
- if [[ $coverage = 1 ]]; then
83+
for f in $(find features -name '*.feature' -not -path 'features/main/exposed_state.feature'); do
84+
FEATURE=${f//\//_} phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --tags=~@postgress --format=progress $f || exit $?;
85+
done;
86+
elif [[ $APP_ENV = 'postgres' ]]; then
87+
vendor/bin/behat --suite=postgres --format=progress;
88+
elif [[ $lint != 1 ]]; then
89+
vendor/bin/behat --suite=default --format=progress;
90+
fi
91+
- if [[ $coverage = 1 ]]; then
92+
phpdbg -qrr phpcov.phar merge --clover build/logs/clover.xml build/cov;
93+
fi
94+
- if [[ $coverage != 1 && $lint != 1 ]]; then
95+
tests/Fixtures/app/console api:swagger:export > swagger.json && swagger-cli validate swagger.json && rm swagger.json;
96+
fi
97+
- if [[ $coverage != 1 && $lint != 1 ]]; then
98+
tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml;
99+
fi
100+
- if [[ $lint = 1 ]]; then
101+
php php-cs-fixer.phar fix --dry-run --diff --no-ansi;
102+
fi
103+
- if [[ $lint = 1 ]]; then
104+
phpstan analyse -c phpstan.neon -l5 --ansi src tests;
105+
fi
106+
107+
after_success:
108+
- if [[ $coverage = 1 ]]; then
109+
travis_retry php coveralls.phar;
110+
fi

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 2.2.5
4+
5+
* Fix a various issues preventing the metadata cache to work properly (performance fix)
6+
* Fix a cache corruption issue when using subresources
7+
* Fix non-standard outputs when using the HAL format
8+
* Persist data in Doctrine DataPersister only if needed
9+
* Fix identifiers handling in GraphQL mutations
10+
* Fix client-side ID creation or update when using GraphQL mutations
11+
* Fix an error that was occuring when the Expression Language component wasn't installed
12+
* Update the `ChainSubresourceDataProvider` class to take into account `RestrictedDataProviderInterface`
13+
314
## 2.2.4
415

516
* Fix a BC break preventing to pass non-arrays to the builtin Symfony normalizers when using custom normalizers

Dockerfile.coverage

Lines changed: 0 additions & 30 deletions
This file was deleted.

behat.yml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ default:
3131
extensions:
3232
'Behat\Symfony2Extension':
3333
kernel:
34-
env: '%env(APP_ENV)%'
34+
env: 'test'
3535
debug: 'true'
3636
path: 'tests/Fixtures/app/AppKernel.php'
3737
bootstrap: 'tests/Fixtures/app/bootstrap.php'
@@ -57,3 +57,5 @@ coverage:
5757
- 'CoverageContext'
5858
- 'Behat\MinkExtension\Context\MinkContext'
5959
- 'Behatch\Context\RestContext'
60+
filters:
61+
tags: ~@postgres

brigade.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

features/main/subresource.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Feature: Subresource support
2424
}
2525
"""
2626

27+
Scenario: Get a non existant subresource
28+
Given there is an answer "42" to the question "What's the answer to the Ultimate Question of Life, the Universe and Everything?"
29+
When I send a "GET" request to "/questions/999999/answer"
30+
And the response status code should be 404
31+
And the response should be in JSON
32+
2733
Scenario: Get subresource one to one relation
2834
When I send a "GET" request to "/questions/1/answer/related_questions"
2935
And the response status code should be 200

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ini name="memory_limit" value="-1" />
1313
<server name="KERNEL_DIR" value="tests/Fixtures/app/" />
1414
<server name="KERNEL_CLASS" value="AppKernel" />
15+
<server name="APP_ENV" value="test_phpunit" />
1516
<server name="LEGACY" value="0" />
1617
</php>
1718

src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function load(array $configs, ContainerBuilder $container)
134134
$this->registerApiKeysConfiguration($container, $config, $loader);
135135
$this->registerSwaggerConfiguration($container, $config, $loader);
136136
$this->registerJsonApiConfiguration($formats, $loader);
137-
$this->registerJsonLdConfiguration($formats, $loader);
137+
$this->registerJsonLdConfiguration($container, $formats, $loader, $config['enable_docs']);
138138
$this->registerJsonHalConfiguration($formats, $loader);
139139
$this->registerJsonProblemConfiguration($errorFormats, $loader);
140140
$this->registerGraphqlConfiguration($container, $config, $loader);
@@ -372,17 +372,23 @@ private function registerJsonApiConfiguration(array $formats, XmlFileLoader $loa
372372
/**
373373
* Registers the JSON-LD and Hydra configuration.
374374
*
375-
* @param array $formats
376-
* @param XmlFileLoader $loader
375+
* @param ContainerBuilder $container
376+
* @param array $formats
377+
* @param XmlFileLoader $loader
378+
* @param bool $docEnabled
377379
*/
378-
private function registerJsonLdConfiguration(array $formats, XmlFileLoader $loader)
380+
private function registerJsonLdConfiguration(ContainerBuilder $container, array $formats, XmlFileLoader $loader, bool $docEnabled)
379381
{
380382
if (!isset($formats['jsonld'])) {
381383
return;
382384
}
383385

384386
$loader->load('jsonld.xml');
385387
$loader->load('hydra.xml');
388+
389+
if (!$docEnabled) {
390+
$container->removeDefinition('api_platform.hydra.listener.response.add_link_header');
391+
}
386392
}
387393

388394
/**

src/EventListener/ReadListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ private function getSubresourceData(Request $request, array $attributes, array $
176176

177177
$data = $this->subresourceDataProvider->getSubresource($attributes['resource_class'], $identifiers, $attributes['subresource_context'], $attributes['subresource_operation_name']);
178178

179+
if (null === $data) {
180+
throw new NotFoundHttpException('Not Found.');
181+
}
182+
179183
return $data;
180184
}
181185
}

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,20 @@ public function testRegisterHttpCacheWhenEnabledWithNoRequestOption()
371371
$this->extension->load($config, $containerBuilder);
372372
}
373373

374+
public function testDisabledDocsRemovesAddLinkHeaderService()
375+
{
376+
$containerBuilderProphecy = $this->getBaseContainerBuilderProphecy();
377+
$containerBuilderProphecy->removeDefinition('api_platform.hydra.listener.response.add_link_header')->shouldBeCalled();
378+
$containerBuilderProphecy->setParameter('api_platform.enable_docs', false)->shouldBeCalled();
379+
$containerBuilderProphecy->setParameter('api_platform.enable_docs', true)->shouldNotBeCalled();
380+
$containerBuilder = $containerBuilderProphecy->reveal();
381+
382+
$config = self::DEFAULT_CONFIG;
383+
$config['api_platform']['enable_docs'] = false;
384+
385+
$this->extension->load($config, $containerBuilder);
386+
}
387+
374388
private function getPartialContainerBuilderProphecy($test = false)
375389
{
376390
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);

tests/EventListener/ReadListenerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,30 @@ public function testRetrieveSubresource()
199199
$this->assertSame($data, $request->attributes->get('data'));
200200
}
201201

202+
/**
203+
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
204+
*/
205+
public function testRetrieveSubresourceNotFound()
206+
{
207+
$identifierDenormalizer = $this->prophesize(ChainIdentifierDenormalizer::class);
208+
$identifierDenormalizer->denormalize('1', 'Bar')->willThrow(new InvalidIdentifierException())->shouldBeCalled();
209+
210+
$collectionDataProvider = $this->prophesize(CollectionDataProviderInterface::class);
211+
$collectionDataProvider->getCollection()->shouldNotBeCalled();
212+
213+
$itemDataProvider = $this->prophesize(ItemDataProviderInterface::class);
214+
$itemDataProvider->getItem()->shouldNotBeCalled();
215+
216+
$request = new Request([], [], ['id' => 1, '_api_resource_class' => 'Foo', '_api_subresource_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json', '_api_subresource_context' => ['identifiers' => [['id', 'Bar', true]], 'property' => 'bar']]);
217+
$request->setMethod('GET');
218+
219+
$event = $this->prophesize(GetResponseEvent::class);
220+
$event->getRequest()->willReturn($request)->shouldBeCalled();
221+
222+
$listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $this->prophesize(SubresourceDataProviderInterface::class)->reveal(), null, $identifierDenormalizer->reveal());
223+
$listener->onKernelRequest($event->reveal());
224+
}
225+
202226
/**
203227
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
204228
*/

tests/Fixtures/app/AppKernel.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ class AppKernel extends Kernel
3838
{
3939
use MicroKernelTrait;
4040

41+
public function __construct(string $environment, bool $debug)
42+
{
43+
parent::__construct($environment, $debug);
44+
45+
// patch for behat/symfony2-extension not supporting %env(APP_ENV)%
46+
$this->environment = $_SERVER['APP_ENV'] ?? $environment;
47+
}
48+
4149
public function registerBundles(): array
4250
{
4351
$bundles = [
@@ -69,15 +77,9 @@ protected function configureRoutes(RouteCollectionBuilder $routes)
6977

7078
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
7179
{
72-
$environment = $this->getEnvironment();
7380
$c->setParameter('kernel.project_dir', __DIR__);
7481

75-
// patch for behat not supporting %env(APP_ENV)% in older versions
76-
if (($appEnv = $_SERVER['APP_ENV'] ?? 'test') && $appEnv !== $environment) {
77-
$environment = $appEnv;
78-
}
79-
80-
$loader->load("{$this->getRootDir()}/config/config_{$environment}.yml");
82+
$loader->load("{$this->getRootDir()}/config/config_{$this->getEnvironment()}.yml");
8183

8284
$securityConfig = [
8385
'encoders' => [
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
imports:
2+
- { resource: config_test.yml }

0 commit comments

Comments
 (0)