Skip to content

Commit c08758c

Browse files
committed
Merge 4.1
2 parents aa20430 + 613bb5b commit c08758c

File tree

14 files changed

+67
-39
lines changed

14 files changed

+67
-39
lines changed

phpunit.baseline.xml

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<files version="1">
33
<file path="vendor/symfony/deprecation-contracts/function.php">
44
<line number="25" hash="c6af5d66288d0667e424978000f29571e4954b81">
5+
<issue><![CDATA[Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Type" class is deprecated. Use "Symfony\Component\TypeInfo\Type" class from "symfony/type-info" instead.]]></issue>
56
<issue><![CDATA[Since symfony/validator 7.1: Not passing a value for the "requireTld" option to the Url constraint is deprecated. Its default value will change to "true".]]></issue>
7+
<issue><![CDATA[Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\PropertyInfoExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\PropertyInfoExtractor::getType()" instead.]]></issue>
68
</line>
79
</file>
810
</files>

src/Doctrine/Odm/Filter/DateFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private function addMatch(Builder $aggregationBuilder, string $field, string $op
248248
*/
249249
public function getSchema(Parameter $parameter): array
250250
{
251-
return ['type' => 'date'];
251+
return ['type' => 'string', 'format' => 'date'];
252252
}
253253

254254
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null

src/Doctrine/Odm/Filter/NumericFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@ protected function getType(?string $doctrineType = null): string
168168

169169
public function getSchema(Parameter $parameter): array
170170
{
171-
return ['type' => 'numeric'];
171+
return ['type' => 'number'];
172172
}
173173
}

src/Doctrine/Orm/Filter/DateFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterf
280280
*/
281281
public function getSchema(Parameter $parameter): array
282282
{
283-
return ['type' => 'date'];
283+
return ['type' => 'string', 'format' => 'date'];
284284
}
285285

286286
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null

src/Doctrine/Orm/Filter/NumericFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,6 @@ protected function getType(?string $doctrineType = null): string
181181

182182
public function getSchema(Parameter $parameter): array
183183
{
184-
return ['type' => 'numeric'];
184+
return ['type' => 'number'];
185185
}
186186
}

src/Serializer/AbstractItemNormalizer.php

+12-22
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,17 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
232232
try {
233233
return $this->iriConverter->getResourceFromIri($data, $context + ['fetch_data' => true]);
234234
} catch (ItemNotFoundException $e) {
235-
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
235+
if (!isset($context['not_normalizable_value_exceptions'])) {
236+
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
237+
}
238+
239+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" resource "string" (IRI), "%s" given.', $resourceClass, \gettype($data)), $data, [$resourceClass], $context['deserialization_path'] ?? null, true, $e->getCode(), $e);
236240
} catch (InvalidArgumentException $e) {
237-
throw new UnexpectedValueException(\sprintf('Invalid IRI "%s".', $data), $e->getCode(), $e);
241+
if (!isset($context['not_normalizable_value_exceptions'])) {
242+
throw new UnexpectedValueException(\sprintf('Invalid IRI "%s".', $data), $e->getCode(), $e);
243+
}
244+
245+
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type of the "%s" resource "string" (IRI), "%s" given.', $resourceClass, \gettype($data)), $data, [$resourceClass], $context['deserialization_path'] ?? null, true, $e->getCode(), $e);
238246
}
239247
}
240248

@@ -649,32 +657,14 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
649657
if (!isset($context['not_normalizable_value_exceptions'])) {
650658
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
651659
}
652-
$context['not_normalizable_value_exceptions'][] = NotNormalizableValueException::createForUnexpectedDataType(
653-
$e->getMessage(),
654-
$value,
655-
[$className],
656-
$context['deserialization_path'] ?? null,
657-
true,
658-
$e->getCode(),
659-
$e
660-
);
661660

662-
return null;
661+
throw NotNormalizableValueException::createForUnexpectedDataType($e->getMessage(), $value, [$className], $context['deserialization_path'] ?? null, true, $e->getCode(), $e);
663662
} catch (InvalidArgumentException $e) {
664663
if (!isset($context['not_normalizable_value_exceptions'])) {
665664
throw new UnexpectedValueException(\sprintf('Invalid IRI "%s".', $value), $e->getCode(), $e);
666665
}
667-
$context['not_normalizable_value_exceptions'][] = NotNormalizableValueException::createForUnexpectedDataType(
668-
$e->getMessage(),
669-
$value,
670-
[$className],
671-
$context['deserialization_path'] ?? null,
672-
true,
673-
$e->getCode(),
674-
$e
675-
);
676666

677-
return null;
667+
throw NotNormalizableValueException::createForUnexpectedDataType($e->getMessage(), $value, [$className], $context['deserialization_path'] ?? null, true, $e->getCode(), $e);
678668
}
679669
}
680670

src/Serializer/Tests/AbstractItemNormalizerTest.php

+37-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
5252
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
5353
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
54-
use Symfony\Component\Serializer\Serializer;
5554
use Symfony\Component\Serializer\SerializerInterface;
5655
use Symfony\Component\TypeInfo\Type;
5756

@@ -1042,6 +1041,43 @@ public function testDeserializationPathForNotDenormalizableRelations(): void
10421041
$this->assertSame('relatedDummies[0]', $errors[0]->getPath());
10431042
}
10441043

