Skip to content

Commit

Permalink
Merge pull request #1839 from meyerbaptiste/merge_2.2
Browse files Browse the repository at this point in the history
Merge 2.2
  • Loading branch information
meyerbaptiste committed Apr 10, 2018
2 parents 342b92a + 7efe1ff commit c550dbe
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 97 deletions.
83 changes: 67 additions & 16 deletions .travis.yml
Expand Up @@ -16,6 +16,9 @@ matrix:
include:
- php: '7.0'
- php: '7.1'
- php: '7.2'
- php: '7.2'
env: coverage=1
- php: '7.2'
env: lint=1
- php: '7.2'
Expand All @@ -24,36 +27,84 @@ matrix:
env: SYMFONY_DEPRECATIONS_HELPER=0
- php: '7.2'
services:
- postgresql
- postgresql
before_script:
- psql -c 'create database api_platform_test;' -U postgres
- psql -c 'create database api_platform_test;' -U postgres
env: APP_ENV=postgres
- php: '7.2'
services:
- mysql
- mysql
before_script:
- mysql -e 'CREATE DATABASE api_platform_test;'
- mysql -e 'CREATE DATABASE api_platform_test;'
env: APP_ENV=mysql
allow_failures:
env: SYMFONY_DEPRECATIONS_HELPER=0

before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- npm install -g swagger-cli
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.10.0/php-cs-fixer.phar; fi
- if [[ $lint = 1 ]]; then composer global require --dev 'phpstan/phpstan:^0.8'; fi
- if [[ $coverage != 1 && $lint != 1 ]]; then
npm install -g swagger-cli;
fi
- if [[ $coverage = 1 ]]; then
mkdir -p build/logs build/cov;
fi
- if [[ $coverage = 1 ]]; then
wget https://phar.phpunit.de/phpcov.phar;
fi
- if [[ $coverage = 1 ]]; then
wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar;
fi
- if [[ $lint = 1 ]]; then
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.8.4/php-cs-fixer.phar;
fi
- if [[ $lint = 1 ]]; then
composer global require --dev 'phpstan/phpstan:^0.8';
fi
- export PATH="$PATH:$HOME/.composer/vendor/bin"

install:
- if [[ $deps != 'low' ]]; then composer update --prefer-dist --no-progress --no-suggest --ansi; fi
- if [[ $deps = 'low' ]]; then composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi; fi
- if [[ $coverage = 1 ]]; then
composer require --dev --no-update 'phpunit/php-code-coverage:^5.2.2';
fi
- if [[ $deps = 'low' ]]; then
composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi;
else
composer update --prefer-dist --no-progress --no-suggest --ansi;
fi

