• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15973247443

30 Jun 2025 12:44PM UTC coverage: 22.065% (+0.001%) from 22.064%
15973247443

push

github

web-flow
chore: use treat phpdoc type as certain (#7250)

8 of 16 new or added lines in 13 files covered. (50.0%)

123 existing lines in 11 files now uncovered.

11518 of 52201 relevant lines covered (22.06%)

22.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Serializer/Tests/AbstractItemNormalizerTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Serializer\Tests;
15

16
use ApiPlatform\Metadata\ApiProperty;
17
use ApiPlatform\Metadata\ApiResource;
18
use ApiPlatform\Metadata\Exception\AccessDeniedException;
19
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
20
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
21
use ApiPlatform\Metadata\Get;
22
use ApiPlatform\Metadata\GetCollection;
23
use ApiPlatform\Metadata\IriConverterInterface;
24
use ApiPlatform\Metadata\Operations;
25
use ApiPlatform\Metadata\Patch;
26
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
27
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
28
use ApiPlatform\Metadata\Property\PropertyNameCollection;
29
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
30
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
31
use ApiPlatform\Metadata\ResourceAccessCheckerInterface;
32
use ApiPlatform\Metadata\ResourceClassResolverInterface;
33
use ApiPlatform\Metadata\UrlGeneratorInterface;
34
use ApiPlatform\Serializer\AbstractItemNormalizer;
35
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\DtoWithNullValue;
36
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\Dummy;
37
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\DummyTableInheritance;
38
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\DummyTableInheritanceChild;
39
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\DummyTableInheritanceRelated;
40
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\NonCloneableDummy;
41
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\PropertyCollectionIriOnly;
42
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\PropertyCollectionIriOnlyRelation;
43
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\RelatedDummy;
44
use ApiPlatform\Serializer\Tests\Fixtures\ApiResource\SecuredDummy;
45
use Doctrine\Common\Collections\ArrayCollection;
46
use PHPUnit\Framework\TestCase;
47
use Prophecy\Argument;
48
use Prophecy\PhpUnit\ProphecyTrait;
49
use Symfony\Component\PropertyAccess\PropertyAccessor;
50
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
51
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
52
use Symfony\Component\PropertyInfo\Type as LegacyType;
53
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
54
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
55
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
56
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
57
use Symfony\Component\Serializer\SerializerInterface;
58
use Symfony\Component\TypeInfo\Type;
59

60
/**
61
 * @author Amrouche Hamza <hamza.simperfit@gmail.com>
62
 * @author Kévin Dunglas <dunglas@gmail.com>
63
 */
64
class AbstractItemNormalizerTest extends TestCase
65
{
66
    use ProphecyTrait;
67

68
    #[\PHPUnit\Framework\Attributes\Group('legacy')]
69
    public function testSupportNormalizationAndSupportDenormalization(): void
70
    {
71
        $std = new \stdClass();
×
72
        $dummy = new Dummy();
×
73

74
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
75
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
76
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
77
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
78

79
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
80
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
81
        $resourceClassResolverProphecy->isResourceClass(\stdClass::class)->willReturn(false);
×
82

83
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
84

85
        $this->assertTrue($normalizer->supportsNormalization($dummy));
×
86
        $this->assertFalse($normalizer->supportsNormalization($std));
×
87
        $this->assertTrue($normalizer->supportsDenormalization($dummy, Dummy::class));
×
88
        $this->assertFalse($normalizer->supportsDenormalization($std, \stdClass::class));
×
89
        $this->assertFalse($normalizer->supportsNormalization([]));
×
90
        $this->assertSame(['object' => true], $normalizer->getSupportedTypes('any'));
×
91
    }
92

93
    public function testNormalize(): void
94
    {
95
        $relatedDummy = new RelatedDummy();
×
96

97
        $dummy = new Dummy();
×
98
        $dummy->setName('foo');
×
99
        $dummy->setAlias('ignored');
×
100
        $dummy->setRelatedDummy($relatedDummy);
×
101
        $dummy->relatedDummies->add(new RelatedDummy());
×
102

103
        $relatedDummies = new ArrayCollection([$relatedDummy]);
×
104

105
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
106
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['name', 'alias', 'relatedDummy', 'relatedDummies']));
×
107

108
        // BC layer for api-platform/metadata < 4.1
109
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
110
            $relatedDummyType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class);
×
111
            $relatedDummiesType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $relatedDummyType);
×
112

113
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
114
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true));
×
115
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'alias', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true));
×
116
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummyType])->withDescription('')->withReadable(true)->withWritable(false)->withReadableLink(false));
×
117
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummiesType])->withReadable(true)->withWritable(false)->withReadableLink(false));
×
118
        } else {
119
            $relatedDummyType = Type::object(RelatedDummy::class);
×
120
            $relatedDummiesType = Type::collection(Type::object(ArrayCollection::class), $relatedDummyType, Type::int());
×
121

122
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
123
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true));
×
124
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'alias', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true));
×
125
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withNativeType($relatedDummyType)->withDescription('')->withReadable(true)->withWritable(false)->withReadableLink(false));
×
126
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withNativeType($relatedDummiesType)->withReadable(true)->withWritable(false)->withReadableLink(false));
×
127
        }
128

129
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
130
        $iriConverterProphecy->getIriFromResource($dummy, Argument::cetera())->willReturn('/dummies/1');
×
131
        $iriConverterProphecy->getIriFromResource($relatedDummy, Argument::cetera())->willReturn('/dummies/2');
×
132

133
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
134
        $propertyAccessorProphecy->getValue($dummy, 'name')->willReturn('foo');
×
135
        $propertyAccessorProphecy->getValue($dummy, 'relatedDummy')->willReturn($relatedDummy);
×
136
        $propertyAccessorProphecy->getValue($dummy, 'relatedDummies')->willReturn($relatedDummies);
×
137

138
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
139
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
140
        $resourceClassResolverProphecy->getResourceClass($dummy, null)->willReturn(Dummy::class);
×
141
        $resourceClassResolverProphecy->getResourceClass($relatedDummy, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
142
        $resourceClassResolverProphecy->getResourceClass($relatedDummies, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
143
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
144
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
145

146
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
147
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
148
        $serializerProphecy->normalize('foo', null, Argument::type('array'))->willReturn('foo');
×
149
        $serializerProphecy->normalize(['/dummies/2'], null, Argument::type('array'))->willReturn(['/dummies/2']);
×
150

151
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
152
        $normalizer->setSerializer($serializerProphecy->reveal());
×
153

154
        $expected = [
×
155
            'name' => 'foo',
×
156
            'relatedDummy' => '/dummies/2',
×
157
            'relatedDummies' => ['/dummies/2'],
×
158
        ];
×
159
        $this->assertSame($expected, $normalizer->normalize($dummy, null, [
×
160
            'resources' => [],
×
161
            'ignored_attributes' => ['alias'],
×
162
        ]));
×
163
    }
164

165
    public function testNormalizeWithSecuredProperty(): void
166
    {
167
        $dummy = new SecuredDummy();
×
168
        $dummy->setTitle('myPublicTitle');
×
169
        $dummy->setAdminOnlyProperty('secret');
×
170

171
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
172
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'adminOnlyProperty']));
×
173

174
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
175

176
        // BC layer for api-platform/metadata < 4.1
177
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
178
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true));
×
179
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withSecurity('is_granted(\'ROLE_ADMIN\')'));
×
180
        } else {
181
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true));
×
182
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withSecurity('is_granted(\'ROLE_ADMIN\')'));
×
183
        }
184

185
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
186
        $iriConverterProphecy->getIriFromResource($dummy, Argument::cetera())->willReturn('/secured_dummies/1');
×
187

188
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
189
        $propertyAccessorProphecy->getValue($dummy, 'title')->willReturn('myPublicTitle');
×
190
        $propertyAccessorProphecy->getValue($dummy, 'adminOnlyProperty')->willReturn('secret');
×
191

192
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
193
        $resourceClassResolverProphecy->getResourceClass($dummy, null)->willReturn(SecuredDummy::class);
×
194
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
195
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
196

197
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
198
        $resourceAccessChecker->isGranted(
×
199
            SecuredDummy::class,
×
200
            'is_granted(\'ROLE_ADMIN\')',
×
201
            ['object' => $dummy, 'property' => 'adminOnlyProperty']
×
202
        )->willReturn(false);
×
203

204
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
205
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
206
        $serializerProphecy->normalize('myPublicTitle', null, Argument::type('array'))->willReturn('myPublicTitle');
×
207

208
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
209
        $normalizer->setSerializer($serializerProphecy->reveal());
×
210

211
        $expected = [
×
212
            'title' => 'myPublicTitle',
×
213
        ];
×
214
        $this->assertSame($expected, $normalizer->normalize($dummy, null, [
×
215
            'resources' => [],
×
216
        ]));
×
217
    }
218

219
    public function testNormalizePropertyAsIriWithUriTemplate(): void
