Skip to content

Commit

Permalink
Merge pull request #3913 from dunglas/fix/merge-2.5
Browse files Browse the repository at this point in the history
Fix/merge 2.5
  • Loading branch information
dunglas committed Dec 17, 2020
2 parents 76ca535 + 9d2244b commit 75deb1a
Show file tree
Hide file tree
Showing 34 changed files with 88 additions and 105 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/ci.yml
Expand Up @@ -100,7 +100,7 @@ jobs:
- '7.2'
- '7.3'
- '7.4'
- 'rc'
- '8.0'
include:
- php: '7.4'
coverage: true
Expand Down Expand Up @@ -129,13 +129,13 @@ jobs:
if: matrix.coverage
run: echo "COVERAGE=1" >> $GITHUB_ENV
- name: Remove Doctrine MongoDB ODM
if: (startsWith(matrix.php, '7.1') || startsWith(matrix.php, 'rc'))
if: (startsWith(matrix.php, '7.1') || startsWith(matrix.php, '8.0'))
run: |
composer remove --dev --no-interaction --no-progress --no-update --ansi \
doctrine/mongodb-odm \
doctrine/mongodb-odm-bundle \
- name: Set Composer platform config
if: (startsWith(matrix.php, 'rc'))
if: (startsWith(matrix.php, '8.0'))
run: |
composer config platform.php 7.4.99
- name: Update project dependencies
Expand All @@ -146,10 +146,10 @@ jobs:
- name: Install PHPUnit
run: vendor/bin/simple-phpunit --version
- name: Clear test app cache
if: (!startsWith(matrix.php, 'rc'))
if: (!startsWith(matrix.php, '8.0'))
run: tests/Fixtures/app/console cache:clear --ansi
- name: Clear test app cache (php rc)
if: (startsWith(matrix.php, 'rc'))
- name: Clear test app cache (php 8.0)
if: (startsWith(matrix.php, '8.0'))
run: rm -Rf tests/Fixtures/app/var/cache/*
- name: Run PHPUnit tests
run: |
Expand Down Expand Up @@ -195,7 +195,7 @@ jobs:
- '7.2'
- '7.3'
- '7.4'
- 'rc'
- '8.0'
include:
- php: '7.4'
coverage: true
Expand All @@ -211,6 +211,10 @@ jobs:
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite
coverage: pcov
ini-values: memory_limit=-1
- name: Set Composer platform config
if: (startsWith(matrix.php, '8.0'))
run: |
composer config platform.php 7.4.99
- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand All @@ -237,10 +241,10 @@ jobs:
- name: Install PHPUnit
run: vendor/bin/simple-phpunit --version
- name: Clear test app cache
if: (!startsWith(matrix.php, 'rc'))
if: (!startsWith(matrix.php, '8.0'))
run: tests/Fixtures/app/console cache:clear --ansi
- name: Clear test app cache (php rc)
if: (startsWith(matrix.php, 'rc'))
- name: Clear test app cache (php 8.0)
if: (startsWith(matrix.php, '8.0'))
run: rm -Rf tests/Fixtures/app/var/cache/*
- name: Run Behat tests
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@
/build/
/composer.lock
/composer.phar
/phpstan.neon
/phpunit.xml
/swagger.json
/swagger.yaml
Expand Down
2 changes: 2 additions & 0 deletions .php_cs.dist
Expand Up @@ -17,6 +17,7 @@ $finder = PhpCsFixer\Finder::create()
'tests/Fixtures/app/var',
])
->notPath('src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php')
->notPath('tests/Fixtures/TestBundle/Entity/DummyPhp8.php') // temporary
->append([
'tests/Fixtures/app/console',
]);
Expand Down Expand Up @@ -98,6 +99,7 @@ return PhpCsFixer\Config::create()
'phpdoc_add_missing_param_annotation' => [
'only_untyped' => true,
],
'phpdoc_no_alias_tag' => false, // Set the rule to true when https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5357 is fixed
'phpdoc_order' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_var_annotation_correct_order' => true,
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -58,6 +58,13 @@
* Validator:Query filters and parameters are validated (#1723)
* `ExceptionInterface` now extends `\Throwable` (#3217)

## 2.5.9

* Fix a warning when preloading the `AbstractPaginator` class (#3827)
* OpenAPI: prevent `additionalProp1` from showing in example values (#3888)
* Varnish: fix a bug when passing an empty list of tags to the purger (#3827)
* JSON Schema: mark `hydra:mapping` properties as nullable (#3877)

## 2.5.8

* PHP 8 support (#3791, #3745, #3855)
Expand Down
6 changes: 0 additions & 6 deletions phpstan.neon.dist
Expand Up @@ -46,12 +46,6 @@ parameters:
message: '#Strict comparison using !== between .+ and .+ will always evaluate to false\.#'
paths:
- src/Bridge/Doctrine/Common/PropertyHelperTrait.php
-
message: '#Variable \$iri might not be defined\.#'
path: src/JsonApi/Serializer/ItemNormalizer.php
-
message: '#Variable \$positionPm might not be defined\.#'
path: src/Util/ClassInfoTrait.php
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy<(\\?[a-zA-Z0-9_]+)+>::\$[a-zA-Z0-9_]+#'
-
message: '#Call to an undefined method Doctrine\\Persistence\\ObjectManager::getConnection\(\)#'
Expand Down
Expand Up @@ -103,7 +103,7 @@ public function postFlush(): void
return;
}

$this->purger->purge($this->tags);
$this->purger->purge(array_values($this->tags));
$this->tags = [];
}

Expand Down
Expand Up @@ -31,8 +31,8 @@
*/
final class OrderExtension implements AggregationCollectionExtensionInterface
{
use PropertyHelperTrait;
use MongoDbOdmPropertyHelperTrait;
use PropertyHelperTrait;

private $order;
private $resourceMetadataFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/MongoDbOdm/Filter/AbstractFilter.php
Expand Up @@ -32,8 +32,8 @@
*/
abstract class AbstractFilter implements FilterInterface
{
use PropertyHelperTrait;
use MongoDbOdmPropertyHelperTrait;
use PropertyHelperTrait;

protected $managerRegistry;
protected $logger;
Expand Down
3 changes: 3 additions & 0 deletions src/Bridge/Doctrine/Orm/Extension/PaginationExtension.php
Expand Up @@ -28,6 +28,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

// Help opcache.preload discover always-needed symbols
class_exists(AbstractPaginator::class);

/**
* Applies pagination on the Doctrine query for resource collection when enabled.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/Orm/Filter/AbstractFilter.php
Expand Up @@ -35,8 +35,8 @@
*/
abstract class AbstractFilter implements FilterInterface
{
use PropertyHelperTrait;
use OrmPropertyHelperTrait;
use PropertyHelperTrait;

protected $managerRegistry;
protected $requestStack;
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Bundle/Test/Response.php
Expand Up @@ -145,7 +145,7 @@ public function toArray(bool $throw = true): array
}

try {
$content = json_decode($content, true, 512, JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? \JSON_THROW_ON_ERROR : 0));
$content = json_decode($content, true, 512, JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0));
} catch (\JsonException $e) {
throw new JsonException($e->getMessage(), $e->getCode());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Routing/IriConverter.php
Expand Up @@ -45,8 +45,8 @@
*/
final class IriConverter implements IriConverterInterface
{
use ResourceClassInfoTrait;
use OperationDataProviderTrait;
use ResourceClassInfoTrait;

private $routeNameResolver;
private $router;
Expand Down
Expand Up @@ -32,7 +32,7 @@ class PropertySchemaFormat implements PropertySchemaRestrictionMetadataInterface
public function create(Constraint $constraint, PropertyMetadata $propertyMetadata): array
{
if ($constraint instanceof Email) {
return ['format' => 'email'];
return ['format' => 'email'];
}

if ($constraint instanceof Uuid) {
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Factory/ItemResolverFactory.php
Expand Up @@ -35,8 +35,8 @@
*/
final class ItemResolverFactory implements ResolverFactoryInterface
{
use CloneTrait;
use ClassInfoTrait;
use CloneTrait;

private $readStage;
private $securityStage;
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Stage/ReadStage.php
Expand Up @@ -35,9 +35,9 @@
*/
final class ReadStage implements ReadStageInterface
{
use ArrayTrait;
use ClassInfoTrait;
use IdentifierTrait;
use ArrayTrait;

private $resourceMetadataFactory;
private $iriConverter;
Expand Down
10 changes: 9 additions & 1 deletion src/JsonSchema/SchemaFactory.php
Expand Up @@ -110,11 +110,19 @@ public function buildSchema(string $className, string $format = 'json', string $
return $schema;
}

$definition = new \ArrayObject(['type' => 'object', 'additionalProperties' => $serializerContext[AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES] ?? true]);
/** @var \ArrayObject<string, mixed> $definition */
$definition = new \ArrayObject(['type' => 'object']);
$definitions[$definitionName] = $definition;
if (null !== $resourceMetadata && null !== $description = $resourceMetadata->getDescription()) {
$definition['description'] = $description;
}

// additionalProperties are allowed by default, so it does not need to be set explicitly, unless allow_extra_attributes is false
// See https://json-schema.org/understanding-json-schema/reference/object.html#properties
if (false === ($serializerContext[AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES] ?? true)) {
$definition['additionalProperties'] = false;
}

// see https://github.com/json-schema-org/json-schema-spec/pull/737
if (
Schema::VERSION_SWAGGER !== $version &&
Expand Down
2 changes: 1 addition & 1 deletion src/OpenApi/OpenApi.php
Expand Up @@ -34,7 +34,7 @@ final class OpenApi implements DocumentationInterface
private $tags;
private $externalDocs;

public function __construct(Info $info, array $servers = [], Paths $paths, Components $components = null, array $security = [], array $tags = [], $externalDocs = null)
public function __construct(Info $info, array $servers, Paths $paths, Components $components = null, array $security = [], array $tags = [], $externalDocs = null)
{
$this->openapi = self::VERSION;
$this->info = $info;
Expand Down
3 changes: 2 additions & 1 deletion src/Serializer/AbstractItemNormalizer.php
Expand Up @@ -251,7 +251,8 @@ public function denormalize($data, $class, $format = null, array $context = [])
}

/**
* Originally from {@see https://github.com/symfony/symfony/pull/28263}. Refactor after it is merged.
* Method copy-pasted from symfony/serializer.
* Remove it after symfony/serializer version update @see https://github.com/symfony/symfony/pull/28263.
*
* {@inheritdoc}
*
Expand Down
27 changes: 5 additions & 22 deletions src/Util/Inflector.php
Expand Up @@ -13,7 +13,6 @@

namespace ApiPlatform\Core\Util;

use ApiPlatform\Core\Exception\RuntimeException;
use Doctrine\Common\Inflector\Inflector as LegacyInflector;
use Doctrine\Inflector\Inflector as InflectorObject;
use Doctrine\Inflector\InflectorFactory;
Expand All @@ -28,7 +27,7 @@
final class Inflector
{
/**
* @var InflectorObject
* @var InflectorObject|null
*/
private static $instance;

Expand All @@ -39,34 +38,18 @@ private static function getInstance(): InflectorObject
}

/**
* @see LegacyInflector::tableize()
* @see InflectorObject::tableize()
*/
public static function tableize(string $word): string
{
if (class_exists(InflectorFactory::class)) {
return self::getInstance()->tableize($word);
}

if (class_exists(LegacyInflector::class)) {
return LegacyInflector::tableize($word);
}

throw new RuntimeException('Unable to find a proper Doctrine Inflector instance.');
return class_exists(LegacyInflector::class) ? LegacyInflector::tableize($word) : self::getInstance()->tableize($word);
}

/**
* @see LegacyInflector::pluralize()
* @see InflectorObject::pluralize()
*/
public static function pluralize(string $word): string
{
if (class_exists(InflectorFactory::class)) {
return self::getInstance()->pluralize($word);
}

if (class_exists(LegacyInflector::class)) {
return LegacyInflector::pluralize($word);
}

throw new RuntimeException('Unable to find a proper Doctrine Inflector instance.');
return class_exists(LegacyInflector::class) ? LegacyInflector::pluralize($word) : self::getInstance()->pluralize($word);
}
}
1 change: 1 addition & 0 deletions tests/Annotation/ApiResourceTest.php
Expand Up @@ -207,6 +207,7 @@ public function testConstructAttribute()
'hydra_context' => ['hydra' => 'foo'],
'pagination_via_cursor' => ['foo'],
'stateless' => true,
'composite_identifier' => null,
], $resource->attributes);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/JsonApiContext.php
Expand Up @@ -80,7 +80,7 @@ public function theJsonShouldBeValidAccordingToTheJsonApiSchema()
$this->validator->validate($json, (object) ['$ref' => "file://{$this->jsonApiSchemaFile}"]);

if (!$this->validator->isValid()) {
throw new ExpectationFailedException(sprintf('The JSON is not valid according to the JSON API schema.'));
throw new ExpectationFailedException('The JSON is not valid according to the JSON API schema.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/JsonHalContext.php
Expand Up @@ -67,7 +67,7 @@ public function theJsonShouldBeValidAccordingToTheJsonHALSchema()
$this->validator->validate($json, (object) ['$ref' => "file://{$this->schemaFile}"]);

if (!$this->validator->isValid()) {
throw new ExpectationFailedException(sprintf('The JSON is not valid according to the HAL+JSON schema.'));
throw new ExpectationFailedException('The JSON is not valid according to the HAL+JSON schema.');
}
}

Expand Down
Expand Up @@ -56,7 +56,7 @@ public function testOnFlush()
$toDeleteNoPurge->setId(5);

$purgerProphecy = $this->prophesize(PurgerInterface::class);
$purgerProphecy->purge(['/dummies' => '/dummies', '/dummies/1' => '/dummies/1', '/dummies/2' => '/dummies/2', '/dummies/3' => '/dummies/3', '/dummies/4' => '/dummies/4'])->shouldBeCalled();
$purgerProphecy->purge(['/dummies', '/dummies/1', '/dummies/2', '/dummies/3', '/dummies/4'])->shouldBeCalled();

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
$iriConverterProphecy->getIriFromResourceClass(Dummy::class)->willReturn('/dummies')->shouldBeCalled();
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testPreUpdate()
$dummy->setId(1);

$purgerProphecy = $this->prophesize(PurgerInterface::class);
$purgerProphecy->purge(['/dummies' => '/dummies', '/dummies/1' => '/dummies/1', '/related_dummies/old' => '/related_dummies/old', '/related_dummies/new' => '/related_dummies/new'])->shouldBeCalled();
$purgerProphecy->purge(['/dummies', '/dummies/1', '/related_dummies/old', '/related_dummies/new'])->shouldBeCalled();

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
$iriConverterProphecy->getIriFromResourceClass(Dummy::class)->willReturn('/dummies')->shouldBeCalled();
Expand Down
Expand Up @@ -79,7 +79,7 @@ public function getCollection(string $resourceClass, string $operationName = nul
[],
];

yield 'Empty ChainCollectionDataProvider' => [
yield 'Empty ChainCollectionDataProvider' => [
new ChainCollectionDataProvider([]),
['some_context'],
[],
Expand Down
Expand Up @@ -80,7 +80,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null
[],
];

yield 'Empty ChainItemDataProvider' => [
yield 'Empty ChainItemDataProvider' => [
new ChainItemDataProvider([]),
['some_context'],
[],
Expand Down
Expand Up @@ -79,7 +79,7 @@ public function getSubresource(string $resourceClass, array $identifiers, array
[],
];

yield 'Empty ChainSubresourceDataProvider' => [
yield 'Empty ChainSubresourceDataProvider' => [
new ChainSubresourceDataProvider([]),
['some_context'],
[],
Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Symfony/Routing/IriConverterTest.php
Expand Up @@ -43,8 +43,8 @@
*/
class IriConverterTest extends TestCase
{
use ProphecyTrait;
use ExpectDeprecationTrait;
use ProphecyTrait;

public function testGetItemFromIriNoRouteException()
{
Expand Down

0 comments on commit 75deb1a

Please sign in to comment.