Skip to content

Commit f7406d1

Browse files
bendaviesteohhanhui
authored andcommitted
replace exception annotations with methods
1 parent e6cd60c commit f7406d1

File tree

55 files changed

+388
-433
lines changed

Some content is hidden

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

55 files changed

+388
-433
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
@@ -41,7 +41,7 @@ before_install:
4141
- phpenv config-rm xdebug.ini || echo "xdebug not available"
4242
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
4343
- if [[ $lint = 1 ]]; then
44-
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.8.4/php-cs-fixer.phar;
44+
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.12.0/php-cs-fixer.phar;
4545
fi
4646
- if [[ $lint = 1 ]]; then
4747
composer global require --dev 'phpstan/phpstan:^0.8';

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());

tests/Bridge/Doctrine/Orm/CollectionDataProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
1818
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface;
1919
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
20+
use ApiPlatform\Core\Exception\RuntimeException;
2021
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
2122
use Doctrine\Common\Persistence\ManagerRegistry;
2223
use Doctrine\Common\Persistence\ObjectManager;
@@ -80,12 +81,11 @@ public function testQueryResultExtension()
8081
$this->assertEquals([], $dataProvider->getCollection(Dummy::class, 'foo'));
8182
}
8283

83-
/**
84-
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
85-
* @expectedExceptionMessage The repository class must have a "createQueryBuilder" method.
86-
*/
8784
public function testCannotCreateQueryBuilder()
8885
{
86+
$this->expectException(RuntimeException::class);
87+
$this->expectExceptionMessage('The repository class must have a "createQueryBuilder" method.');
88+
8989
$repositoryProphecy = $this->prophesize(ObjectRepository::class);
9090

9191
$managerProphecy = $this->prophesize(ObjectManager::class);

tests/Bridge/Doctrine/Orm/Extension/EagerLoadingExtensionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
1818
use ApiPlatform\Core\Exception\PropertyNotFoundException;
1919
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
20+
use ApiPlatform\Core\Exception\RuntimeException;
2021
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2122
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2223
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
@@ -326,12 +327,11 @@ public function testDenormalizeItemWithExistingGroups()
326327
$eagerExtensionTest->applyToItem($queryBuilderProphecy->reveal(), new QueryNameGenerator(), RelatedDummy::class, ['id' => 1], 'item_operation', [AbstractNormalizer::GROUPS => 'some_groups']);
327328
}
328329

329-
/**
330-
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
331-
* @expectedExceptionMessage The total number of joined relations has exceeded the specified maximum. Raise the limit if necessary, or use the "max_depth" option of the Symfony serializer.
332-
*/
333330
public function testMaxJoinsReached()
334331
{
332+
$this->expectException(RuntimeException::class);
333+
$this->expectExceptionMessage('The total number of joined relations has exceeded the specified maximum. Raise the limit if necessary, or use the "max_depth" option of the Symfony serializer.');
334+
335335
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
336336
$resourceMetadataFactoryProphecy->create(Dummy::class)->willReturn(new ResourceMetadata());
337337

tests/Bridge/Doctrine/Orm/Extension/FilterExtensionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterExtension;
1919
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\FilterInterface;
2020
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
21+
use ApiPlatform\Core\Exception\InvalidArgumentException;
2122
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
2223
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
2324
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
@@ -78,11 +79,12 @@ public function testApplyToCollectionWithValidFiltersAndDeprecatedFilterCollecti
7879

7980
/**
8081
* @group legacy
81-
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
82-
* @expectedExceptionMessage The "$filterLocator" argument is expected to be an implementation of the "Psr\Container\ContainerInterface" interface.
8382
*/
8483
public function testConstructWithInvalidFilterLocator()
8584
{
85+
$this->expectException(InvalidArgumentException::class);
86+
$this->expectExceptionMessage('The "$filterLocator" argument is expected to be an implementation of the "Psr\\Container\\ContainerInterface" interface.');
87+
8688
new FilterExtension($this->prophesize(ResourceMetadataFactoryInterface::class)->reveal(), new \ArrayObject());
8789
}
8890

tests/Bridge/Doctrine/Orm/Extension/PaginationExtensionTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
1818
use ApiPlatform\Core\DataProvider\PaginatorInterface;
1919
use ApiPlatform\Core\DataProvider\PartialPaginatorInterface;
20+
use ApiPlatform\Core\Exception\InvalidArgumentException;
2021
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
2122
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
2223
use Doctrine\Common\Persistence\ManagerRegistry;
@@ -99,12 +100,11 @@ public function testApplyToCollectionWithItemPerPageZero()
99100
$extension->applyToCollection($queryBuilder, new QueryNameGenerator(), 'Foo', 'op');
100101
}
101102

102-
/**
103-
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
104-
* @expectedExceptionMessage Page should not be greater than 1 if itemsPerPage is equal to 0
105-
*/
106103
public function testApplyToCollectionWithItemPerPageZeroAndPage2()
107104
{
105+
$this->expectException(InvalidArgumentException::class);
106+
$this->expectExceptionMessage('Page should not be greater than 1 if itemsPerPage is equal to 0');
107+
108108
$requestStack = new RequestStack();
109109
$requestStack->push(new Request(['pagination' => true, 'itemsPerPage' => 0, '_page' => 2]));
110110

@@ -135,12 +135,11 @@ public function testApplyToCollectionWithItemPerPageZeroAndPage2()
135135
$extension->applyToCollection($queryBuilder, new QueryNameGenerator(), 'Foo', 'op');
136136
}
137137

138-
/**
139-
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
140-
* @expectedExceptionMessage Item per page parameter should not be less than 0
141-
*/
142138
public function testApplyToCollectionWithItemPerPageLessThen0()
143139
{
140+
$this->expectException(InvalidArgumentException::class);
141+
$this->expectExceptionMessage('Item per page parameter should not be less than 0');
142+
144143
$requestStack = new RequestStack();
145144
$requestStack->push(new Request(['pagination' => true, 'itemsPerPage' => -20, '_page' => 2]));
146145

0 commit comments

Comments
 (0)