220
    {
221
        $propertyCollectionIriOnlyRelation = new PropertyCollectionIriOnlyRelation();
×
222
        $propertyCollectionIriOnlyRelation->name = 'My Relation';
×
223

224
        $propertyCollectionIriOnly = new PropertyCollectionIriOnly();
×
225
        $propertyCollectionIriOnly->addPropertyCollectionIriOnlyRelation($propertyCollectionIriOnlyRelation);
×
226

227
        $collectionOperation = new GetCollection('/property-collection-relations');
×
228
        $getIterableOperation = new GetCollection('/parent/{parentId}/another-collection-operations');
×
229
        $getToOneOperation = new Get('/parent/{parentId}/another-collection-operations/{id}');
×
230

231
        $resourceRelationMetadataCollection = new ResourceMetadataCollection(PropertyCollectionIriOnlyRelation::class, [
×
232
            (new ApiResource())->withOperations(new Operations([$collectionOperation, $getIterableOperation, $getToOneOperation])),
×
233
        ]);
×
234

235
        $resourceMetadataCollectionFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
236
        $resourceMetadataCollectionFactoryProphecy->create(PropertyCollectionIriOnlyRelation::class)->willReturn($resourceRelationMetadataCollection);
×
237

238
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
239
        $propertyNameCollectionFactoryProphecy->create(PropertyCollectionIriOnly::class, ['normalization_groups' => null, 'denormalization_groups' => null, 'operation_name' => null])->willReturn(
×
240
            new PropertyNameCollection(['propertyCollectionIriOnlyRelation', 'iterableIri', 'toOneRelation'])
×
241
        );
×
242

243
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
244

245
        // BC layer for api-platform/metadata < 4.1
246
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
247
            $propertyMetadataFactoryProphecy->create(PropertyCollectionIriOnly::class, 'propertyCollectionIriOnlyRelation', ['normalization_groups' => null, 'denormalization_groups' => null, 'operation_name' => null])->willReturn(
×
248
                (new ApiProperty())->withReadable(true)->withUriTemplate('/property-collection-relations')->withBuiltinTypes([
×
249
                    new LegacyType('iterable', false, null, true, new LegacyType('int', false, null, false), new LegacyType('object', false, PropertyCollectionIriOnlyRelation::class, false)),
×
250
                ])
×
251
            );
×
252
            $propertyMetadataFactoryProphecy->create(PropertyCollectionIriOnly::class, 'iterableIri', ['normalization_groups' => null, 'denormalization_groups' => null, 'operation_name' => null])->willReturn(
×
253
                (new ApiProperty())->withReadable(true)->withUriTemplate('/parent/{parentId}/another-collection-operations')->withBuiltinTypes([
×
254
                    new LegacyType('iterable', false, null, true, new LegacyType('int', false, null, false), new LegacyType('object', false, PropertyCollectionIriOnlyRelation::class, false)),
×
255
                ])
×
256
            );
×
257
            $propertyMetadataFactoryProphecy->create(PropertyCollectionIriOnly::class, 'toOneRelation', ['normalization_groups' => null, 'denormalization_groups' => null, 'operation_name' => null])->willReturn(
×
258
                (new ApiProperty())->withReadable(true)->withUriTemplate('/parent/{parentId}/another-collection-operations/{id}')->withBuiltinTypes([
×
259
                    new LegacyType('object', false, PropertyCollectionIriOnlyRelation::class, false),
×
260
                ])
×
261
            );
×
262
        } else {
263
            $propertyMetadataFactoryProphecy->create(PropertyCollectionIriOnly::class, 'propertyCollectionIriOnlyRelation', ['normalization_groups' => null, 'denormalization_groups' => null, 'operation_name' => null])->willReturn(
×
264
                (new ApiProperty())->withReadable(true)->withUriTemplate('/property-collection-relations')->withNativeType(Type::list(Type::object(PropertyCollectionIriOnlyRelation::class)))
×
265
            );
×
266
            $propertyMetadataFactoryProphecy->create(PropertyCollectionIriOnly::class, 'iterableIri', ['normalization_groups' => null, 'denormalization_groups' => null, 'operation_name' => null])->willReturn(
×
267
                (new ApiProperty())->withReadable(true)->withUriTemplate('/parent/{parentId}/another-collection-operations')->withNativeType(Type::iterable(Type::object(PropertyCollectionIriOnlyRelation::class)))
×
268
            );
×
269
            $propertyMetadataFactoryProphecy->create(PropertyCollectionIriOnly::class, 'toOneRelation', ['normalization_groups' => null, 'denormalization_groups' => null, 'operation_name' => null])->willReturn(
×
270
                (new ApiProperty())->withReadable(true)->withUriTemplate('/parent/{parentId}/another-collection-operations/{id}')->withNativeType(Type::object(PropertyCollectionIriOnlyRelation::class))
×
271
            );
×
272
        }
273

274
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
275
        $iriConverterProphecy->getIriFromResource($propertyCollectionIriOnly, UrlGeneratorInterface::ABS_URL, null, Argument::any())->willReturn('/property-collection-relations', '/parent/42/another-collection-operations');
×
276
        $iriConverterProphecy->getIriFromResource($propertyCollectionIriOnly, UrlGeneratorInterface::ABS_PATH, Argument::type(GetCollection::class), Argument::any())->willReturn('/property-collection-relations', '/parent/42/another-collection-operations');
×
277
        $iriConverterProphecy->getIriFromResource($propertyCollectionIriOnly, UrlGeneratorInterface::ABS_PATH, Argument::type(Get::class), Argument::any())->willReturn('/parent/42/another-collection-operations/24');
×
278

279
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
280
        $propertyAccessorProphecy->getValue($propertyCollectionIriOnly, 'propertyCollectionIriOnlyRelation')->willReturn([$propertyCollectionIriOnlyRelation]);
×
281
        $propertyAccessorProphecy->getValue($propertyCollectionIriOnly, 'iterableIri')->willReturn($propertyCollectionIriOnlyRelation);
×
282
        $propertyAccessorProphecy->getValue($propertyCollectionIriOnly, 'toOneRelation')->willReturn($propertyCollectionIriOnlyRelation);
×
283

284
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
285

286
        $resourceClassResolverProphecy->isResourceClass(PropertyCollectionIriOnly::class)->willReturn(true);
×
287
        $resourceClassResolverProphecy->getResourceClass(null, PropertyCollectionIriOnly::class)->willReturn(PropertyCollectionIriOnly::class);
×
288

289
        $resourceClassResolverProphecy->isResourceClass(PropertyCollectionIriOnlyRelation::class)->willReturn(true);
×
290
        $resourceClassResolverProphecy->getResourceClass([$propertyCollectionIriOnlyRelation], PropertyCollectionIriOnlyRelation::class)->willReturn(PropertyCollectionIriOnlyRelation::class);
×
291

292
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), new PropertyAccessor(), // $propertyAccessorProphecy->reveal(),
×
293
            null, null, [], $resourceMetadataCollectionFactoryProphecy->reveal(), null, ) extends AbstractItemNormalizer {};
×
294

295
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
296
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
297
        $normalizer->setSerializer($serializerProphecy->reveal());
×
298

299
        $expected = [
×
300
            'propertyCollectionIriOnlyRelation' => '/property-collection-relations',
×
301
            'iterableIri' => '/parent/42/another-collection-operations',
×
302
            'toOneRelation' => '/parent/42/another-collection-operations/24',
×
303
        ];
×
304

305
        $this->assertSame($expected, $normalizer->normalize($propertyCollectionIriOnly, 'jsonld', [
×
306
            'resources' => [],
×
307
            'root_operation' => new GetCollection('/property_collection_iri_onlies'),
×
308
        ]));
×
309
    }
310

311
    public function testDenormalizeWithSecuredPropertyAndThrowOnAccessDeniedExtraPropertyInAttributeMetaThrowsAccessDeniedExceptionWithSecurityMessage(): void
312
    {
313
        $data = [
×
314
            'title' => 'foo',
×
315
            'adminOnlyProperty' => 'secret',
×
316
        ];
×
317
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
318
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'adminOnlyProperty']));
×
319

320
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
321

322
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
323
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
324
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withSecurityPostDenormalize('is_granted(\'ROLE_ADMIN\')')->withExtraProperties(['throw_on_access_denied' => true]));
×
325
        } else {
326
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
327
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withSecurityPostDenormalize('is_granted(\'ROLE_ADMIN\')')->withExtraProperties(['throw_on_access_denied' => true]));
×
328
        }
329

330
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
331

332
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
333

334
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
335
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
336
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
337

338
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
339
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
340

341
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
342
        $resourceAccessChecker->isGranted(
×
343
            SecuredDummy::class,
×
344
            'is_granted(\'ROLE_ADMIN\')',
×
345
            Argument::that(function (array $context) {
×
346
                return \array_key_exists('property', $context)
×
347
                    && \array_key_exists('object', $context)
×
348
                    && \array_key_exists('previous_object', $context)
×
349
                    && 'adminOnlyProperty' === $context['property']
×
350
                    && null === $context['previous_object']
×
351
                    && $context['object'] instanceof SecuredDummy;
×
352
            })
×
353
        )->willReturn(false);
×
354

355
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
356
        $normalizer->setSerializer($serializerProphecy->reveal());
×
357

358
        $this->expectException(AccessDeniedException::class);
×
359
        $this->expectExceptionMessage('Access denied');
×
360

361
        $normalizer->denormalize($data, SecuredDummy::class);
×
362
    }
363

364
    public function testDenormalizeWithSecuredPropertyAndThrowOnAccessDeniedExtraPropertyInOperationAndSecurityMessageInOperationThrowsAccessDeniedExceptionWithSecurityMessage(): void
365
    {
366
        $data = [
×
367
            'title' => 'foo',
×
368
            'adminOnlyProperty' => 'secret',
×
369
        ];
×
370
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
371
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'adminOnlyProperty']));
×
372

373
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
374

375
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
376
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
377
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withSecurityPostDenormalize('is_granted(\'ROLE_ADMIN\')'));
×
378
        } else {
379
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
380
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withSecurityPostDenormalize('is_granted(\'ROLE_ADMIN\')'));
×
381
        }
382

383
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
384

385
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
386

387
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
388
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
389
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
390

