Skip to content

Commit d928fd1

Browse files
author
abluchet
committed
Merge remote-tracking branch 'upstream/2.2' into merge-2.2
2 parents d2250c1 + 99f2724 commit d928fd1

File tree

59 files changed

+449
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+449
-485
lines changed

.php_cs.dist

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
$header = <<<'HEADER'
46
This file is part of the API Platform project.
57
@@ -18,13 +20,7 @@ return PhpCsFixer\Config::create()
1820
->setRiskyAllowed(true)
1921
->setRules([
2022
'@DoctrineAnnotation' => true,
21-
'doctrine_annotation_array_assignment' => [
22-
'operator' => '=',
23-
],
24-
'doctrine_annotation_spaces' => [
25-
'after_array_assignments_equals' => false,
26-
'before_array_assignments_equals' => false,
27-
],
23+
'@PHPUnit60Migration:risky' => true,
2824
'@Symfony' => true,
2925
'@Symfony:risky' => true,
3026
'array_syntax' => [
@@ -34,12 +30,18 @@ return PhpCsFixer\Config::create()
3430
'allow_single_line_closure' => true,
3531
],
3632
'declare_strict_types' => true,
33+
'doctrine_annotation_array_assignment' => [
34+
'operator' => '=',
35+
],
36+
'doctrine_annotation_spaces' => [
37+
'after_array_assignments_equals' => false,
38+
'before_array_assignments_equals' => false,
39+
],
3740
'header_comment' => [
3841
'header' => $header,
3942
'location' => 'after_open',
4043
],
4144
'modernize_types_casting' => true,
42-
// 'native_function_invocation' => true,
4345
'no_extra_consecutive_blank_lines' => [
4446
'break',
4547
'continue',
@@ -54,9 +56,6 @@ return PhpCsFixer\Config::create()
5456
'no_useless_else' => true,
5557
'no_useless_return' => true,
5658
'ordered_imports' => true,
57-
// 'phpdoc_add_missing_param_annotation' => [
58-
// 'only_untyped' => false,
59-
// ],
6059
'phpdoc_order' => true,
6160
'psr4' => true,
6261
'semicolon_after_instruction' => true,

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ before_install:
4040
- phpenv config-rm xdebug.ini || echo "xdebug not available"
4141
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
4242
- if [[ $lint = 1 ]]; then
43-
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.8.4/php-cs-fixer.phar;
43+
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.12.0/php-cs-fixer.phar;
4444
fi
4545
- if [[ $lint = 1 ]]; then
4646
composer global require --dev 'phpstan/phpstan:^0.8';

features/main/circular_reference.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ Feature: Circular references handling
6060
"@type": "CircularReference",
6161
"parent": "/circular_references/1",
6262
"children": [
63-
"/circular_references/1"
63+
"/circular_references/1",
64+
"/circular_references/2"
6465
]
6566
},
6667
"children": []

src/Bridge/Doctrine/Orm/Extension/EagerLoadingExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ private function apply(bool $collection, QueryBuilder $queryBuilder, QueryNameGe
107107
$context += $this->getNormalizationContext($context['resource_class'] ?? $resourceClass, $contextType, $options);
108108
}
109109

110+
if (empty($context[AbstractNormalizer::GROUPS]) && !isset($context[AbstractNormalizer::ATTRIBUTES])) {
111+
return;
112+
}
113+
110114
$this->joinRelations($queryBuilder, $queryNameGenerator, $resourceClass, $forceEager, $fetchPartial, $queryBuilder->getRootAliases()[0], $options, $context);
111115
}
112116

src/Hydra/Serializer/CollectionFiltersNormalizer.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use ApiPlatform\Core\Api\FilterInterface;
1818
use ApiPlatform\Core\Api\FilterLocatorTrait;
1919
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
20-
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
2120
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
2221
use Psr\Container\ContainerInterface;
2322
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
@@ -31,7 +30,6 @@
3130
*/
3231
final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
3332
{
34-
use JsonLdContextTrait;
3533
use FilterLocatorTrait;
3634

3735
private $collectionNormalizer;

src/Hydra/Serializer/PartialCollectionViewNormalizer.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use ApiPlatform\Core\DataProvider\PaginatorInterface;
1717
use ApiPlatform\Core\DataProvider\PartialPaginatorInterface;
18-
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
1918
use ApiPlatform\Core\Util\IriHelper;
2019
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2120
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
@@ -29,8 +28,6 @@
2928
*/
3029
final class PartialCollectionViewNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
3130
{
32-
use JsonLdContextTrait;
33-
3431
private $collectionNormalizer;
3532
private $pageParameterName;
3633
private $enabledParameterName;

tests/Annotation/ApiFilterTest.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,27 @@
2323
*/
2424
class ApiFilterTest extends TestCase
2525
{
26-
/**
27-
* @expectedException \InvalidArgumentException
28-
* @expectedExceptionMessage This annotation needs a value representing the filter class.
29-
*/
3026
public function testInvalidConstructor()
3127
{
28+
$this->expectException(\InvalidArgumentException::class);
29+
$this->expectExceptionMessage('This annotation needs a value representing the filter class.');
30+
3231
$resource = new ApiFilter();
3332
}
3433

35-
/**
36-
* @expectedException \InvalidArgumentException
37-
* @expectedExceptionMessage The filter class "ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy" does not implement "ApiPlatform\Core\Api\FilterInterface".
38-
*/
3934
public function testInvalidFilter()
4035
{
36+
$this->expectException(\InvalidArgumentException::class);
37+
$this->expectExceptionMessage('The filter class "ApiPlatform\\Core\\Tests\\Fixtures\\TestBundle\\Entity\\Dummy" does not implement "ApiPlatform\\Core\\Api\\FilterInterface".');
38+
4139
$resource = new ApiFilter(['value' => Dummy::class]);
4240
}
4341

44-
/**
45-
* @expectedException \InvalidArgumentException
46-
* @expectedExceptionMessage Property "foo" does not exist on the ApiFilter annotation.
47-
*/
4842
public function testInvalidProperty()
4943
{
44+
$this->expectException(\InvalidArgumentException::class);
45+
$this->expectExceptionMessage('Property "foo" does not exist on the ApiFilter annotation.');
46+
5047
$resource = new ApiFilter(['value' => DummyFilter::class, 'foo' => 'bar']);
5148
}
5249

tests/Api/FilterLocatorTraitTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,24 @@ public function testSetFilterLocatorWithNullAndNullAllowed()
5858

5959
/**
6060
* @group legacy
61-
* @expectedException \InvalidArgumentException
62-
* @expectedExceptionMessage The "$filterLocator" argument is expected to be an implementation of the "Psr\Container\ContainerInterface" interface.
6361
*/
6462
public function testSetFilterLocatorWithNullAndNullNotAllowed()
6563
{
64+
$this->expectException(\InvalidArgumentException::class);
65+
$this->expectExceptionMessage('The "$filterLocator" argument is expected to be an implementation of the "Psr\\Container\\ContainerInterface" interface.');
66+
6667
$filterLocatorTraitImpl = $this->getFilterLocatorTraitImpl();
6768
$filterLocatorTraitImpl->setFilterLocator(null);
6869
}
6970

7071
/**
7172
* @group legacy
72-
* @expectedException \InvalidArgumentException
73-
* @expectedExceptionMessage The "$filterLocator" argument is expected to be an implementation of the "Psr\Container\ContainerInterface" interface or null.
7473
*/
7574
public function testSetFilterLocatorWithInvalidFilterLocator()
7675
{
76+
$this->expectException(\InvalidArgumentException::class);
77+
$this->expectExceptionMessage('The "$filterLocator" argument is expected to be an implementation of the "Psr\\Container\\ContainerInterface" interface or null.');
78+
7779
$filterLocatorTraitImpl = $this->getFilterLocatorTraitImpl();
7880
$filterLocatorTraitImpl->setFilterLocator(new \ArrayObject(), true);
7981
}

tests/Api/IdentifiersExtractorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Core\Api\IdentifiersExtractor;
1717
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
18+
use ApiPlatform\Core\Exception\RuntimeException;
1819
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
1920
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2021
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
@@ -152,12 +153,11 @@ public function testGetRelatedIdentifiersFromItem($item, $expected)
152153
$this->assertSame($expected, $identifiersExtractor->getIdentifiersFromItem($item));
153154
}
154155

155-
/**
156-
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
157-
* @expectedMessage No identifier found in "ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedDummy" through relation "relatedDummy" of "ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy" used as identifier
158-
*/
159156
public function testThrowNoIdentifierFromItem()
160157
{
158+
$this->expectException(RuntimeException::class);
159+
$this->expectExceptionMessage('No identifier found in "ApiPlatform\\Core\\Tests\\Fixtures\\TestBundle\\Entity\\RelatedDummy" through relation "relatedDummy" of "ApiPlatform\\Core\\Tests\\Fixtures\\TestBundle\\Entity\\Dummy" used as identifier');
160+
161161
$prophecies = $this->getMetadataFactoryProphecies(Dummy::class, ['id', 'relatedDummy']);
162162
list($propertyNameCollectionFactoryProphecy, $propertyMetadataFactoryProphecy) = $this->getMetadataFactoryProphecies(RelatedDummy::class, [], $prophecies);
163163

tests/Api/ResourceClassResolverTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Core\Api\ResourceClassResolver;
1717
use ApiPlatform\Core\DataProvider\PaginatorInterface;
18+
use ApiPlatform\Core\Exception\InvalidArgumentException;
1819
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
1920
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection;
2021
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
@@ -93,25 +94,23 @@ public function testGetResourceClassWithPaginatorInterfaceAsValue()
9394
$this->assertEquals($resourceClass, Dummy::class);
9495
}
9596

96-
/**
97-
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
98-
* @expectedExceptionMessage No resource class found for object of type "stdClass".
99-
*/
10097
public function testGetResourceClassWithWrongClassName()
10198
{
99+
$this->expectException(InvalidArgumentException::class);
100+
$this->expectExceptionMessage('No resource class found for object of type "stdClass".');
101+
102102
$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
103103
$resourceNameCollectionFactoryProphecy->create()->willReturn(new ResourceNameCollection([Dummy::class]))->shouldBeCalled();
104104

105105
$resourceClassResolver = new ResourceClassResolver($resourceNameCollectionFactoryProphecy->reveal());
106106
$resourceClassResolver->getResourceClass(new \stdClass(), null);
107107
}
108108

109-
/**
110-
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
111-
* @expectedExceptionMessage No resource class found.
112-
*/
113109
public function testGetResourceClassWithNoResourceClassName()
114110
{
111+
$this->expectException(InvalidArgumentException::class);
112+
$this->expectExceptionMessage('No resource class found.');
113+
115114
$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
116115

117116
$resourceClassResolver = new ResourceClassResolver($resourceNameCollectionFactoryProphecy->reveal());
@@ -140,12 +139,11 @@ public function testIsResourceClassWithWrongClassName()
140139
$this->assertFalse($resourceClass);
141140
}
142141

143-
/**
144-
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
145-
* @expectedExceptionMessage No resource class found.
146-
*/
147142
public function testGetResourceClassWithNoResourceClassNameAndNoObject()
148143
{
144+
$this->expectException(InvalidArgumentException::class);
145+
$this->expectExceptionMessage('No resource class found.');
146+
149147
$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
150148

151149
$resourceClassResolver = new ResourceClassResolver($resourceNameCollectionFactoryProphecy->reveal());

0 commit comments

Comments
 (0)