1044+
public function testDeserializationPathForNotDenormalizableResource(): void
1045+
{
1046+
$this->expectException(NotNormalizableValueException::class);
1047+
1048+
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
1049+
1050+
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
1051+
1052+
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
1053+
$iriConverterProphecy->getResourceFromIri(Argument::cetera())->willThrow(new InvalidArgumentException('Invalid IRI'));
1054+
1055+
$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
1056+
$resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
1057+
$resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
1058+
1059+
$propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
1060+
1061+
$serializerProphecy = $this->prophesize(SerializerInterface::class);
1062+
$serializerProphecy->willImplement(DenormalizerInterface::class);
1063+
1064+
$normalizer = $this->getMockForAbstractClass(AbstractItemNormalizer::class, [
1065+
$propertyNameCollectionFactoryProphecy->reveal(),
1066+
$propertyMetadataFactoryProphecy->reveal(),
1067+
$iriConverterProphecy->reveal(),
1068+
$resourceClassResolverProphecy->reveal(),
1069+
$propertyAccessorProphecy->reveal(),
1070+
null,
1071+
null,
1072+
[],
1073+
null,
1074+
null,
1075+
]);
1076+
$normalizer->setSerializer($serializerProphecy->reveal());
1077+
1078+
$normalizer->denormalize('wrong IRI', Dummy::class, null, ['not_normalizable_value_exceptions' => []]);
1079+
}
1080+
10451081
public function testInnerDocumentNotAllowed(): void
10461082
{
10471083
$this->expectException(UnexpectedValueException::class);

src/State/ApiResource/Error.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function __construct(
104104
identifier: true,
105105
writable: false,
106106
initializable: false,
107-
schema: ['type' => 'number', 'example' => 404, 'default' => 400]
107+
schema: ['type' => 'number', 'examples' => [404], 'default' => 400]
108108
)] private int $status,
109109
?array $originalTrace = null,
110110
private ?string $instance = null,

src/State/ProviderInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* Retrieves data from a persistence layer.
2222
*
23-
* @template T of object|array
23+
* @template T of object
2424
*
2525
* @author Antoine Bluchet <[email protected]>
2626
*/

src/Symfony/Tests/Fixtures/TestBundle/Validator/Constraint/DummyCompoundRequirements.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ final class DummyCompoundRequirements extends Compound
2323
public function getConstraints(array $options): array
2424
{
2525
return [
26-
new Length(['min' => 1, 'max' => 32]),
27-
new Regex(['pattern' => '/^[a-z]$/']),
26+
new Length(min: 1, max: 32),
27+
new Regex(pattern: '/^[a-z]$/'),
2828
];
2929
}
3030
}

src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestrictionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public static function createProvider(): \Generator
8383
]),
8484
'email' => [
8585
new NotNull(),
86-
new Length(['min' => 2, 'max' => 255]),
86+
new Length(min: 2, max: 255),
8787
new Email(['mode' => Email::VALIDATION_MODE_HTML5]),
8888
],
8989
'phone' => new Optional([
9090
new Type(['type' => 'string']),
91-
new Regex(['pattern' => '/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/']),
91+
new Regex(pattern: '/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/'),
9292
]),
9393
'age' => new Optional([
9494
new Type(['type' => 'int']),

tests/Fixtures/TestBundle/ApiResource/WithParameter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#[Get(
3333
uriTemplate: 'with_parameters/{id}{._format}',
3434
uriVariables: [
35-
'id' => new Link(schema: ['type' => 'uuid'], property: 'id'),
35+
'id' => new Link(schema: ['type' => 'string', 'format' => 'uuid'], property: 'id'),
3636
],
3737
parameters: [
3838
'groups' => new QueryParameter(filter: new GroupFilter(parameterName: 'groups', overrideDefaultGroups: false)),

tests/Fixtures/TestBundle/Document/FilteredDateParameter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
'date' => new QueryParameter(
3333
filter: new DateFilter(),
3434
property: 'createdAt',
35-
openApi: new Parameter('createdAt', 'query', allowEmptyValue: true)
35+
openApi: new Parameter('date', 'query', allowEmptyValue: true)
3636
),
3737
'date_include_null_always' => new QueryParameter(
3838
filter: new DateFilter(),
3939
property: 'createdAt',
4040
filterContext: DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER,
41-
openApi: new Parameter('createdAt', 'query', allowEmptyValue: true)
41+
openApi: new Parameter('date_include_null_always', 'query', allowEmptyValue: true)
4242
),
4343
'date_old_way' => new QueryParameter(
4444
filter: new DateFilter(properties: ['createdAt' => DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER]),
4545
property: 'createdAt',
46-
openApi: new Parameter('createdAt', 'query', allowEmptyValue: true)
46+
openApi: new Parameter('date_old_way', 'query', allowEmptyValue: true)
4747
),
4848
],
4949
)]

tests/Fixtures/TestBundle/Document/FilteredRangeParameter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
parameters: [
2727
'quantity' => new QueryParameter(
2828
filter: new RangeFilter(),
29-
openApi: new Parameter('createdAt', 'query', allowEmptyValue: true)
29+
openApi: new Parameter('quantity', 'query', allowEmptyValue: true)
3030
),
3131
'amount' => new QueryParameter(
3232
filter: new RangeFilter(),
3333
property: 'quantity',
34-
openApi: new Parameter('createdAt', 'query', allowEmptyValue: true)
34+
openApi: new Parameter('amount', 'query', allowEmptyValue: true)
3535
),
3636
],
3737
)]

0 commit comments

Comments
 (0)