Skip to content

Commit c07166a

Browse files
committed
phpunit !
1 parent 4c171e5 commit c07166a

Some content is hidden

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

41 files changed

+139
-614
lines changed

src/Documentation/Action/DocumentationAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName
4545
public function __invoke(Request $request = null): DocumentationInterface
4646
{
4747
if (null !== $request) {
48-
$context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', $this->swaggerVersions[0] ?? 3)];
48+
$context = ['base_url' => $request->getBaseUrl()];
4949
if ($request->query->getBoolean('api_gateway')) {
5050
$context['api_gateway'] = true;
5151
}
@@ -54,7 +54,7 @@ public function __invoke(Request $request = null): DocumentationInterface
5454
$attributes = RequestAttributesExtractor::extractAttributes($request);
5555
}
5656

57-
if ('json' === $request->getRequestFormat() && null !== $this->openApiFactory && 3 === ($context['spec_version'] ?? null)) {
57+
if ('json' === $request->getRequestFormat() && null !== $this->openApiFactory) {
5858
return $this->openApiFactory->__invoke($context ?? []);
5959
}
6060

src/GraphQl/Serializer/SerializerContextBuilder.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ public function create(?string $resourceClass, Operation $operation, array $reso
4141
}
4242

4343
$context['operation'] = $operation;
44-
$context['input'] = $operation->getInput();
45-
$context['output'] = $operation->getOutput();
44+
if ($operation->getInput()) {
45+
$context['input'] = $operation->getInput();
46+
}
47+
if ($operation->getOutput()) {
48+
$context['output'] = $operation->getOutput();
49+
}
4650
$context = $normalization ? array_merge($operation->getNormalizationContext() ?? [], $context) : array_merge($operation->getDenormalizationContext() ?? [], $context);
4751

4852
if ($normalization) {
@@ -55,7 +59,7 @@ public function create(?string $resourceClass, Operation $operation, array $reso
5559
/**
5660
* Retrieves fields, recursively replaces the "_id" key (the raw id) by "id" (the name of the property expected by the Serializer) and flattens edge and node structures (pagination).
5761
*/
58-
private function fieldsToAttributes(?string $resourceClass, ?Operation $operation, array $resolverContext, array $context): array
62+
private function fieldsToAttributes(?string $resourceClass, Operation $operation, array $resolverContext, array $context): array
5963
{
6064
if (isset($resolverContext['fields'])) {
6165
$fields = $resolverContext['fields'];
@@ -68,10 +72,6 @@ private function fieldsToAttributes(?string $resourceClass, ?Operation $operatio
6872
$attributes = $this->replaceIdKeys($fields['edges']['node'] ?? $fields['collection'] ?? $fields, $resourceClass, $context);
6973

7074
if ($resolverContext['is_mutation'] || $resolverContext['is_subscription']) {
71-
if (!$operation) {
72-
throw new \LogicException('An operation should always exist for a mutation or a subscription.');
73-
}
74-
7575
$wrapFieldName = lcfirst($operation->getShortName());
7676

7777
return $attributes[$wrapFieldName] ?? [];

src/HttpCache/EventListener/AddTagsListener.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public function onKernelResponse(ResponseEvent $event): void
8383
return;
8484
}
8585

86+
if (!$this->purger) {
87+
$response->headers->set('Cache-Tags', implode(',', $resources));
88+
89+
return;
90+
}
91+
8692
$headers = $this->purger->getResponseHeaders($resources);
8793

8894
foreach ($headers as $key => $value) {

src/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private function getOperationWithDefaults(ApiResource $resource, Operation $oper
187187

188188
// TODO: remove in 3.0
189189
if ($operation instanceof HttpOperation && 'getUriVariables' === $methodName && !$operation->getUriTemplate() && $operation instanceof CollectionOperationInterface && !$operation->getUriVariables()) {
190-
trigger_deprecation('api-platform', '2.7', 'Identifiers are declared on the default #[ApiResource] but you did not specify identifiers on the collection operation. In 3.0 the collection operations can have identifiers, you should specify identifiers on the operation not on the resource to avoid unwanted behavior.');
190+
trigger_deprecation('api-platform', '2.7', sprintf('Identifiers on "%s" are declared on the default #[ApiResource] but you did not specify identifiers on the collection operation. In 3.0 the collection operations can have identifiers, you should specify identifiers on the operation not on the resource to avoid unwanted behavior.', $operation->getShortName()));
191191
continue;
192192
}
193193

src/Serializer/AbstractItemNormalizer.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
4040
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
4141
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
42-
use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface;
4342
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
4443
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
4544

@@ -48,7 +47,7 @@
4847
*
4948
* @author Kévin Dunglas <[email protected]>
5049
*/
51-
abstract class AbstractItemNormalizer extends AbstractObjectNormalizer implements ContextAwareDenormalizerInterface
50+
abstract class AbstractItemNormalizer extends AbstractObjectNormalizer
5251
{
5352
use ClassInfoTrait;
5453
use ContextTrait;
@@ -568,8 +567,9 @@ protected function getFactoryOptions(array $context): array
568567
$options['serializer_groups'] = (array) $context[self::GROUPS];
569568
}
570569

571-
if (isset($context['resource_class']) && $this->resourceClassResolver->isResourceClass($context['resource_class'])) {
572-
$resourceClass = $this->resourceClassResolver->getResourceClass($context['resource_class'], $context['resource_class']);
570+
if (isset($context['resource_class']) && $this->resourceClassResolver->isResourceClass($context['resource_class']) && $this->resourceMetadataCollectionFactory) {
571+
$resourceClass = $this->resourceClassResolver->getResourceClass(null, $context['resource_class']); // fix for abstract classes and interfaces
572+
// This is a hot spot, we should avoid calling this here but in many cases we can't
573573
$operation = $context['operation'] ?? $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation($context['operation_name'] ?? null);
574574
$options['normalization_groups'] = $operation->getNormalizationContext()['groups'] ?? null;
575575
$options['denormalization_groups'] = $operation->getDenormalizationContext()['groups'] ?? null;
@@ -618,7 +618,9 @@ protected function getAttributeValue($object, $attribute, $format = null, array
618618
$resourceClass = $this->resourceClassResolver->getResourceClass($attributeValue, $className);
619619
$childContext = $this->createChildContext($context, $attribute, $format);
620620
$childContext['resource_class'] = $resourceClass;
621-
$childContext['operation'] = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation();
621+
if ($this->resourceMetadataCollectionFactory) {
622+
$childContext['operation'] = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation();
623+
}
622624
unset($childContext['iri'], $childContext['uri_variables']);
623625

624626
return $this->normalizeCollectionOfRelations($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext);
@@ -636,7 +638,9 @@ protected function getAttributeValue($object, $attribute, $format = null, array
636638
$resourceClass = $this->resourceClassResolver->getResourceClass($attributeValue, $className);
637639
$childContext = $this->createChildContext($context, $attribute, $format);
638640
$childContext['resource_class'] = $resourceClass;
639-
$childContext['operation'] = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation();
641+
if ($this->resourceMetadataCollectionFactory) {
642+
$childContext['operation'] = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation();
643+
}
640644
unset($childContext['iri'], $childContext['uri_variables']);
641645

642646
return $this->normalizeRelation($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext);
@@ -761,9 +765,9 @@ private function createAttributeValue($attribute, $value, $format = null, array
761765
$resourceClass = $this->resourceClassResolver->getResourceClass(null, $className);
762766
$childContext = $this->createChildContext($context, $attribute, $format);
763767
$childContext['resource_class'] = $resourceClass;
764-
// if ($this->resourceMetadataCollectionFactory instanceof ResourceMetadataCollectionFactoryInterface) {
765-
$childContext['operation'] = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation();
766-
// }
768+
if ($this->resourceMetadataCollectionFactory) {
769+
$childContext['operation'] = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation();
770+
}
767771

768772
return $this->denormalizeRelation($attribute, $propertyMetadata, $resourceClass, $value, $format, $childContext);
769773
}

src/Serializer/JsonEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function encode($data, $format, array $context = []): string
7171
/**
7272
* {@inheritdoc}
7373
*/
74-
public function supportsDecoding($format): bool
74+
public function supportsDecoding($format, array $context = []): bool
7575
{
7676
return $this->format === $format;
7777
}

src/Symfony/Bundle/Resources/config/graphql.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
</service>
145145

146146
<service id="api_platform.graphql.serializer.context_builder" class="ApiPlatform\GraphQl\Serializer\SerializerContextBuilder" public="false">
147-
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory" />
148147
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
149148
</service>
150149
<service id="ApiPlatform\GraphQl\Serializer\SerializerContextBuilderInterface" alias="api_platform.graphql.serializer.context_builder" />

src/Symfony/Bundle/Resources/views/DataCollector/request.html.twig

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,6 @@
185185
</div>
186186
</div>
187187
</div>
188-
<div class="tab">
189-
<h3 class="tab-title data-provider-tab-title">Data Providers</h3>
190-
<div class="tab-content data-provider-tab-content">
191-
{{ apiPlatform.providerTable(collector.collectionDataProviders, 'collection data provider') }}
192-
{{ apiPlatform.providerTable(collector.itemDataProviders, 'item data provider') }}
193-
{{ apiPlatform.providerTable(collector.subresourceDataProviders, 'subresource data provider') }}
194-
</div>
195-
</div>
196-
197-
<div class="tab">
198-
<h3 class="tab-title data-persister-tab-title">Data Persisters</h3>
199-
<div class="tab-content data-persister-tab-content">
200-
{{ apiPlatform.providerTable(collector.dataPersisters, 'data persister') }}
201-
</div>
202-
</div>
203188
</div>
204189
{% endif %}
205190
{% endblock %}

src/Symfony/Bundle/Resources/views/DataCollector/request_legacy.html.twig

Lines changed: 0 additions & 200 deletions
This file was deleted.

0 commit comments

Comments
 (0)