script:
- vendor/bin/phpunit
- if [[ $APP_ENV != 'postgres' ]]; then vendor/bin/behat --suite=default --format=progress; fi
- if [[ $APP_ENV = 'postgres' ]]; then vendor/bin/behat --suite=postgres --format=progress; fi
- tests/Fixtures/app/console api:swagger:export > swagger.json && swagger-cli validate swagger.json && rm swagger.json
- tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
- if [[ $lint = 1 ]]; then phpstan analyse -c phpstan.neon -l5 --ansi src tests; fi
- if [[ $coverage = 1 ]]; then
APP_ENV=test_phpunit phpdbg -qrr vendor/bin/phpunit --coverage-php build/cov/coverage-phpunit.cov;
elif [[ $lint != 1 ]]; then
APP_ENV=test_phpunit vendor/bin/phpunit;
fi
- if [[ $coverage = 1 ]]; then
for f in $(find features -name '*.feature' -not -path 'features/main/exposed_state.feature'); do
FEATURE=${f//\//_} phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --tags=~@postgress --format=progress $f || exit $?;
done;
elif [[ $APP_ENV = 'postgres' ]]; then
vendor/bin/behat --suite=postgres --format=progress;
elif [[ $lint != 1 ]]; then
vendor/bin/behat --suite=default --format=progress;
fi
- if [[ $coverage = 1 ]]; then
phpdbg -qrr phpcov.phar merge --clover build/logs/clover.xml build/cov;
fi
- if [[ $coverage != 1 && $lint != 1 ]]; then
tests/Fixtures/app/console api:swagger:export > swagger.json && swagger-cli validate swagger.json && rm swagger.json;
fi
- if [[ $coverage != 1 && $lint != 1 ]]; then
tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml;
fi
- if [[ $lint = 1 ]]; then
php php-cs-fixer.phar fix --dry-run --diff --no-ansi;
fi
- if [[ $lint = 1 ]]; then
phpstan analyse -c phpstan.neon -l5 --ansi src tests;
fi

after_success:
- if [[ $coverage = 1 ]]; then
travis_retry php coveralls.phar;
fi
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,16 @@
# Changelog

## 2.2.5

* Fix a various issues preventing the metadata cache to work properly (performance fix)
* Fix a cache corruption issue when using subresources
* Fix non-standard outputs when using the HAL format
* Persist data in Doctrine DataPersister only if needed
* Fix identifiers handling in GraphQL mutations
* Fix client-side ID creation or update when using GraphQL mutations
* Fix an error that was occuring when the Expression Language component wasn't installed
* Update the `ChainSubresourceDataProvider` class to take into account `RestrictedDataProviderInterface`

## 2.2.4

* Fix a BC break preventing to pass non-arrays to the builtin Symfony normalizers when using custom normalizers
Expand Down
30 changes: 0 additions & 30 deletions Dockerfile.coverage

This file was deleted.

4 changes: 3 additions & 1 deletion behat.yml.dist
Expand Up @@ -31,7 +31,7 @@ default:
extensions:
'Behat\Symfony2Extension':
kernel:
env: '%env(APP_ENV)%'
env: 'test'
debug: 'true'
path: 'tests/Fixtures/app/AppKernel.php'
bootstrap: 'tests/Fixtures/app/bootstrap.php'
Expand All @@ -57,3 +57,5 @@ coverage:
- 'CoverageContext'
- 'Behat\MinkExtension\Context\MinkContext'
- 'Behatch\Context\RestContext'
filters:
tags: ~@postgres
39 changes: 0 additions & 39 deletions brigade.js

This file was deleted.

6 changes: 6 additions & 0 deletions features/main/subresource.feature
Expand Up @@ -24,6 +24,12 @@ Feature: Subresource support
}
"""

Scenario: Get a non existant subresource
Given there is an answer "42" to the question "What's the answer to the Ultimate Question of Life, the Universe and Everything?"
When I send a "GET" request to "/questions/999999/answer"
And the response status code should be 404
And the response should be in JSON

Scenario: Get subresource one to one relation
When I send a "GET" request to "/questions/1/answer/related_questions"
And the response status code should be 200
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -12,6 +12,7 @@
<ini name="memory_limit" value="-1" />
<server name="KERNEL_DIR" value="tests/Fixtures/app/" />
<server name="KERNEL_CLASS" value="AppKernel" />
<server name="APP_ENV" value="test_phpunit" />
<server name="LEGACY" value="0" />
</php>

Expand Down
Expand Up @@ -134,7 +134,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerApiKeysConfiguration($container, $config, $loader);
$this->registerSwaggerConfiguration($container, $config, $loader);
$this->registerJsonApiConfiguration($formats, $loader);
$this->registerJsonLdConfiguration($formats, $loader);
$this->registerJsonLdConfiguration($container, $formats, $loader, $config['enable_docs']);
$this->registerJsonHalConfiguration($formats, $loader);
$this->registerJsonProblemConfiguration($errorFormats, $loader);
$this->registerGraphqlConfiguration($container, $config, $loader);
Expand Down Expand Up @@ -372,17 +372,23 @@ private function registerJsonApiConfiguration(array $formats, XmlFileLoader $loa
/**
* Registers the JSON-LD and Hydra configuration.
*
* @param array $formats
* @param XmlFileLoader $loader
* @param ContainerBuilder $container
* @param array $formats
* @param XmlFileLoader $loader
* @param bool $docEnabled
*/
private function registerJsonLdConfiguration(array $formats, XmlFileLoader $loader)
private function registerJsonLdConfiguration(ContainerBuilder $container, array $formats, XmlFileLoader $loader, bool $docEnabled)
{
if (!isset($formats['jsonld'])) {
return;
}

$loader->load('jsonld.xml');
$loader->load('hydra.xml');

if (!$docEnabled) {
$container->removeDefinition('api_platform.hydra.listener.response.add_link_header');
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/EventListener/ReadListener.php
Expand Up @@ -176,6 +176,10 @@ private function getSubresourceData(Request $request, array $attributes, array $

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

if (null === $data) {
throw new NotFoundHttpException('Not Found.');
}

return $data;
}
}
Expand Up @@ -371,6 +371,20 @@ public function testRegisterHttpCacheWhenEnabledWithNoRequestOption()
$this->extension->load($config, $containerBuilder);
}

public function testDisabledDocsRemovesAddLinkHeaderService()
{
$containerBuilderProphecy = $this->getBaseContainerBuilderProphecy();
$containerBuilderProphecy->removeDefinition('api_platform.hydra.listener.response.add_link_header')->shouldBeCalled();
$containerBuilderProphecy->setParameter('api_platform.enable_docs', false)->shouldBeCalled();
$containerBuilderProphecy->setParameter('api_platform.enable_docs', true)->shouldNotBeCalled();
$containerBuilder = $containerBuilderProphecy->reveal();

$config = self::DEFAULT_CONFIG;
$config['api_platform']['enable_docs'] = false;

$this->extension->load($config, $containerBuilder);
}

private function getPartialContainerBuilderProphecy($test = false)
{
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
Expand Down
24 changes: 24 additions & 0 deletions tests/EventListener/ReadListenerTest.php
Expand Up @@ -199,6 +199,30 @@ public function testRetrieveSubresource()
$this->assertSame($data, $request->attributes->get('data'));
}

/**
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testRetrieveSubresourceNotFound()
{
$identifierDenormalizer = $this->prophesize(ChainIdentifierDenormalizer::class);
$identifierDenormalizer->denormalize('1', 'Bar')->willThrow(new InvalidIdentifierException())->shouldBeCalled();

$collectionDataProvider = $this->prophesize(CollectionDataProviderInterface::class);
$collectionDataProvider->getCollection()->shouldNotBeCalled();

$itemDataProvider = $this->prophesize(ItemDataProviderInterface::class);
$itemDataProvider->getItem()->shouldNotBeCalled();

$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']]);
$request->setMethod('GET');

$event = $this->prophesize(GetResponseEvent::class);
$event->getRequest()->willReturn($request)->shouldBeCalled();

$listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $this->prophesize(SubresourceDataProviderInterface::class)->reveal(), null, $identifierDenormalizer->reveal());
$listener->onKernelRequest($event->reveal());
}

/**
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
Expand Down
16 changes: 9 additions & 7 deletions tests/Fixtures/app/AppKernel.php
Expand Up @@ -38,6 +38,14 @@ class AppKernel extends Kernel
{
use MicroKernelTrait;

public function __construct(string $environment, bool $debug)
{
parent::__construct($environment, $debug);

// patch for behat/symfony2-extension not supporting %env(APP_ENV)%
$this->environment = $_SERVER['APP_ENV'] ?? $environment;
}

public function registerBundles(): array
{
$bundles = [
Expand Down Expand Up @@ -69,15 +77,9 @@ protected function configureRoutes(RouteCollectionBuilder $routes)

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

// patch for behat not supporting %env(APP_ENV)% in older versions
if (($appEnv = $_SERVER['APP_ENV'] ?? 'test') && $appEnv !== $environment) {
$environment = $appEnv;
}

$loader->load("{$this->getRootDir()}/config/config_{$environment}.yml");
$loader->load("{$this->getRootDir()}/config/config_{$this->getEnvironment()}.yml");

$securityConfig = [
'encoders' => [
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/app/config/config_test_phpunit.yml
@@ -0,0 +1,2 @@
imports:
- { resource: config_test.yml }

0 comments on commit c550dbe

Please sign in to comment.