Skip to content

Commit 3fac8d2

Browse files
committed
normalizer
1 parent aacd21a commit 3fac8d2

File tree

9 files changed

+31
-35
lines changed

9 files changed

+31
-35
lines changed

src/Metadata/Tests/Property/PropertyInfoPropertyNameCollectionFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
2525
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
2626
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
27-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
27+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
2828

2929
/**
3030
* @author Oskar Stark <[email protected]>
@@ -81,7 +81,7 @@ public function testCreateMethodReturnsProperPropertyNameCollectionForObjectWith
8181
new PropertyInfoExtractor([
8282
new SerializerExtractor(
8383
new ClassMetadataFactory(
84-
new AnnotationLoader(
84+
new AttributeLoader(
8585
)
8686
)
8787
),

tests/Elasticsearch/Serializer/ItemNormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ public function testGetSupportedTypes(): void
150150

151151
// TODO: use prophecy when getSupportedTypes() will be added to the interface
152152
$this->itemNormalizer = new ItemNormalizer(new class() implements NormalizerInterface {
153-
public function normalize(mixed $object, string $format = null, array $context = [])
153+
public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
154154
{
155155
return null;
156156
}
157157

158-
public function supportsNormalization(mixed $data, string $format = null): bool
158+
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
159159
{
160160
return true;
161161
}

tests/Fixtures/DummySequentiallyValidatedEntity.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ class DummySequentiallyValidatedEntity
1919
{
2020
/**
2121
* @var string
22-
*
23-
* @Assert\Sequentially({
24-
*
25-
* @Assert\Length(min=1, max=32),
26-
*
27-
* @Assert\Regex(pattern="/^[a-z]$/")
28-
* })
2922
*/
23+
#[Assert\Sequentially([
24+
new Assert\Length(min: 1, max: 32),
25+
new Assert\Regex(pattern: "/^[a-z]$/")
26+
])]
3027
public $dummy;
3128
}

tests/Fixtures/app/AppKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
120120
'validation' => ['enable_attributes' => true, 'email_validation_mode' => 'html5'],
121121
'serializer' => ['enable_attributes' => true],
122122
'test' => null,
123-
'session' => ['cookie_secure' => true, 'cookie_samesite' => 'lax', 'handler_id' => 'session.handler.native_file'],
123+
'session' => class_exists(SessionFactory::class) ? ['storage_factory_id' => 'session.storage.factory.mock_file'] : ['storage_id' => 'session.storage.mock_file'],
124124
'profiler' => [
125125
'enabled' => true,
126126
'collect' => false,

tests/GraphQl/Resolver/Stage/SerializeStageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function testApplyBadNormalizedData(): void
190190
$normalizationContext = ['normalization' => true];
191191
$this->serializerContextBuilderProphecy->create($resourceClass, $operation, $context, true)->shouldBeCalled()->willReturn($normalizationContext);
192192

193-
$this->normalizerProphecy->normalize(Argument::type(\stdClass::class), ItemNormalizer::FORMAT, $normalizationContext)->willReturn(new \stdClass());
193+
$this->normalizerProphecy->normalize(Argument::type(\stdClass::class), ItemNormalizer::FORMAT, $normalizationContext)->willReturn(0);
194194

195195
$this->expectException(\UnexpectedValueException::class);
196196
$this->expectExceptionMessage('Expected serialized data to be a nullable array.');

tests/Hal/Serializer/ItemNormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use Symfony\Component\PropertyInfo\Type;
3030
use Symfony\Component\Serializer\Exception\LogicException;
3131
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
32-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
32+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
3333
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
3434
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
3535
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
@@ -289,7 +289,7 @@ public function testMaxDepth(): void
289289
$resourceClassResolverProphecy->reveal(),
290290
null,
291291
null,
292-
new ClassMetadataFactory(new AnnotationLoader())
292+
new ClassMetadataFactory(new AttributeLoader())
293293
);
294294
$serializer = new Serializer([$normalizer]);
295295
$normalizer->setSerializer($serializer);

tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,12 @@ public function testGetSupportedTypes(): void
344344
// TODO: use prophecy when getSupportedTypes() will be added to the interface
345345
$normalizer = new CollectionFiltersNormalizer(
346346
new class() implements NormalizerInterface {
347-
public function normalize(mixed $object, string $format = null, array $context = [])
347+
public function normalize(mixed $object, string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
348348
{
349349
return null;
350350
}
351351

352-
public function supportsNormalization(mixed $data, string $format = null): bool
352+
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
353353
{
354354
return true;
355355
}

tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ public function testGetSupportedTypes(): void
202202

203203
// TODO: use prophecy when getSupportedTypes() will be added to the interface
204204
$normalizer = new PartialCollectionViewNormalizer(new class() implements NormalizerInterface {
205-
public function normalize(mixed $object, string $format = null, array $context = [])
205+
public function normalize(mixed $object, string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
206206
{
207207
return null;
208208
}
209209

210-
public function supportsNormalization(mixed $data, string $format = null): bool
210+
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
211211
{
212212
return true;
213213
}

tests/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@
4242
use ApiPlatform\Tests\Fixtures\DummyValidatedEntity;
4343
use ApiPlatform\Tests\Fixtures\DummyValidatedHostnameEntity;
4444
use ApiPlatform\Tests\Fixtures\DummyValidatedUlidEntity;
45-
use Doctrine\Common\Annotations\AnnotationReader;
4645
use PHPUnit\Framework\TestCase;
4746
use Prophecy\PhpUnit\ProphecyTrait;
4847
use Symfony\Component\PropertyInfo\Type;
4948
use Symfony\Component\Validator\Constraints\Hostname;
5049
use Symfony\Component\Validator\Constraints\Ulid;
5150
use Symfony\Component\Validator\Mapping\ClassMetadata;
5251
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
53-
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
52+
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
5453

5554
/**
5655
* @author Baptiste Meyer <[email protected]>
@@ -64,7 +63,7 @@ class ValidatorPropertyMetadataFactoryTest extends TestCase
6463
protected function setUp(): void
6564
{
6665
$this->validatorClassMetadata = new ClassMetadata(DummyValidatedEntity::class);
67-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($this->validatorClassMetadata);
66+
(new AttributeLoader())->loadClassMetadata($this->validatorClassMetadata);
6867
}
6968

7069
public function testCreateWithPropertyWithRequiredConstraints(): void
@@ -218,7 +217,7 @@ public function testCreateWithRequiredByDecorated(): void
218217
public function testCreateWithPropertyWithValidationConstraints(): void
219218
{
220219
$validatorClassMetadata = new ClassMetadata(DummyIriWithValidationEntity::class);
221-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
220+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
222221

223222
$types = [
224223
'dummyUrl' => 'https://schema.org/url',
@@ -260,7 +259,7 @@ public function testCreateWithPropertyWithValidationConstraints(): void
260259
public function testCreateWithPropertyLengthRestriction(): void
261260
{
262261
$validatorClassMetadata = new ClassMetadata(DummyValidatedEntity::class);
263-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
262+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
264263

265264
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
266265
$validatorMetadataFactory->getMetadataFor(DummyValidatedEntity::class)
@@ -287,7 +286,7 @@ public function testCreateWithPropertyLengthRestriction(): void
287286
public function testCreateWithPropertyRegexRestriction(): void
288287
{
289288
$validatorClassMetadata = new ClassMetadata(DummyValidatedEntity::class);
290-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
289+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
291290

292291
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
293292
$validatorMetadataFactory->getMetadataFor(DummyValidatedEntity::class)
@@ -316,7 +315,7 @@ public function testCreateWithPropertyRegexRestriction(): void
316315
public function testCreateWithPropertyFormatRestriction(string $property, string $class, array $expectedSchema): void
317316
{
318317
$validatorClassMetadata = new ClassMetadata($class);
319-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
318+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
320319

321320
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
322321
$validatorMetadataFactory->getMetadataFor($class)
@@ -355,7 +354,7 @@ public static function providePropertySchemaFormatCases(): \Generator
355354
public function testCreateWithSequentiallyConstraint(): void
356355
{
357356
$validatorClassMetadata = new ClassMetadata(DummySequentiallyValidatedEntity::class);
358-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
357+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
359358

360359
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
361360
$validatorMetadataFactory->getMetadataFor(DummySequentiallyValidatedEntity::class)
@@ -382,7 +381,7 @@ public function testCreateWithSequentiallyConstraint(): void
382381
public function testCreateWithCompoundConstraint(): void
383382
{
384383
$validatorClassMetadata = new ClassMetadata(DummyCompoundValidatedEntity::class);
385-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
384+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
386385

387386
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
388387
$validatorMetadataFactory->getMetadataFor(DummyCompoundValidatedEntity::class)
@@ -409,7 +408,7 @@ public function testCreateWithCompoundConstraint(): void
409408
public function testCreateWithAtLeastOneOfConstraint(): void
410409
{
411410
$validatorClassMetadata = new ClassMetadata(DummyAtLeastOneOfValidatedEntity::class);
412-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
411+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
413412

414413
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
415414
$validatorMetadataFactory->getMetadataFor(DummyAtLeastOneOfValidatedEntity::class)
@@ -440,7 +439,7 @@ public function testCreateWithAtLeastOneOfConstraint(): void
440439
public function testCreateWithPropertyUniqueRestriction(): void
441440
{
442441
$validatorClassMetadata = new ClassMetadata(DummyUniqueValidatedEntity::class);
443-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
442+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
444443

445444
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
446445
$validatorMetadataFactory->getMetadataFor(DummyUniqueValidatedEntity::class)
@@ -469,7 +468,7 @@ public function testCreateWithPropertyUniqueRestriction(): void
469468
public function testCreateWithRangeConstraint(Type $type, string $property, array $expectedSchema): void
470469
{
471470
$validatorClassMetadata = new ClassMetadata(DummyRangeValidatedEntity::class);
472-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
471+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
473472

474473
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
475474
$validatorMetadataFactory->getMetadataFor(DummyRangeValidatedEntity::class)
@@ -506,7 +505,7 @@ public static function provideRangeConstraintCases(): \Generator
506505
public function testCreateWithPropertyChoiceRestriction(ApiProperty $propertyMetadata, string $property, array $expectedSchema): void
507506
{
508507
$validatorClassMetadata = new ClassMetadata(DummyValidatedChoiceEntity::class);
509-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
508+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
510509

511510
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
512511
$validatorMetadataFactory->getMetadataFor(DummyValidatedChoiceEntity::class)
@@ -545,7 +544,7 @@ public static function provideChoiceConstraintCases(): \Generator
545544
public function testCreateWithPropertyCountRestriction(string $property, array $expectedSchema): void
546545
{
547546
$validatorClassMetadata = new ClassMetadata(DummyCountValidatedEntity::class);
548-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
547+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
549548

550549
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
551550
$validatorMetadataFactory->getMetadataFor(DummyCountValidatedEntity::class)
@@ -577,7 +576,7 @@ public static function provideCountConstraintCases(): \Generator
577576
public function testCreateWithPropertyCollectionRestriction(): void
578577
{
579578
$validatorClassMetadata = new ClassMetadata(DummyCollectionValidatedEntity::class);
580-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
579+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
581580

582581
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
583582
$validatorMetadataFactory->getMetadataFor(DummyCollectionValidatedEntity::class)
@@ -643,7 +642,7 @@ public function testCreateWithPropertyCollectionRestriction(): void
643642
public function testCreateWithPropertyNumericRestriction(ApiProperty $propertyMetadata, string $property, array $expectedSchema): void
644643
{
645644
$validatorClassMetadata = new ClassMetadata(DummyNumericValidatedEntity::class);
646-
(new AnnotationLoader(new AnnotationReader()))->loadClassMetadata($validatorClassMetadata);
645+
(new AttributeLoader())->loadClassMetadata($validatorClassMetadata);
647646

648647
$validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
649648
$validatorMetadataFactory->getMetadataFor(DummyNumericValidatedEntity::class)

0 commit comments

Comments
 (0)