Skip to content

Commit 8a5494d

Browse files
committed
tests: fix tests
1 parent 11dafa5 commit 8a5494d

File tree

4 files changed

+76
-67
lines changed

4 files changed

+76
-67
lines changed

.php_cs.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ return PhpCsFixer\Config::create()
2929
'@PHPUnit60Migration:risky' => true,
3030
'@Symfony' => true,
3131
'@Symfony:risky' => true,
32+
'single_line_comment_style' => false, // Temporary fix for compatibility with PHP 8 attributes, see https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5284
3233
'align_multiline_comment' => [
3334
'comment_type' => 'phpdocs_like',
3435
],

phpstan.neon.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ parameters:
2121
- tests/Bridge/NelmioApiDoc/*
2222
- src/Bridge/FosUser/*
2323
# BC layer
24+
- tests/Annotation/ApiResourceTest.php
25+
- tests/Annotation/ApiPropertyTest.php
26+
- tests/Metadata/Resource/Factory/AnnotationResourceMetadataFactoryTest.php
2427
- tests/Fixtures/TestBundle/BrowserKit/Client.php
2528
# The Symfony Configuration API isn't good enough to be analysed
2629
- src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
@@ -101,6 +104,13 @@ parameters:
101104
message: '#Property Doctrine\\ORM\\Mapping\\ClassMetadataInfo::\$fieldMappings \(array.*\)>\) does not accept array\(.*\)\.#'
102105
path: tests/Bridge/Doctrine/Orm/Metadata/Property/DoctrineOrmPropertyMetadataFactoryTest.php
103106

107+
# Expected, due to PHP 8 attributes
108+
- '#ReflectionProperty::getAttributes\(\)#'
109+
- '#ReflectionMethod::getAttributes\(\)#'
110+
- '#ReflectionClass<mixed>::getAttributes\(\)#'
111+
- '#Constructor of class ApiPlatform\\Core\\Annotation\\ApiResource has an unused parameter#'
112+
- '#Constructor of class ApiPlatform\\Core\\Annotation\\ApiProperty has an unused parameter#'
113+
104114
# Expected, due to optional interfaces
105115
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryCollectionExtensionInterface::applyToCollection\(\) invoked with 5 parameters, 3-4 required\.#'
106116
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryResult(Item|Collection)ExtensionInterface::getResult\(\) invoked with 4 parameters, 1 required\.#'

src/Annotation/ApiProperty.php

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,24 @@ final class ApiProperty
9494
public $example;
9595

9696
/**
97-
* @param string $description
98-
* @param bool $readable
99-
* @param bool $writable
100-
* @param bool $readableLink
101-
* @param bool $writableLink
102-
* @param bool $required
103-
* @param bool $iri
104-
* @param bool $identifier
105-
* @param string|int|float|bool|array $default
97+
* @param string $description
98+
* @param bool $readable
99+
* @param bool $writable
100+
* @param bool $readableLink
101+
* @param bool $writableLink
102+
* @param bool $required
103+
* @param string $iri
104+
* @param bool $identifier
105+
* @param string|int|float|bool|array $default
106106
* @param string|int|float|bool|array|null $example
107-
*
108-
* @param string $deprecationReason
109-
* @param bool $fetchable
110-
* @param bool $fetchEager
111-
* @param array $jsonldContext
112-
* @param array $openapiContext
113-
* @param bool $push
114-
* @param string $security
115-
* @param array $swaggerContext
107+
* @param string $deprecationReason
108+
* @param bool $fetchable
109+
* @param bool $fetchEager
110+
* @param array $jsonldContext
111+
* @param array $openapiContext
112+
* @param bool $push
113+
* @param string $security
114+
* @param array $swaggerContext
116115
*
117116
* @throws InvalidArgumentException
118117
*/
@@ -121,7 +120,7 @@ public function __construct(
121120
?bool $readable = null,
122121
?bool $writable = null,
123122
?bool $readableLink = null,
124-
?bool $writableLink = null,
123+
?bool $writableLink = null,
125124
?bool $required = null,
126125
?string $iri = null,
127126
?bool $identifier = null,
@@ -132,23 +131,23 @@ public function __construct(
132131
?array $attributes = null,
133132
?string $deprecationReason = null,
134133
?bool $fetchable = null,
135-
?bool $fetchEager = null,
134+
?bool $fetchEager = null,
136135
?array $jsonldContext = null,
137136
?array $openapiContext = null,
138137
?bool $push = null,
139138
?string $security = null,
140139
?array $swaggerContext = null
141140
) {
142-
if (!is_array($description)) {
141+
if (!\is_array($description)) { // @phpstan-ignore-line Doctrine annotations support
143142
[$publicProperties, $configurableAttributes] = self::getConfigMetadata();
144143

145144
foreach ($publicProperties as $prop => $_) {
146-
$this->{$prop} = $$prop;
145+
$this->{$prop} = ${$prop};
147146
}
148147

149148
$description = [];
150149
foreach ($configurableAttributes as $attribute => $_) {
151-
$description[$attribute] = $$attribute;
150+
$description[$attribute] = ${$attribute};
152151
}
153152
}
154153

src/Annotation/ApiResource.php

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -129,47 +129,46 @@ final class ApiResource
129129
public $subresourceOperations;
130130

131131
/**
132-
* @param string $description
133-
* @param array $collectionOperations https://api-platform.com/docs/core/operations
134-
* @param array $graphql https://api-platform.com/docs/core/graphql
135-
* @param array $itemOperations https://api-platform.com/docs/core/operations
136-
* @param array $subresourceOperations https://api-platform.com/docs/core/subresources
137-
*
138-
* @param array $cacheHeaders https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers
139-
* @param array $denormalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups
140-
* @param string $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
141-
* @param bool $elasticsearch https://api-platform.com/docs/core/elasticsearch/
142-
* @param bool $fetchPartial https://api-platform.com/docs/core/performance/#fetch-partial
143-
* @param bool $forceEager https://api-platform.com/docs/core/performance/#force-eager
144-
* @param array $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
145-
* @param string[] $filters https://api-platform.com/docs/core/filters/#doctrine-orm-and-mongodb-odm-filters
146-
* @param string[] $hydraContext https://api-platform.com/docs/core/extending-jsonld-context/#hydra
147-
* @param string|false $input https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
148-
* @param bool|array $mercure https://api-platform.com/docs/core/mercure
149-
* @param bool $messenger https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus
150-
* @param array $normalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups
151-
* @param array $openapiContext https://api-platform.com/docs/core/swagger/#using-the-openapi-and-swagger-contexts
152-
* @param array $order https://api-platform.com/docs/core/default-order/#overriding-default-order
153-
* @param string|false $output https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
154-
* @param bool $paginationClientEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource-1
155-
* @param bool $paginationClientItemsPerPage https://api-platform.com/docs/core/pagination/#for-a-specific-resource-3
156-
* @param bool $paginationClientPartial https://api-platform.com/docs/core/pagination/#for-a-specific-resource-6
157-
* @param array $paginationViaCursor https://api-platform.com/docs/core/pagination/#cursor-based-pagination
158-
* @param bool $paginationEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource
159-
* @param bool $paginationFetchJoinCollection https://api-platform.com/docs/core/pagination/#controlling-the-behavior-of-the-doctrine-orm-paginator
160-
* @param int $paginationItemsPerPage https://api-platform.com/docs/core/pagination/#changing-the-number-of-items-per-page
161-
* @param int $paginationMaximumItemsPerPage https://api-platform.com/docs/core/pagination/#changing-maximum-items-per-page
162-
* @param bool $paginationPartial https://api-platform.com/docs/core/performance/#partial-pagination
163-
* @param string $routePrefix https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations
164-
* @param string $security https://api-platform.com/docs/core/security
165-
* @param string $securityMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
166-
* @param string $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
167-
* @param string $securityPostDenormalizeMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
168-
* @param bool $stateless
169-
* @param string $sunset https://api-platform.com/docs/core/deprecations/#setting-the-sunset-http-header-to-indicate-when-a-resource-or-an-operation-will-be-removed
170-
* @param array $swaggerContext https://api-platform.com/docs/core/swagger/#using-the-openapi-and-swagger-contexts
171-
* @param array $validationGroups https://api-platform.com/docs/core/validation/#using-validation-groups
172-
* @param int $urlGenerationStrategy
132+
* @param string $description
133+
* @param array $collectionOperations https://api-platform.com/docs/core/operations
134+
* @param array $graphql https://api-platform.com/docs/core/graphql
135+
* @param array $itemOperations https://api-platform.com/docs/core/operations
136+
* @param array $subresourceOperations https://api-platform.com/docs/core/subresources
137+
* @param array $cacheHeaders https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers
138+
* @param array $denormalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups
139+
* @param string $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
140+
* @param bool $elasticsearch https://api-platform.com/docs/core/elasticsearch/
141+
* @param bool $fetchPartial https://api-platform.com/docs/core/performance/#fetch-partial
142+
* @param bool $forceEager https://api-platform.com/docs/core/performance/#force-eager
143+
* @param array $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
144+
* @param string[] $filters https://api-platform.com/docs/core/filters/#doctrine-orm-and-mongodb-odm-filters
145+
* @param string[] $hydraContext https://api-platform.com/docs/core/extending-jsonld-context/#hydra
146+
* @param string|false $input https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
147+
* @param bool|array $mercure https://api-platform.com/docs/core/mercure
148+
* @param bool $messenger https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus
149+
* @param array $normalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups
150+
* @param array $openapiContext https://api-platform.com/docs/core/swagger/#using-the-openapi-and-swagger-contexts
151+
* @param array $order https://api-platform.com/docs/core/default-order/#overriding-default-order
152+
* @param string|false $output https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
153+
* @param bool $paginationClientEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource-1
154+
* @param bool $paginationClientItemsPerPage https://api-platform.com/docs/core/pagination/#for-a-specific-resource-3
155+
* @param bool $paginationClientPartial https://api-platform.com/docs/core/pagination/#for-a-specific-resource-6
156+
* @param array $paginationViaCursor https://api-platform.com/docs/core/pagination/#cursor-based-pagination
157+
* @param bool $paginationEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource
158+
* @param bool $paginationFetchJoinCollection https://api-platform.com/docs/core/pagination/#controlling-the-behavior-of-the-doctrine-orm-paginator
159+
* @param int $paginationItemsPerPage https://api-platform.com/docs/core/pagination/#changing-the-number-of-items-per-page
160+
* @param int $paginationMaximumItemsPerPage https://api-platform.com/docs/core/pagination/#changing-maximum-items-per-page
161+
* @param bool $paginationPartial https://api-platform.com/docs/core/performance/#partial-pagination
162+
* @param string $routePrefix https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations
163+
* @param string $security https://api-platform.com/docs/core/security
164+
* @param string $securityMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
165+
* @param string $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
166+
* @param string $securityPostDenormalizeMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
167+
* @param bool $stateless
168+
* @param string $sunset https://api-platform.com/docs/core/deprecations/#setting-the-sunset-http-header-to-indicate-when-a-resource-or-an-operation-will-be-removed
169+
* @param array $swaggerContext https://api-platform.com/docs/core/swagger/#using-the-openapi-and-swagger-contexts
170+
* @param array $validationGroups https://api-platform.com/docs/core/validation/#using-validation-groups
171+
* @param int $urlGenerationStrategy
173172
*
174173
* @throws InvalidArgumentException
175174
*/
@@ -220,16 +219,16 @@ public function __construct(
220219
?array $validationGroups = null,
221220
?int $urlGenerationStrategy = null
222221
) {
223-
if (!is_array($description)) {
222+
if (!\is_array($description)) { // @phpstan-ignore-line Doctrine annotations support
224223
[$publicProperties, $configurableAttributes] = self::getConfigMetadata();
225224

226225
foreach ($publicProperties as $prop => $_) {
227-
$this->{$prop} = $$prop;
226+
$this->{$prop} = ${$prop};
228227
}
229228

230229
$description = [];
231230
foreach ($configurableAttributes as $attribute => $_) {
232-
$description[$attribute] = $$attribute;
231+
$description[$attribute] = ${$attribute};
233232
}
234233
}
235234

0 commit comments

Comments
 (0)