391
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
392
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
393

394
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
395
        $resourceAccessChecker->isGranted(
×
396
            SecuredDummy::class,
×
397
            'is_granted(\'ROLE_ADMIN\')',
×
398
            Argument::that(function (array $context) {
×
399
                return \array_key_exists('property', $context)
×
400
                    && \array_key_exists('object', $context)
×
401
                    && \array_key_exists('previous_object', $context)
×
402
                    && 'adminOnlyProperty' === $context['property']
×
403
                    && null === $context['previous_object']
×
404
                    && $context['object'] instanceof SecuredDummy;
×
405
            })
×
406
        )->willReturn(false);
×
407

408
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
409
        $normalizer->setSerializer($serializerProphecy->reveal());
×
410

411
        $this->expectException(AccessDeniedException::class);
×
412
        $this->expectExceptionMessage('Custom access denied message');
×
413

414
        $operation = new Patch(securityMessage: 'Custom access denied message', extraProperties: ['throw_on_access_denied' => true]);
×
415

416
        $normalizer->denormalize($data, SecuredDummy::class, 'json', [
×
417
            'operation' => $operation,
×
418
        ]);
×
419
    }
420

421
    public function testDenormalizeWithSecuredPropertyAndThrowOnAccessDeniedExtraPropertyInOperationThrowsAccessDeniedException(): void
422
    {
423
        $data = [
×
424
            'title' => 'foo',
×
425
            'adminOnlyProperty' => 'secret',
×
426
        ];
×
427
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
428
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'adminOnlyProperty']));
×
429

430
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
431

432
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
433
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
434
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withSecurityPostDenormalize('is_granted(\'ROLE_ADMIN\')'));
×
435
        } else {
436
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
437
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withSecurityPostDenormalize('is_granted(\'ROLE_ADMIN\')'));
×
438
        }
439

440
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
441

442
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
443

444
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
445
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
446
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
447

448
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
449
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
450

451
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
452
        $resourceAccessChecker->isGranted(
×
453
            SecuredDummy::class,
×
454
            'is_granted(\'ROLE_ADMIN\')',
×
455
            Argument::that(function (array $context) {
×
456
                return \array_key_exists('property', $context)
×
457
                    && \array_key_exists('object', $context)
×
458
                    && \array_key_exists('previous_object', $context)
×
459
                    && 'adminOnlyProperty' === $context['property']
×
460
                    && null === $context['previous_object']
×
461
                    && $context['object'] instanceof SecuredDummy;
×
462
            })
×
463
        )->willReturn(false);
×
464

465
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
466
        $normalizer->setSerializer($serializerProphecy->reveal());
×
467

468
        $this->expectException(AccessDeniedException::class);
×
469
        $this->expectExceptionMessage('Access denied');
×
470

471
        $operation = new Patch(extraProperties: ['throw_on_access_denied' => true]);
×
472

473
        $normalizer->denormalize($data, SecuredDummy::class, 'json', [
×
474
            'operation' => $operation,
×
475
        ]);
×
476
    }
477

478
    public function testDenormalizeWithSecuredProperty(): void
479
    {
480
        $data = [
×
481
            'title' => 'foo',
×
482
            'adminOnlyProperty' => 'secret',
×
483
        ];
×
484

485
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
486
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'adminOnlyProperty']));
×
487

488
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
489

490
        // BC layer for api-platform/metadata < 4.1
491
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
492
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
493
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withSecurity('is_granted(\'ROLE_ADMIN\')'));
×
494
        } else {
495
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
496
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'adminOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withSecurity('is_granted(\'ROLE_ADMIN\')'));
×
497
        }
498

499
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
500

501
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
502

503
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
504
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
505
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
506

507
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
508
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
509

510
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
511
        $resourceAccessChecker->isGranted(
×
512
            SecuredDummy::class,
×
513
            'is_granted(\'ROLE_ADMIN\')',
×
514
            ['object' => null, 'property' => 'adminOnlyProperty']
×
515
        )->willReturn(false);
×
516

517
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
518
        $normalizer->setSerializer($serializerProphecy->reveal());
×
519

520
        $actual = $normalizer->denormalize($data, SecuredDummy::class);
×
521

522
        $this->assertInstanceOf(SecuredDummy::class, $actual);
×
523

524
        $propertyAccessorProphecy->setValue($actual, 'title', 'foo')->shouldHaveBeenCalled();
×
525
        $propertyAccessorProphecy->setValue($actual, 'adminOnlyProperty', 'secret')->shouldNotHaveBeenCalled();
×
526
    }
527

528
    public function testDenormalizeCreateWithDeniedPostDenormalizeSecuredProperty(): void
529
    {
530
        $data = [
×
531
            'title' => 'foo',
×
532
            'ownerOnlyProperty' => 'should not be set',
×
533
        ];
×
534

535
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
536
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'ownerOnlyProperty']));
×
537

538
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
539

540
        // BC layer for api-platform/metadata < 4.1
541
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
542
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
543
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withWritable(true)->withSecurityPostDenormalize('false')->withDefault(''));
×
544
        } else {
545
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
546
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withWritable(true)->withSecurityPostDenormalize('false')->withDefault(''));
×
547
        }
548

549
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
550

551
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
552

553
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
554
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
555
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
556

557
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
558
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
559

560
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
561
        $resourceAccessChecker->isGranted(
×
562
            SecuredDummy::class,
×
563
            'false',
×
564
            Argument::any()
×
565
        )->willReturn(false);
×
566

567
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
568
        $normalizer->setSerializer($serializerProphecy->reveal());
×
569

570
        $actual = $normalizer->denormalize($data, SecuredDummy::class);
×
571

572
        $this->assertInstanceOf(SecuredDummy::class, $actual);
×
573

574
        $propertyAccessorProphecy->setValue($actual, 'title', 'foo')->shouldHaveBeenCalled();
×
575
        $propertyAccessorProphecy->setValue($actual, 'ownerOnlyProperty', 'should not be set')->shouldHaveBeenCalled();
×
576
        $propertyAccessorProphecy->setValue($actual, 'ownerOnlyProperty', '')->shouldHaveBeenCalled();
×
577
    }
578

579
    public function testDenormalizeUpdateWithSecuredProperty(): void
580
    {
581
        $dummy = new SecuredDummy();
×
582

583
        $data = [
×
584
            'title' => 'foo',
×
585
            'ownerOnlyProperty' => 'secret',
×
586
        ];
×
587

588
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
589
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'ownerOnlyProperty']));
×
590

591
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
592

593
        // BC layer for api-platform/metadata < 4.1
594
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
595
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
596
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withWritable(true)->withSecurity('true'));
×
597
        } else {
598
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
599
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withWritable(true)->withSecurity('true'));
×
600
        }
601

602
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
603

604
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
605

606
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
607
        $resourceClassResolverProphecy->getResourceClass($dummy, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
608
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
609
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
610

611
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
612
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
613

614
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
615
        $resourceAccessChecker->isGranted(
×
616
            SecuredDummy::class,
×
617
            'true',
×
618
            ['object' => null, 'property' => 'ownerOnlyProperty']
×
619
        )->willReturn(true);
×
620
        $resourceAccessChecker->isGranted(
×
621
            SecuredDummy::class,
×
622
            'true',
×
623
            ['object' => $dummy, 'property' => 'ownerOnlyProperty']
×
624
        )->willReturn(true);
×
625

626
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
627
        $normalizer->setSerializer($serializerProphecy->reveal());
×
628

629
        $context = [AbstractItemNormalizer::OBJECT_TO_POPULATE => $dummy];
×
630
        $actual = $normalizer->denormalize($data, SecuredDummy::class, null, $context);
×
631

632
        $this->assertInstanceOf(SecuredDummy::class, $actual);
×
633

634
        $propertyAccessorProphecy->setValue($actual, 'title', 'foo')->shouldHaveBeenCalled();
×
635
        $propertyAccessorProphecy->setValue($actual, 'ownerOnlyProperty', 'secret')->shouldHaveBeenCalled();
×
636
    }
637

638
    public function testDenormalizeUpdateWithDeniedSecuredProperty(): void
639
    {
640
        $dummy = new SecuredDummy();
×
641
        $dummy->setOwnerOnlyProperty('secret');
×
642

643
        $data = [
×
644
            'title' => 'foo',
×
645
            'ownerOnlyProperty' => 'should not be set',
×
646
        ];
×
647

648
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
649
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'ownerOnlyProperty']));
×
650

651
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
652

653
        // BC layer for api-platform/metadata < 4.1
654
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
655
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
656
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withWritable(true)->withSecurity('false'));
×
657
        } else {
658
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
659
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withWritable(true)->withSecurity('false'));
×
660
        }
661

662
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
663

664
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
665

666
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
667
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
668
        $resourceClassResolverProphecy->getResourceClass($dummy, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
669
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
670

671
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
672
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
673

674
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
675
        $resourceAccessChecker->isGranted(
×
676
            SecuredDummy::class,
×
677
            'false',
×
678
            ['object' => null, 'property' => 'ownerOnlyProperty']
×
679
        )->willReturn(false);
×
680
        $resourceAccessChecker->isGranted(
×
681
            SecuredDummy::class,
×
682
            'false',
×
683
            ['object' => $dummy, 'property' => 'ownerOnlyProperty']
×
684
        )->willReturn(false);
×
685

686
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
687
        $normalizer->setSerializer($serializerProphecy->reveal());
×
688

689
        $context = [AbstractItemNormalizer::OBJECT_TO_POPULATE => $dummy];
×
690
        $actual = $normalizer->denormalize($data, SecuredDummy::class, null, $context);
×
691

692
        $this->assertInstanceOf(SecuredDummy::class, $actual);
×
693

694
        $propertyAccessorProphecy->setValue($actual, 'title', 'foo')->shouldHaveBeenCalled();
×
695
        $propertyAccessorProphecy->setValue($actual, 'ownerOnlyProperty', 'should not be set')->shouldNotHaveBeenCalled();
×
696
    }
697

698
    public function testDenormalizeUpdateWithDeniedPostDenormalizeSecuredProperty(): void
699
    {
700
        $dummy = new SecuredDummy();
×
701
        $dummy->setOwnerOnlyProperty('secret');
×
702

703
        $data = [
×
704
            'title' => 'foo',
×
705
            'ownerOnlyProperty' => 'should not be set',
×
706
        ];
×
707

708
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
709
        $propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn(new PropertyNameCollection(['title', 'ownerOnlyProperty']));
×
710

711
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
712

713
        // BC layer for api-platform/metadata < 4.1
714
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
715
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
716
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true)->withWritable(true)->withSecurityPostDenormalize('false'));
×
717
        } else {
718
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
719
            $propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true)->withWritable(true)->withSecurityPostDenormalize('false'));
×
720
        }
721

722
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
723

724
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
725
        $propertyAccessorProphecy->getValue($dummy, 'ownerOnlyProperty')->willReturn('secret');
×
726

727
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
728
        $resourceClassResolverProphecy->getResourceClass($dummy, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
729
        $resourceClassResolverProphecy->getResourceClass(null, SecuredDummy::class)->willReturn(SecuredDummy::class);
×
730
        $resourceClassResolverProphecy->isResourceClass(SecuredDummy::class)->willReturn(true);
×
731

732
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
733
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
734

735
        $resourceAccessChecker = $this->prophesize(ResourceAccessCheckerInterface::class);
×
736
        $resourceAccessChecker->isGranted(
×
737
            SecuredDummy::class,
×
738
            'false',
×
739
            ['object' => $dummy, 'previous_object' => $dummy, 'property' => 'ownerOnlyProperty']
×
740
        )->willReturn(false);
×
741

742
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, $resourceAccessChecker->reveal()) extends AbstractItemNormalizer {};
×
743
        $normalizer->setSerializer($serializerProphecy->reveal());
×
744

745
        $context = [AbstractItemNormalizer::OBJECT_TO_POPULATE => $dummy];
×
746
        $actual = $normalizer->denormalize($data, SecuredDummy::class, null, $context);
×
747

748
        $this->assertInstanceOf(SecuredDummy::class, $actual);
×
749

750
        $propertyAccessorProphecy->setValue($actual, 'title', 'foo')->shouldHaveBeenCalled();
×
751
        $propertyAccessorProphecy->setValue($actual, 'ownerOnlyProperty', 'should not be set')->shouldHaveBeenCalled();
×
752
        $propertyAccessorProphecy->setValue($actual, 'ownerOnlyProperty', 'secret')->shouldHaveBeenCalled();
×
753
    }
754

755
    public function testNormalizeReadableLinks(): void
756
    {
757
        $relatedDummy = new RelatedDummy();
×
758

759
        $dummy = new Dummy();
×
760
        $dummy->setRelatedDummy($relatedDummy);
×
761
        $dummy->relatedDummies->add(new RelatedDummy());
×
762

763
        $relatedDummies = new ArrayCollection([$relatedDummy]);
×
764

765
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
766
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['relatedDummy', 'relatedDummies']));
×
767

768
        // BC layer for api-platform/metadata < 4.1
769
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
770
            $relatedDummyType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class);
×
771
            $relatedDummiesType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $relatedDummyType);
×
772

773
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
774
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummyType])->withReadable(true)->withWritable(false)->withReadableLink(true));
×
775
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummiesType])->withReadable(true)->withWritable(false)->withReadableLink(true));
×
776
        } else {
777
            $relatedDummyType = Type::object(RelatedDummy::class);
×
778
            $relatedDummiesType = Type::collection(Type::object(ArrayCollection::class), $relatedDummyType, Type::int());
×
779

780
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
781
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withNativeType($relatedDummyType)->withReadable(true)->withWritable(false)->withReadableLink(true));
×
782
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withNativeType($relatedDummiesType)->withReadable(true)->withWritable(false)->withReadableLink(true));
×
783
        }
784

785
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
786
        $iriConverterProphecy->getIriFromResource($dummy, Argument::cetera())->willReturn('/dummies/1');
×
787

788
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
789
        $propertyAccessorProphecy->getValue($dummy, 'relatedDummy')->willReturn($relatedDummy);
×
790
        $propertyAccessorProphecy->getValue($dummy, 'relatedDummies')->willReturn($relatedDummies);
×
791

792
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
793
        $resourceClassResolverProphecy->getResourceClass($dummy, null)->willReturn(Dummy::class);
×
794
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
795
        $resourceClassResolverProphecy->getResourceClass($relatedDummy, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
796
        $resourceClassResolverProphecy->getResourceClass($relatedDummies, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
797
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
798
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
799

800
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
801
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
802
        $relatedDummyChildContext = Argument::allOf(
×
803
            Argument::type('array'),
×
804
            Argument::withEntry('resource_class', RelatedDummy::class),
×
805
            Argument::not(Argument::withKey('iri')),
×
806
            Argument::not(Argument::withKey('force_resource_class'))
×
807
        );
×
808
        $serializerProphecy->normalize($relatedDummy, null, $relatedDummyChildContext)->willReturn(['foo' => 'hello']);
×
809
        $serializerProphecy->normalize(['foo' => 'hello'], null, Argument::type('array'))->willReturn(['foo' => 'hello']);
×
810
        $serializerProphecy->normalize([['foo' => 'hello']], null, Argument::type('array'))->willReturn([['foo' => 'hello']]);
×
811

812
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
813
        $normalizer->setSerializer($serializerProphecy->reveal());
×
814

815
        $expected = [
×
816
            'relatedDummy' => ['foo' => 'hello'],
×
817
            'relatedDummies' => [['foo' => 'hello']],
×
818
        ];
×
819
        $this->assertSame($expected, $normalizer->normalize($dummy, null, [
×
820
            'resources' => [],
×
821
            'force_resource_class' => Dummy::class,
×
822
        ]));
×
823
    }
824

825
    public function testNormalizePolymorphicRelations(): void
826
    {
827
        $concreteDummy = new DummyTableInheritanceChild();
×
828

829
        $dummy = new DummyTableInheritanceRelated();
×
830
        $dummy->addChild($concreteDummy);
×
831

832
        $abstractDummies = new ArrayCollection([$concreteDummy]);
×
833

834
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
835
        $propertyNameCollectionFactoryProphecy->create(DummyTableInheritanceRelated::class, [])->willReturn(new PropertyNameCollection(['children']));
×
836

837
        // BC layer for api-platform/metadata < 4.1
838
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
839
            $abstractDummyType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, DummyTableInheritance::class);
×
840
            $abstractDummiesType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $abstractDummyType);
×
841

842
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
843
            $propertyMetadataFactoryProphecy->create(DummyTableInheritanceRelated::class, 'children', [])->willReturn((new ApiProperty())->withBuiltinTypes([$abstractDummiesType])->withReadable(true)->withWritable(false)->withReadableLink(true));
×
844
        } else {
845
            $abstractDummyType = Type::object(DummyTableInheritance::class);
×
846
            $abstractDummiesType = Type::collection(Type::object(ArrayCollection::class), $abstractDummyType, Type::int());
×
847

848
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
849
            $propertyMetadataFactoryProphecy->create(DummyTableInheritanceRelated::class, 'children', [])->willReturn((new ApiProperty())->withNativeType($abstractDummiesType)->withReadable(true)->withWritable(false)->withReadableLink(true));
×
850
        }
851

852
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
853
        $iriConverterProphecy->getIriFromResource($dummy, Argument::cetera())->willReturn('/dummies/1');
×
854

855
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
856
        $propertyAccessorProphecy->getValue($dummy, 'children')->willReturn($abstractDummies);
×
857

858
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
859
        $resourceClassResolverProphecy->getResourceClass($dummy, null)->willReturn(DummyTableInheritanceRelated::class);
×
860
        $resourceClassResolverProphecy->getResourceClass(null, DummyTableInheritanceRelated::class)->willReturn(DummyTableInheritanceRelated::class);
×
861
        $resourceClassResolverProphecy->getResourceClass($concreteDummy, DummyTableInheritance::class)->willReturn(DummyTableInheritanceChild::class);
×
862
        $resourceClassResolverProphecy->getResourceClass($abstractDummies, DummyTableInheritance::class)->willReturn(DummyTableInheritance::class);
×
863
        $resourceClassResolverProphecy->isResourceClass(DummyTableInheritanceRelated::class)->willReturn(true);
×
864
        $resourceClassResolverProphecy->isResourceClass(DummyTableInheritance::class)->willReturn(true);
×
865

866
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
867
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
868
        $concreteDummyChildContext = Argument::allOf(
×
869
            Argument::type('array'),
×
870
            Argument::not(Argument::withKey('iri'))
×
871
        );
×
872
        $serializerProphecy->normalize($concreteDummy, null, $concreteDummyChildContext)->willReturn(['foo' => 'concrete']);
×
873
        $serializerProphecy->normalize([['foo' => 'concrete']], null, Argument::type('array'))->willReturn([['foo' => 'concrete']]);
×
874

875
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
876
        $normalizer->setSerializer($serializerProphecy->reveal());
×
877

878
        $expected = [
×
879
            'children' => [['foo' => 'concrete']],
×
880
        ];
×
881
        $this->assertSame($expected, $normalizer->normalize($dummy, null, [
×
882
            'resources' => [],
×
883
        ]));
×
884
    }
885

886
    public function testDenormalize(): void
887
    {
888
        $data = [
×
889
            'name' => 'foo',
×
890
            'relatedDummy' => '/dummies/1',
×
891
            'relatedDummies' => ['/dummies/2'],
×
892
        ];
×
893

894
        $relatedDummy1 = new RelatedDummy();
×
895
        $relatedDummy2 = new RelatedDummy();
×
896

897
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
898
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['name', 'relatedDummy', 'relatedDummies']));
×
899

900
        // BC layer for api-platform/metadata < 4.1
901
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
902
            $relatedDummyType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class);
×
903
            $relatedDummiesType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $relatedDummyType);
×
904

905
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
906
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
907

908
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummyType])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
909
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummiesType])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
910
        } else {
911
            $relatedDummyType = Type::object(RelatedDummy::class);
×
912
            $relatedDummiesType = Type::collection(Type::object(ArrayCollection::class), $relatedDummyType, Type::int());
×
913

914
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
915
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
916

917
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withNativeType($relatedDummyType)->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
918
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withNativeType($relatedDummiesType)->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
919
        }
920

921
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
922
        $iriConverterProphecy->getResourceFromIri('/dummies/1', Argument::type('array'))->willReturn($relatedDummy1);
×
923
        $iriConverterProphecy->getResourceFromIri('/dummies/2', Argument::type('array'))->willReturn($relatedDummy2);
×
924

925
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
926

927
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
928
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
929
        $resourceClassResolverProphecy->getResourceClass(null, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
930
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
931
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
932

933
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
934
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
935

936
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
937
        $normalizer->setSerializer($serializerProphecy->reveal());
×
938

939
        $actual = $normalizer->denormalize($data, Dummy::class);
×
940

941
        $this->assertInstanceOf(Dummy::class, $actual);
×
942

943
        $propertyAccessorProphecy->setValue($actual, 'name', 'foo')->shouldHaveBeenCalled();
×
944
        $propertyAccessorProphecy->setValue($actual, 'relatedDummy', $relatedDummy1)->shouldHaveBeenCalled();
×
945
        $propertyAccessorProphecy->setValue($actual, 'relatedDummies', [$relatedDummy2])->shouldHaveBeenCalled();
×
946
    }
947

948
    public function testCanDenormalizeInputClassWithDifferentFieldsThanResourceClass(): void
949
    {
950
        $this->markTestSkipped('TODO: check why this test has been commented');
×
951

952
        // $data = [
953
        //     'dummyName' => 'Dummy Name',
954
        // ];
955
        //
956
        // $context = [
957
        //     'resource_class' => DummyForAdditionalFields::class,
958
        //     'input' => ['class' => DummyForAdditionalFieldsInput::class],
959
        //     'output' => ['class' => DummyForAdditionalFields::class],
960
        // ];
961
        // $augmentedContext = $context + ['api_denormalize' => true];
962
        //
963
        // $preHydratedDummy = new DummyForAdditionalFieldsInput('Name Dummy');
964
        // $cleanedContext = array_diff_key($augmentedContext, [
965
        //     'input' => null,
966
        //     'resource_class' => null,
967
        // ]);
968
        // $cleanedContextWithObjectToPopulate = array_merge($cleanedContext, [
969
        //     AbstractObjectNormalizer::OBJECT_TO_POPULATE => $preHydratedDummy,
970
        //     AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE => true,
971
        // ]);
972
        //
973
        // $dummyInputDto = new DummyForAdditionalFieldsInput('Dummy Name');
974
        // $dummy = new DummyForAdditionalFields('Dummy Name', 'name-dummy');
975
        //
976
        // $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
977
        //
978
        // $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
979
        //
980
        // $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
981
        //
982
        // $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
983
        // $resourceClassResolverProphecy->getResourceClass(null, DummyForAdditionalFields::class)->willReturn(DummyForAdditionalFields::class);
984
        //
985
        // $inputDataTransformerProphecy = $this->prophesize(DataTransformerInitializerInterface::class);
986
        // $inputDataTransformerProphecy->willImplement(DataTransformerInitializerInterface::class);
987
        // $inputDataTransformerProphecy->initialize(DummyForAdditionalFieldsInput::class, $cleanedContext)->willReturn($preHydratedDummy);
988
        // $inputDataTransformerProphecy->supportsTransformation($data, DummyForAdditionalFields::class, $augmentedContext)->willReturn(true);
989
        // $inputDataTransformerProphecy->transform($dummyInputDto, DummyForAdditionalFields::class, $augmentedContext)->willReturn($dummy);
990
        //
991
        // $serializerProphecy = $this->prophesize(SerializerInterface::class);
992
        // $serializerProphecy->willImplement(DenormalizerInterface::class);
993
        // $serializerProphecy->denormalize($data, DummyForAdditionalFieldsInput::class, 'json', $cleanedContextWithObjectToPopulate)->willReturn($dummyInputDto);
994
        //
995
        // $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), null, null, null, [], null, null) extends AbstractItemNormalizer {
996
        // };
997
        // $normalizer->setSerializer($serializerProphecy->reveal());
998
        //
999
        // $actual = $normalizer->denormalize($data, DummyForAdditionalFields::class, 'json', $context);
1000
        //
1001
        // $this->assertInstanceOf(DummyForAdditionalFields::class, $actual);
1002
        // $this->assertSame('Dummy Name', $actual->getName());
1003
    }
1004

1005
    public function testDenormalizeWritableLinks(): void
1006
    {
1007
        $data = [
×
1008
            'name' => 'foo',
×
1009
            'relatedDummy' => ['foo' => 'bar'],
×
1010
            'relatedDummies' => [['bar' => 'baz']],
×
1011
            'relatedDummiesWithUnionTypes' => [0 => ['bar' => 'qux'], 1. => ['bar' => 'quux']],
×
1012
        ];
×
1013

1014
        $relatedDummy1 = new RelatedDummy();
×
1015
        $relatedDummy2 = new RelatedDummy();
×
1016
        $relatedDummy3 = new RelatedDummy();
×
1017
        $relatedDummy4 = new RelatedDummy();
×
1018

1019
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1020
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['name', 'relatedDummy', 'relatedDummies', 'relatedDummiesWithUnionTypes']));
×
1021

1022
        // BC layer for api-platform/metadata < 4.1
1023
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1024
            $relatedDummyType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class);
×
1025
            $relatedDummiesType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $relatedDummyType);
×
1026
            $relatedDummiesWithUnionTypesIntType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $relatedDummyType);
×
1027
            $relatedDummiesWithUnionTypesFloatType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT), $relatedDummyType);
×
1028

1029
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1030
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
1031
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummyType])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1032
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummiesType])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1033
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummiesWithUnionTypes', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummiesWithUnionTypesIntType, $relatedDummiesWithUnionTypesFloatType])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1034
        } else {
1035
            $relatedDummyType = Type::object(RelatedDummy::class);
×
1036
            $relatedDummiesType = Type::collection(Type::object(ArrayCollection::class), $relatedDummyType, Type::int());
×
1037
            $relatedDummiesWithUnionTypesIntType = Type::collection(Type::object(ArrayCollection::class), $relatedDummyType, Type::int());
×
1038
            $relatedDummiesWithUnionTypesFloatType = Type::collection(Type::object(ArrayCollection::class), $relatedDummyType, Type::float());
×
1039

1040
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1041
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
1042
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withNativeType($relatedDummyType)->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1043
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withNativeType($relatedDummiesType)->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1044
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummiesWithUnionTypes', [])->willReturn((new ApiProperty())->withNativeType(Type::union($relatedDummiesWithUnionTypesIntType, $relatedDummiesWithUnionTypesFloatType))->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1045
        }
1046

1047
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1048

1049
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1050

1051
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1052
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1053
        $resourceClassResolverProphecy->getResourceClass(null, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1054
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1055
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
1056
        $resourceClassResolverProphecy->isResourceClass(ArrayCollection::class)->willReturn(false);
×
1057

1058
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1059
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1060
        $serializerProphecy->denormalize(['foo' => 'bar'], RelatedDummy::class, null, Argument::type('array'))->willReturn($relatedDummy1);
×
1061
        $serializerProphecy->denormalize(['bar' => 'baz'], RelatedDummy::class, null, Argument::type('array'))->willReturn($relatedDummy2);
×
1062
        $serializerProphecy->denormalize(['bar' => 'qux'], RelatedDummy::class, null, Argument::type('array'))->willReturn($relatedDummy3);
×
1063
        $serializerProphecy->denormalize(['bar' => 'quux'], RelatedDummy::class, null, Argument::type('array'))->willReturn($relatedDummy4);
×
1064

1065
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1066
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1067

1068
        $actual = $normalizer->denormalize($data, Dummy::class);
×
1069

1070
        $this->assertInstanceOf(Dummy::class, $actual);
×
1071

1072
        $propertyAccessorProphecy->setValue($actual, 'name', 'foo')->shouldHaveBeenCalled();
×
1073
        $propertyAccessorProphecy->setValue($actual, 'relatedDummy', $relatedDummy1)->shouldHaveBeenCalled();
×
1074
        $propertyAccessorProphecy->setValue($actual, 'relatedDummies', [$relatedDummy2])->shouldHaveBeenCalled();
×
1075
        $propertyAccessorProphecy->setValue($actual, 'relatedDummiesWithUnionTypes', [0 => $relatedDummy3, 1. => $relatedDummy4])->shouldHaveBeenCalled();
×
1076
    }
1077

1078
    public function testBadRelationType(): void
1079
    {
1080
        $this->expectException(NotNormalizableValueException::class);
×
1081
        $this->expectExceptionMessage('The type of the "relatedDummy" attribute must be "array" (nested document) or "string" (IRI), "integer" given.');
×
1082

1083
        $data = [
×
1084
            'relatedDummy' => 22,
×
1085
        ];
×
1086

1087
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1088
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['relatedDummy']));
×
1089

1090
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1091

1092
        // BC layer for api-platform/metadata < 4.1
1093
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1094
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn(
×
1095
                (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class)])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false)
×
1096
            );
×
1097
        } else {
1098
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn(
×
1099
                (new ApiProperty())->withNativeType(Type::object(RelatedDummy::class))->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false)
×
1100
            );
×
1101
        }
1102

1103
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1104

1105
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1106
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1107
        $resourceClassResolverProphecy->getResourceClass(null, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1108
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1109
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
1110

1111
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1112

1113
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1114
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1115

1116
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1117
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1118

1119
        $normalizer->denormalize($data, Dummy::class);
×
1120
    }
1121

1122
    public function testBadRelationTypeWithExceptionToValidationErrors(): void
1123
    {
1124
        $data = [
×
1125
            'relatedDummy' => 22,
×
1126
        ];
×
1127

1128
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1129
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['relatedDummy']));
×
1130

1131
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1132

1133
        // BC layer for api-platform/metadata < 4.1
1134
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1135
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn(
×
1136
                (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class)])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false)
×
1137
            );
×
1138
        } else {
1139
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn(
×
1140
                (new ApiProperty())->withNativeType(Type::object(RelatedDummy::class))->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false)
×
1141
            );
×
1142
        }
1143

1144
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1145

1146
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1147
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1148
        $resourceClassResolverProphecy->getResourceClass(null, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1149
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1150
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
1151

1152
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1153

1154
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1155
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1156

1157
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1158
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1159

1160
        // 'not_normalizable_value_exceptions' is set by Serializer thanks to DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS
1161
        $actual = $normalizer->denormalize($data, Dummy::class, null, ['not_normalizable_value_exceptions' => []]);
×
1162
        $this->assertNull($actual->relatedDummy);
×
1163
    }
1164

1165
    public function testDeserializationPathForNotDenormalizableRelations(): void
1166
    {
1167
        $data = [
×
1168
            'relatedDummies' => ['wrong'],
×
1169
        ];
×
1170

1171
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1172
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['relatedDummies']));
×
1173

1174
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1175

1176
        // BC layer for api-platform/metadata < 4.1
1177
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1178
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn(
×
1179
                (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, null, new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class))])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true)
×
1180
            );
×
1181
        } else {
1182
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn(
×
1183
                (new ApiProperty())->withNativeType(Type::collection(Type::object(ArrayCollection::class), Type::object(RelatedDummy::class)))->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true)
×
1184
            );
×
1185
        }
1186

1187
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1188
        $iriConverterProphecy->getResourceFromIri(Argument::cetera())->willThrow(new InvalidArgumentException('Invalid IRI'));
×
1189

1190
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1191
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1192
        $resourceClassResolverProphecy->getResourceClass(null, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1193
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1194
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
1195

1196
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1197

1198
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1199
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1200

1201
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1202
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1203

1204
        $errors = [];
×
1205
        $actual = $normalizer->denormalize($data, Dummy::class, null, ['not_normalizable_value_exceptions' => &$errors]);
×
1206
        $this->assertEmpty($actual->relatedDummies);
×
NEW
1207
        $this->assertCount(1, $errors);
×
1208
        $this->assertInstanceOf(NotNormalizableValueException::class, $errors[0]);
×
1209
        $this->assertSame('relatedDummies[0]', $errors[0]->getPath());
×
1210
        $this->assertSame('Invalid IRI "wrong".', $errors[0]->getMessage());
×
1211
    }
1212

1213
    public function testDeserializationPathForNotDenormalizableResource(): void
1214
    {
1215
        $this->expectException(NotNormalizableValueException::class);
×
1216
        $this->expectExceptionMessage('Invalid IRI "wrong IRI".');
×
1217

1218
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1219

1220
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1221

1222
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1223
        $iriConverterProphecy->getResourceFromIri(Argument::cetera())->willThrow(new InvalidArgumentException('Invalid IRI'));
×
1224

1225
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1226
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1227
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1228

1229
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1230

1231
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1232
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1233

1234
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1235
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1236

1237
        $normalizer->denormalize('wrong IRI', Dummy::class, null, ['not_normalizable_value_exceptions' => []]);
×
1238
    }
1239

1240
    public function testDeserializationPathForNotFoundResource(): void
1241
    {
1242
        $this->expectException(NotNormalizableValueException::class);
×
1243
        $this->expectExceptionMessage('Some item not found exception.');
×
1244

1245
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1246

1247
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1248

1249
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1250
        $iriConverterProphecy->getResourceFromIri(Argument::cetera())->willThrow(new ItemNotFoundException('Some item not found exception.'));
×
1251

1252
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1253
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1254
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1255

1256
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1257

1258
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1259
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1260

1261
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1262
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1263

1264
        $normalizer->denormalize('/some-iri', Dummy::class, null, ['not_normalizable_value_exceptions' => []]);
×
1265
    }
1266

1267
    public function testInnerDocumentNotAllowed(): void
1268
    {
1269
        $this->expectException(UnexpectedValueException::class);
×
1270
        $this->expectExceptionMessage('Nested documents for attribute "relatedDummy" are not allowed. Use IRIs instead.');
×
1271

1272
        $data = [
×
1273
            'relatedDummy' => [
×
1274
                'foo' => 'bar',
×
1275
            ],
×
1276
        ];
×
1277

1278
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1279
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['relatedDummy']));
×
1280

1281
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1282

1283
        // BC layer for api-platform/metadata < 4.1
1284
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1285
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn(
×
1286
                (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class)])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false)
×
1287
            );
×
1288
        } else {
1289
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn(
×
1290
                (new ApiProperty())->withNativeType(Type::object(RelatedDummy::class))->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false)
×
1291
            );
×
1292
        }
1293

1294
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1295

1296
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1297
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1298
        $resourceClassResolverProphecy->getResourceClass(null, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1299
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
1300
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1301

1302
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1303

1304
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1305
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1306

1307
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1308
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1309

1310
        $normalizer->denormalize($data, Dummy::class);
×
1311
    }
1312

1313
    public function testBadType(): void
1314
    {
1315
        $this->expectException(UnexpectedValueException::class);
×
1316
        $this->expectExceptionMessage('The type of the "foo" attribute must be "float", "integer" given.');
×
1317

1318
        $data = [
×
1319
            'foo' => 42,
×
1320
        ];
×
1321

1322
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1323
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['foo']));
×
1324

1325
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1326

1327
        // BC layer for api-platform/metadata < 4.1
1328
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1329
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'foo', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1330
        } else {
1331
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'foo', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1332
        }
1333

1334
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1335

1336
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1337
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1338
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1339

1340
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1341

1342
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1343
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1344

1345
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1346
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1347

1348
        $normalizer->denormalize($data, Dummy::class);
×
1349
    }
1350

1351
    public function testTypeChecksCanBeDisabled(): void
1352
    {
1353
        $data = [
×
1354
            'foo' => 42,
×
1355
        ];
×
1356

1357
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1358
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['foo']));
×
1359

1360
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1361

1362
        // BC layer for api-platform/metadata < 4.1
1363
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1364
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'foo', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1365
        } else {
1366
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'foo', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1367
        }
1368

1369
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1370

1371
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1372
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1373
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1374

1375
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1376

1377
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1378
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1379

1380
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1381
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1382

1383
        $actual = $normalizer->denormalize($data, Dummy::class, null, ['disable_type_enforcement' => true]);
×
1384

1385
        $this->assertInstanceOf(Dummy::class, $actual);
×
1386

1387
        $propertyAccessorProphecy->setValue($actual, 'foo', 42)->shouldHaveBeenCalled();
×
1388
    }
1389

1390
    public function testJsonAllowIntAsFloat(): void
1391
    {
1392
        $data = [
×
1393
            'foo' => 42,
×
1394
        ];
×
1395

1396
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1397
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['foo']));
×
1398

1399
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1400

1401
        // BC layer for api-platform/metadata < 4.1
1402
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1403
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'foo', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1404
        } else {
1405
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'foo', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1406
        }
1407

1408
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1409

1410
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1411
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1412
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1413

1414
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1415

1416
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1417
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1418

1419
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1420
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1421

1422
        $actual = $normalizer->denormalize($data, Dummy::class, 'jsonfoo');
×
1423

1424
        $this->assertInstanceOf(Dummy::class, $actual);
×
1425

1426
        $propertyAccessorProphecy->setValue($actual, 'foo', 42)->shouldHaveBeenCalled();
×
1427
    }
1428

1429
    public function testDenormalizeBadKeyType(): void
1430
    {
1431
        $this->expectException(NotNormalizableValueException::class);
×
1432
        $this->expectExceptionMessage('The type of the key "a" must be "int", "string" given.');
×
1433

1434
        $data = [
×
1435
            'name' => 'foo',
×
1436
            'relatedDummy' => [
×
1437
                'foo' => 'bar',
×
1438
            ],
×
1439
            'relatedDummies' => [
×
1440
                'a' => [
×
1441
                    'bar' => 'baz',
×
1442
                ],
×
1443
            ],
×
1444
            'relatedDummiesWithUnionTypes' => [
×
1445
                'a' => [
×
1446
                    'bar' => 'baz',
×
1447
                ],
×
1448
            ],
×
1449
        ];
×
1450

1451
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1452
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['relatedDummies']));
×
1453

1454
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1455

1456
        // BC layer for api-platform/metadata < 4.1
1457
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1458
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
1459
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class)])->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1460

1461
            $type = new LegacyType(
×
1462
                LegacyType::BUILTIN_TYPE_OBJECT,
×
1463
                false,
×
1464
                ArrayCollection::class,
×
1465
                true,
×
1466
                new LegacyType(LegacyType::BUILTIN_TYPE_INT),
×
1467
                new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class)
×
1468
            );
×
1469
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withBuiltinTypes([$type])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1470
        } else {
1471
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
1472
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', [])->willReturn((new ApiProperty())->withNativeType(Type::object(RelatedDummy::class))->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1473

1474
            $type = Type::collection(Type::object(ArrayCollection::class), Type::object(RelatedDummy::class), Type::int());
×
1475
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withNativeType($type)->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1476
        }
1477

1478
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1479

1480
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1481
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1482
        $resourceClassResolverProphecy->getResourceClass(null, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1483
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1484
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
1485

1486
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1487

1488
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1489
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1490

1491
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1492
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1493

1494
        $normalizer->denormalize($data, Dummy::class);
×
1495
    }
1496

1497
    public function testNullable(): void
1498
    {
1499
        $data = [
×
1500
            'name' => null,
×
1501
        ];
×
1502

1503
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1504
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['name']));
×
1505

1506
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1507

1508
        // BC layer for api-platform/metadata < 4.1
1509
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1510
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING, true)])->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1511
        } else {
1512
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn((new ApiProperty())->withNativeType(Type::nullable(Type::string()))->withDescription('')->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(false));
×
1513
        }
1514

1515
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1516

1517
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1518
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1519
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1520

1521
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1522

1523
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1524
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1525

1526
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1527
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1528

1529
        $actual = $normalizer->denormalize($data, Dummy::class);
×
1530

1531
        $this->assertInstanceOf(Dummy::class, $actual);
×
1532

1533
        $propertyAccessorProphecy->setValue($actual, 'name', null)->shouldHaveBeenCalled();
×
1534
    }
1535

1536
    public function testDenormalizeBasicTypePropertiesFromXml(): void
1537
    {
1538
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1539
        $propertyNameCollectionFactoryProphecy->create(ObjectWithBasicProperties::class, [])->willReturn(new PropertyNameCollection([
×
1540
            'boolTrue1',
×
1541
            'boolFalse1',
×
1542
            'boolTrue2',
×
1543
            'boolFalse2',
×
1544
            'int1',
×
1545
            'int2',
×
1546
            'float1',
×
1547
            'float2',
×
1548
            'float3',
×
1549
            'floatNaN',
×
1550
            'floatInf',
×
1551
            'floatNegInf',
×
1552
        ]));
×
1553

1554
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1555

1556
        // BC layer for api-platform/metadata < 4.1
1557
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1558
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'boolTrue1', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_BOOL)])->withDescription('')->withReadable(false)->withWritable(true));
×
1559
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'boolFalse1', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_BOOL)])->withDescription('')->withReadable(false)->withWritable(true));
×
1560
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'boolTrue2', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_BOOL)])->withDescription('')->withReadable(false)->withWritable(true));
×
1561
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'boolFalse2', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_BOOL)])->withDescription('')->withReadable(false)->withWritable(true));
×
1562
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'int1', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)])->withDescription('')->withReadable(false)->withWritable(true));
×
1563
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'int2', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)])->withDescription('')->withReadable(false)->withWritable(true));
×
1564
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'float1', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true));
×
1565
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'float2', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true));
×
1566
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'float3', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true));
×
1567
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'floatNaN', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true));
×
1568
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'floatInf', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true));
×
1569
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'floatNegInf', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)])->withDescription('')->withReadable(false)->withWritable(true));
×
1570
        } else {
1571
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'boolTrue1', [])->willReturn((new ApiProperty())->withNativeType(Type::bool())->withDescription('')->withReadable(false)->withWritable(true));
×
1572
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'boolFalse1', [])->willReturn((new ApiProperty())->withNativeType(Type::bool())->withDescription('')->withReadable(false)->withWritable(true));
×
1573
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'boolTrue2', [])->willReturn((new ApiProperty())->withNativeType(Type::bool())->withDescription('')->withReadable(false)->withWritable(true));
×
1574
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'boolFalse2', [])->willReturn((new ApiProperty())->withNativeType(Type::bool())->withDescription('')->withReadable(false)->withWritable(true));
×
1575
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'int1', [])->willReturn((new ApiProperty())->withNativeType(Type::int())->withDescription('')->withReadable(false)->withWritable(true));
×
1576
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'int2', [])->willReturn((new ApiProperty())->withNativeType(Type::int())->withDescription('')->withReadable(false)->withWritable(true));
×
1577
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'float1', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true));
×
1578
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'float2', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true));
×
1579
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'float3', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true));
×
1580
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'floatNaN', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true));
×
1581
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'floatInf', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true));
×
1582
            $propertyMetadataFactoryProphecy->create(ObjectWithBasicProperties::class, 'floatNegInf', [])->willReturn((new ApiProperty())->withNativeType(Type::float())->withDescription('')->withReadable(false)->withWritable(true));
×
1583
        }
1584

1585
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1586

1587
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1588
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'boolTrue1', true)->shouldBeCalled();
×
1589
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'boolFalse1', false)->shouldBeCalled();
×
1590
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'boolTrue2', true)->shouldBeCalled();
×
1591
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'boolFalse2', false)->shouldBeCalled();
×
1592
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'int1', 4711)->shouldBeCalled();
×
1593
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'int2', -4711)->shouldBeCalled();
×
1594
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'float1', Argument::approximate(123.456, 0))->shouldBeCalled();
×
1595
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'float2', Argument::approximate(-1.2344e56, 1))->shouldBeCalled();
×
1596
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'float3', Argument::approximate(45E-6, 1))->shouldBeCalled();
×
1597
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'floatNaN', Argument::that(static fn (float $arg) => is_nan($arg)))->shouldBeCalled();
×
1598
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'floatInf', \INF)->shouldBeCalled();
×
1599
        $propertyAccessorProphecy->setValue(Argument::type(ObjectWithBasicProperties::class), 'floatNegInf', -\INF)->shouldBeCalled();
×
1600

1601
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1602
        $resourceClassResolverProphecy->getResourceClass(null, ObjectWithBasicProperties::class)->willReturn(ObjectWithBasicProperties::class);
×
1603
        $resourceClassResolverProphecy->isResourceClass(ObjectWithBasicProperties::class)->willReturn(true);
×
1604

1605
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1606
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
1607

1608
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1609
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1610

1611
        $objectWithBasicProperties = $normalizer->denormalize(
×
1612
            [
×
1613
                'boolTrue1' => 'true',
×
1614
                'boolFalse1' => 'false',
×
1615
                'boolTrue2' => '1',
×
1616
                'boolFalse2' => '0',
×
1617
                'int1' => '4711',
×
1618
                'int2' => '-4711',
×
1619
                'float1' => '123.456',
×
1620
                'float2' => '-1.2344e56',
×
1621
                'float3' => '45E-6',
×
1622
                'floatNaN' => 'NaN',
×
1623
                'floatInf' => 'INF',
×
1624
                'floatNegInf' => '-INF',
×
1625
            ],
×
1626
            ObjectWithBasicProperties::class,
×
1627
            'xml'
×
1628
        );
×
1629

1630
        $this->assertInstanceOf(ObjectWithBasicProperties::class, $objectWithBasicProperties);
×
1631
    }
1632

1633
    public function testDenormalizeCollectionDecodedFromXmlWithOneChild(): void
1634
    {
1635
        $data = [
×
1636
            'relatedDummies' => [
×
1637
                'name' => 'foo',
×
1638
            ],
×
1639
        ];
×
1640

1641
        $relatedDummy = new RelatedDummy();
×
1642
        $relatedDummy->setName('foo');
×
1643

1644
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1645
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['relatedDummies']));
×
1646

1647
        // BC layer for api-platform/metadata < 4.1
1648
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1649
            $relatedDummyType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class);
×
1650
            $relatedDummiesType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $relatedDummyType);
×
1651

1652
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1653
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummiesType])->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1654
        } else {
1655
            $relatedDummyType = Type::object(RelatedDummy::class);
×
1656
            $relatedDummiesType = Type::collection(Type::object(ArrayCollection::class), $relatedDummyType, Type::int());
×
1657

1658
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1659
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', [])->willReturn((new ApiProperty())->withNativeType($relatedDummiesType)->withReadable(false)->withWritable(true)->withReadableLink(false)->withWritableLink(true));
×
1660
        }
1661

1662
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1663

1664
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1665
        $propertyAccessorProphecy->setValue(Argument::type(Dummy::class), 'relatedDummies', Argument::type('array'))->shouldBeCalled();
×
1666

1667
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1668
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1669
        $resourceClassResolverProphecy->getResourceClass(null, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1670
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
1671
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1672

1673
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1674
        $serializerProphecy->willImplement(DenormalizerInterface::class);
×
1675
        $serializerProphecy->denormalize(['name' => 'foo'], RelatedDummy::class, 'xml', Argument::type('array'))->willReturn($relatedDummy);
×
1676

1677
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1678
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1679

1680
        $normalizer->denormalize($data, Dummy::class, 'xml');
×
1681
    }
1682

1683
    public function testDenormalizePopulatingNonCloneableObject(): void
1684
    {
1685
        $dummy = new NonCloneableDummy();
×
1686
        $dummy->setName('foo');
×
1687

1688
        $data = [
×
1689
            'name' => 'bar',
×
1690
        ];
×
1691

1692
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1693
        $propertyNameCollectionFactoryProphecy->create(NonCloneableDummy::class, [])->willReturn(new PropertyNameCollection(['name']));
×
1694

1695
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1696

1697
        // BC layer for api-platform/metadata < 4.1
1698
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1699
            $propertyMetadataFactoryProphecy->create(NonCloneableDummy::class, 'name', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(false)->withWritable(true));
×
1700
        } else {
1701
            $propertyMetadataFactoryProphecy->create(NonCloneableDummy::class, 'name', [])->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(false)->withWritable(true));
×
1702
        }
1703

1704
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1705
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1706
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1707
        $resourceClassResolverProphecy->getResourceClass(null, NonCloneableDummy::class)->willReturn(NonCloneableDummy::class);
×
1708
        $resourceClassResolverProphecy->getResourceClass($dummy, NonCloneableDummy::class)->willReturn(NonCloneableDummy::class);
×
1709
        $resourceClassResolverProphecy->isResourceClass(NonCloneableDummy::class)->willReturn(true);
×
1710

1711
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1712
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
1713

1714
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1715
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1716
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1717

1718
        $context = [AbstractItemNormalizer::OBJECT_TO_POPULATE => $dummy];
×
1719
        $actual = $normalizer->denormalize($data, NonCloneableDummy::class, null, $context);
×
1720

1721
        $this->assertInstanceOf(NonCloneableDummy::class, $actual);
×
1722
        $this->assertSame($dummy, $actual);
×
1723
        $propertyAccessorProphecy->setValue($actual, 'name', 'bar')->shouldHaveBeenCalled();
×
1724
    }
1725

1726
    public function testDenormalizeObjectWithNullDisabledTypeEnforcement(): void
1727
    {
1728
        $data = [
×
1729
            'dummy' => null,
×
1730
        ];
×
1731

1732
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1733
        $propertyNameCollectionFactoryProphecy->create(DtoWithNullValue::class, [])->willReturn(new PropertyNameCollection(['dummy']));
×
1734

1735
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1736

1737
        // BC layer for api-platform/metadata < 4.1
1738
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1739
            $propertyMetadataFactoryProphecy->create(DtoWithNullValue::class, 'dummy', [])->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, nullable: true)])->withDescription('')->withReadable(true)->withWritable(true));
×
1740
        } else {
1741
            $propertyMetadataFactoryProphecy->create(DtoWithNullValue::class, 'dummy', [])->willReturn((new ApiProperty())->withNativeType(Type::nullable(Type::object()))->withDescription('')->withReadable(true)->withWritable(true));
×
1742
        }
1743

1744
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1745
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1746
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1747
        $resourceClassResolverProphecy->getResourceClass(null, DtoWithNullValue::class)->willReturn(DtoWithNullValue::class);
×
1748
        $resourceClassResolverProphecy->isResourceClass(DtoWithNullValue::class)->willReturn(true);
×
1749

1750
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1751
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
1752

1753
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1754
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1755

1756
        $context = [AbstractItemNormalizer::DISABLE_TYPE_ENFORCEMENT => true];
×
1757
        $actual = $normalizer->denormalize($data, DtoWithNullValue::class, null, $context);
×
1758

1759
        $this->assertInstanceOf(DtoWithNullValue::class, $actual);
×
1760
        $this->assertEquals(new DtoWithNullValue(), $actual);
×
1761
    }
1762

1763
    public function testCacheKey(): void
1764
    {
1765
        $relatedDummy = new RelatedDummy();
×
1766

1767
        $dummy = new Dummy();
×
1768
        $dummy->setName('foo');
×
1769
        $dummy->setAlias('ignored');
×
1770
        $dummy->setRelatedDummy($relatedDummy);
×
1771
        $dummy->relatedDummies->add(new RelatedDummy());
×
1772

1773
        $relatedDummies = new ArrayCollection([$relatedDummy]);
×
1774

1775
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
1776
        $propertyNameCollectionFactoryProphecy->create(Dummy::class, Argument::type('array'))->willReturn(new PropertyNameCollection(['name', 'alias', 'relatedDummy', 'relatedDummies']));
×
1777

1778
        // BC layer for api-platform/metadata < 4.1
1779
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
×
1780
            $relatedDummyType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class);
×
1781
            $relatedDummiesType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, ArrayCollection::class, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $relatedDummyType);
×
1782

1783
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1784
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', Argument::type('array'))->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true));
×
1785
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'alias', Argument::type('array'))->willReturn((new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)])->withDescription('')->withReadable(true));
×
1786
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', Argument::type('array'))->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummyType])->withDescription('')->withReadable(true)->withWritable(false)->withReadableLink(false));
×
1787
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', Argument::type('array'))->willReturn((new ApiProperty())->withBuiltinTypes([$relatedDummiesType])->withReadable(true)->withWritable(false)->withReadableLink(false));
×
1788
        } else {
1789
            $relatedDummyType = Type::object(RelatedDummy::class);
×
1790
            $relatedDummiesType = Type::collection(Type::object(ArrayCollection::class), $relatedDummyType, Type::int());
×
1791

1792
            $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
1793
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'name', Argument::type('array'))->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true));
×
1794
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'alias', Argument::type('array'))->willReturn((new ApiProperty())->withNativeType(Type::string())->withDescription('')->withReadable(true));
×
1795
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy', Argument::type('array'))->willReturn((new ApiProperty())->withNativeType($relatedDummyType)->withDescription('')->withReadable(true)->withWritable(false)->withReadableLink(false));
×
1796
            $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', Argument::type('array'))->willReturn((new ApiProperty())->withNativeType($relatedDummiesType)->withReadable(true)->withWritable(false)->withReadableLink(false));
×
1797
        }
1798

1799
        $iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
×
1800
        $iriConverterProphecy->getIriFromResource($dummy, Argument::cetera())->willReturn('/dummies/1');
×
1801
        $iriConverterProphecy->getIriFromResource($relatedDummy, Argument::cetera())->willReturn('/dummies/2');
×
1802

1803
        $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
×
1804
        $propertyAccessorProphecy->getValue($dummy, 'name')->willReturn('foo');
×
1805
        $propertyAccessorProphecy->getValue($dummy, 'relatedDummy')->willReturn($relatedDummy);
×
1806
        $propertyAccessorProphecy->getValue($dummy, 'relatedDummies')->willReturn($relatedDummies);
×
1807

1808
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
1809
        $resourceClassResolverProphecy->getResourceClass(null, Dummy::class)->willReturn(Dummy::class);
×
1810
        $resourceClassResolverProphecy->getResourceClass($dummy, null)->willReturn(Dummy::class);
×
1811
        $resourceClassResolverProphecy->getResourceClass($relatedDummy, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1812
        $resourceClassResolverProphecy->getResourceClass($relatedDummies, RelatedDummy::class)->willReturn(RelatedDummy::class);
×
1813
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
1814
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
1815

1816
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
×
1817
        $serializerProphecy->willImplement(NormalizerInterface::class);
×
1818
        $serializerProphecy->normalize('foo', null, Argument::type('array'))->willReturn('foo');
×
1819
        $serializerProphecy->normalize(['/dummies/2'], null, Argument::type('array'))->willReturn(['/dummies/2']);
×
1820

1821
        $normalizer = new class($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal(), null, null, [], null, null) extends AbstractItemNormalizer {};
×
1822
        $normalizer->setSerializer($serializerProphecy->reveal());
×
1823

1824
        $expected = [
×
1825
            'name' => 'foo',
×
1826
            'relatedDummy' => '/dummies/2',
×
1827
            'relatedDummies' => ['/dummies/2'],
×
1828
        ];
×
1829
        $this->assertSame($expected, $normalizer->normalize($dummy, null, [
×
1830
            'resources' => [],
×
1831
            'groups' => ['group'],
×
1832
            'ignored_attributes' => ['alias'],
×
1833
            'operation_name' => 'operation_name',
×
1834
            'root_operation_name' => 'root_operation_name',
×
1835
        ]));
×
1836

1837
        $operationCacheKey = (new \ReflectionClass($normalizer))->getProperty('localFactoryOptionsCache')->getValue($normalizer);
×
1838
        $this->assertEquals(array_keys($operationCacheKey), [\sprintf('%s%s%s%s', Dummy::class, 'operation_name', 'root_operation_name', 'n')]);
×
1839
        $this->assertEquals(current($operationCacheKey), ['serializer_groups' => ['group']]);
×
1840
    }
1841
}
1842

1843
class ObjectWithBasicProperties
1844
{
1845
    /** @var bool */
1846
    public $boolTrue1;
1847

1848
    /** @var bool */
1849
    public $boolFalse1;
1850

1851
    /** @var bool */
1852
    public $boolTrue2;
1853

1854
    /** @var bool */
1855
    public $boolFalse2;
1856

1857
    /** @var int */
1858
    public $int1;
1859

1860
    /** @var int */
1861
    public $int2;
1862

1863
    /** @var float */
1864
    public $float1;
1865

1866
    /** @var float */
1867
    public $float2;
1868

1869
    /** @var float */
1870
    public $float3;
1871

1872
    /** @var float */
1873
    public $floatNaN;
1874

1875
    /** @var float */
1876
    public $floatInf;
1877

1878
    /** @var float */
1879
    public $floatNegInf;
1880
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc