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

api-platform / core / 18089937549

29 Sep 2025 07:56AM UTC coverage: 21.764% (-0.3%) from 22.093%
18089937549

Pull #7416

github

web-flow
Merge 061bcc790 into abe0438be
Pull Request #7416: fix(laravel): serializer attributes on Eloquent methods

0 of 151 new or added lines in 11 files covered. (0.0%)

5028 existing lines in 173 files now uncovered.

11889 of 54626 relevant lines covered (21.76%)

25.32 hits per line

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

0.0
/src/GraphQl/Tests/Type/TypeConverterTest.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\GraphQl\Tests\Type;
15

16
use ApiPlatform\GraphQl\Tests\Fixtures\Enum\GenderTypeEnum;
17
use ApiPlatform\GraphQl\Tests\Fixtures\Type\Definition\DateTimeType;
18
use ApiPlatform\GraphQl\Type\ContextAwareTypeBuilderInterface;
19
use ApiPlatform\GraphQl\Type\TypeConverter;
20
use ApiPlatform\GraphQl\Type\TypesContainerInterface;
21
use ApiPlatform\Metadata\ApiProperty;
22
use ApiPlatform\Metadata\ApiResource;
23
use ApiPlatform\Metadata\Exception\ResourceClassNotFoundException;
24
use ApiPlatform\Metadata\GraphQl\Operation;
25
use ApiPlatform\Metadata\GraphQl\Query;
26
use ApiPlatform\Metadata\GraphQl\QueryCollection;
27
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
28
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
29
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
30
use GraphQL\Type\Definition\EnumType;
31
use GraphQL\Type\Definition\ObjectType;
32
use GraphQL\Type\Definition\Type as GraphQLType;
33
use PHPUnit\Framework\Attributes\DataProvider;
34
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
35
use PHPUnit\Framework\TestCase;
36
use Prophecy\Argument;
37
use Prophecy\PhpUnit\ProphecyTrait;
38
use Prophecy\Prophecy\ObjectProphecy;
39
use Symfony\Component\PropertyInfo\Type as LegacyType;
40
use Symfony\Component\TypeInfo\Type;
41

42
/**
43
 * @author Alan Poulain <contact@alanpoulain.eu>
44
 */
45
class TypeConverterTest extends TestCase
46
{
47
    use ProphecyTrait;
48

49
    private ObjectProphecy $typeBuilderProphecy;
50
    private ObjectProphecy $typesContainerProphecy;
51
    private ObjectProphecy $resourceMetadataCollectionFactoryProphecy;
52
    private ObjectProphecy $propertyMetadataFactoryProphecy;
53
    private TypeConverter $typeConverter;
54

55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function setUp(): void
59
    {
60
        $this->typeBuilderProphecy = $this->prophesize(ContextAwareTypeBuilderInterface::class);
×
61
        $this->typesContainerProphecy = $this->prophesize(TypesContainerInterface::class);
×
UNCOV
62
        $this->resourceMetadataCollectionFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
UNCOV
63
        $this->propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
UNCOV
64
        $this->typeConverter = new TypeConverter($this->typeBuilderProphecy->reveal(), $this->typesContainerProphecy->reveal(), $this->resourceMetadataCollectionFactoryProphecy->reveal(), $this->propertyMetadataFactoryProphecy->reveal());
×
65
    }
66

67
    #[DataProvider('legacyConvertTypeProvider')]
68
    #[IgnoreDeprecations]
69
    public function testConvertTypeLegacy(LegacyType $type, bool $input, int $depth, GraphQLType|string|null $expectedGraphqlType): void
70
    {
UNCOV
71
        $this->expectUserDeprecationMessage('Since api-platform/graphql 4.2: The "ApiPlatform\GraphQl\Type\TypeConverter::convertType()" method is deprecated, use "ApiPlatform\GraphQl\Type\TypeConverter::convertPhpType()" instead.');
×
72

73
        $this->typeBuilderProphecy->isCollection($type)->willReturn(false);
×
74
        $this->resourceMetadataCollectionFactoryProphecy->create(Argument::type('string'))->willReturn(new ResourceMetadataCollection('resourceClass'));
×
UNCOV
75
        $this->typeBuilderProphecy->getEnumType(Argument::type(Operation::class))->willReturn($expectedGraphqlType);
×
76

UNCOV
77
        $operation = (new Query())->withName('test');
×
UNCOV
78
        $graphqlType = $this->typeConverter->convertType($type, $input, $operation, 'resourceClass', 'rootClass', null, $depth);
×
79
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
80
    }
81

82
    public static function legacyConvertTypeProvider(): array
83
    {
84
        return [
×
85
            [new LegacyType(LegacyType::BUILTIN_TYPE_BOOL), false, 0, GraphQLType::boolean()],
×
86
            [new LegacyType(LegacyType::BUILTIN_TYPE_INT), false, 0, GraphQLType::int()],
×
87
            [new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT), false, 0, GraphQLType::float()],
×
88
            [new LegacyType(LegacyType::BUILTIN_TYPE_STRING), false, 0, GraphQLType::string()],
×
89
            [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY), false, 0, 'Iterable'],
×
90
            [new LegacyType(LegacyType::BUILTIN_TYPE_ITERABLE), false, 0, 'Iterable'],
×
91
            [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, \DateTimeInterface::class), false, 0, GraphQLType::string()],
×
92
            [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, GenderTypeEnum::class), false, 0, new EnumType(['name' => 'GenderTypeEnum', 'values' => []])],
×
UNCOV
93
            [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT), false, 0, null],
×
UNCOV
94
            [new LegacyType(LegacyType::BUILTIN_TYPE_CALLABLE), false, 0, null],
×
UNCOV
95
            [new LegacyType(LegacyType::BUILTIN_TYPE_NULL), false, 0, null],
×
UNCOV
96
            [new LegacyType(LegacyType::BUILTIN_TYPE_RESOURCE), false, 0, null],
×
97
        ];
×
98
    }
99

100
    #[DataProvider('convertTypeProvider')]
101
    public function testConvertType(Type $type, bool $input, int $depth, GraphQLType|string|null $expectedGraphqlType): void
102
    {
103
        $this->resourceMetadataCollectionFactoryProphecy->create(Argument::type('string'))->willReturn(new ResourceMetadataCollection('resourceClass'));
×
104
        $this->typeBuilderProphecy->getEnumType(Argument::type(Operation::class))->willReturn($expectedGraphqlType);
×
105

UNCOV
106
        $operation = (new Query())->withName('test');
×
UNCOV
107
        $graphqlType = $this->typeConverter->convertPhpType($type, $input, $operation, 'resourceClass', 'rootClass', null, $depth);
×
UNCOV
108
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
109
    }
110

111
    public static function convertTypeProvider(): array
112
    {
113
        return [
×
UNCOV
114
            [Type::bool(), false, 0, GraphQLType::boolean()],
×
115
            [Type::int(), false, 0, GraphQLType::int()],
×
116
            [Type::float(), false, 0, GraphQLType::float()],
×
UNCOV
117
            [Type::string(), false, 0, GraphQLType::string()],
×
UNCOV
118
            [Type::array(), false, 0, 'Iterable'],
×
119
            [Type::iterable(), false, 0, 'Iterable'],
×
120
            [Type::object(\DateTimeInterface::class), false, 0, GraphQLType::string()],
×
UNCOV
121
            [Type::object(GenderTypeEnum::class), false, 0, new EnumType(['name' => 'GenderTypeEnum', 'values' => []])],
×
UNCOV
122
            [Type::object(), false, 0, null],
×
UNCOV
123
            [Type::callable(), false, 0, null],
×
UNCOV
124
            [Type::null(), false, 0, null],
×
125
            [Type::resource(), false, 0, null],
×
UNCOV
126
        ];
×
127
    }
128

129
    #[IgnoreDeprecations]
130
    public function testConvertTypeNoGraphQlResourceMetadataLegacy(): void
131
    {
132
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummy');
×
133

UNCOV
134
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(false);
×
UNCOV
135
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('dummy', [new ApiResource()]));
×
136

UNCOV
137
        $operation = (new Query())->withName('test');
×
138
        $graphqlType = $this->typeConverter->convertType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
UNCOV
139
        $this->assertNull($graphqlType);
×
140
    }
141

142
    public function testConvertTypeNoGraphQlResourceMetadata(): void
143
    {
UNCOV
144
        $type = Type::object('dummy');
×
145

146
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('dummy', [new ApiResource()]));
×
147

148
        $operation = (new Query())->withName('test');
×
UNCOV
149
        $graphqlType = $this->typeConverter->convertPhpType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
UNCOV
150
        $this->assertNull($graphqlType);
×
151
    }
152

153
    #[IgnoreDeprecations]
154
    public function testConvertTypeNodeResourceLegacy(): void
155
    {
UNCOV
156
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'node');
×
157

158
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(false);
×
159
        $this->resourceMetadataCollectionFactoryProphecy->create('node')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('node', [(new ApiResource())->withShortName('Node')->withGraphQlOperations(['test' => new Query()])]));
×
160

161
        $this->expectException(\UnexpectedValueException::class);
×
162
        $this->expectExceptionMessage('A "Node" resource cannot be used with GraphQL because the type is already used by the Relay specification.');
×
163

164
        $operation = (new Query())->withName('test');
×
UNCOV
165
        $this->typeConverter->convertType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
166
    }
167

168
    public function testConvertTypeNodeResource(): void
169
    {
UNCOV
170
        $type = Type::object('node');
×
171

UNCOV
172
        $this->resourceMetadataCollectionFactoryProphecy->create('node')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('node', [(new ApiResource())->withShortName('Node')->withGraphQlOperations(['test' => new Query()])]));
×
173

174
        $this->expectException(\UnexpectedValueException::class);
×
175
        $this->expectExceptionMessage('A "Node" resource cannot be used with GraphQL because the type is already used by the Relay specification.');
×
176

UNCOV
177
        $operation = (new Query())->withName('test');
×
178
        $this->typeConverter->convertPhpType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
179
    }
180

181
    #[IgnoreDeprecations]
182
    public function testConvertTypeResourceClassNotFoundLegacy(): void
183
    {
184
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummy');
×
185

UNCOV
186
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(false);
×
187
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->shouldBeCalled()->willThrow(new ResourceClassNotFoundException());
×
188

189
        $operation = (new Query())->withName('test');
×
UNCOV
190
        $graphqlType = $this->typeConverter->convertType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
UNCOV
191
        $this->assertNull($graphqlType);
×
192
    }
193

194
    public function testConvertTypeResourceClassNotFound(): void
195
    {
196
        $type = Type::object('dummy');
×
197

UNCOV
198
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->shouldBeCalled()->willThrow(new ResourceClassNotFoundException());
×
199

UNCOV
200
        $operation = (new Query())->withName('test');
×
UNCOV
201
        $graphqlType = $this->typeConverter->convertPhpType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
202
        $this->assertNull($graphqlType);
×
203
    }
204

205
    #[IgnoreDeprecations]
206
    public function testConvertTypeResourceIriLegacy(): void
207
    {
UNCOV
208
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummy');
×
209

210
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummy', [(new ApiResource())->withGraphQlOperations(['test' => new Query()])]);
×
211
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->willReturn($graphqlResourceMetadata);
×
UNCOV
212
        $this->typeBuilderProphecy->isCollection($type)->willReturn(false);
×
UNCOV
213
        $this->propertyMetadataFactoryProphecy->create('rootClass', 'dummyProperty', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withWritableLink(false));
×
214

UNCOV
215
        $operation = (new Query())->withName('test');
×
UNCOV
216
        $graphqlType = $this->typeConverter->convertType($type, true, $operation, 'dummy', 'rootClass', 'dummyProperty', 1);
×
217
        $this->assertSame(GraphQLType::string(), $graphqlType);
×
218
    }
219

220
    public function testConvertTypeResourceIri(): void
221
    {
UNCOV
222
        $type = Type::object('dummy');
×
223

UNCOV
224
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummy', [(new ApiResource())->withGraphQlOperations(['test' => new Query()])]);
×
225
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->willReturn($graphqlResourceMetadata);
×
226
        $this->propertyMetadataFactoryProphecy->create('rootClass', 'dummyProperty', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withWritableLink(false));
×
227

228
        $operation = (new Query())->withName('test');
×
229
        $graphqlType = $this->typeConverter->convertPhpType($type, true, $operation, 'dummy', 'rootClass', 'dummyProperty', 1);
×
230
        $this->assertSame(GraphQLType::string(), $graphqlType);
×
231
    }
232

233
    #[IgnoreDeprecations]
234
    public function testConvertTypeInputResourceLegacy(): void
235
    {
236
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummy');
×
UNCOV
237
        $operation = new Query();
×
UNCOV
238
        $propertyMetadata = (new ApiProperty())->withWritableLink(true);
×
UNCOV
239
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummy', [(new ApiResource())->withGraphQlOperations(['item_query' => $operation])]);
×
UNCOV
240
        $expectedGraphqlType = new ObjectType(['name' => 'resourceObjectType', 'fields' => []]);
×
241

242
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->willReturn($graphqlResourceMetadata);
×
UNCOV
243
        $this->typeBuilderProphecy->isCollection($type)->willReturn(false);
×
244
        $this->propertyMetadataFactoryProphecy->create('rootClass', 'dummyProperty', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withWritableLink(true));
×
UNCOV
245
        $this->typeBuilderProphecy->getResourceObjectType($graphqlResourceMetadata, $operation, $propertyMetadata, ['input' => true, 'wrapped' => false, 'depth' => 1])->shouldBeCalled()->willReturn($expectedGraphqlType);
×
246

UNCOV
247
        $graphqlType = $this->typeConverter->convertType($type, true, $operation, 'dummy', 'rootClass', 'dummyProperty', 1);
×
UNCOV
248
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
249
    }
250

251
    public function testConvertTypeInputResource(): void
252
    {
253
        $type = Type::object('dummy');
×
254
        $operation = new Query();
×
255
        $propertyMetadata = (new ApiProperty())->withWritableLink(true);
×
UNCOV
256
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummy', [(new ApiResource())->withGraphQlOperations(['item_query' => $operation])]);
×
UNCOV
257
        $expectedGraphqlType = new ObjectType(['name' => 'resourceObjectType', 'fields' => []]);
×
258

UNCOV
259
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->willReturn($graphqlResourceMetadata);
×
UNCOV
260
        $this->propertyMetadataFactoryProphecy->create('rootClass', 'dummyProperty', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withWritableLink(true));
×
UNCOV
261
        $this->typeBuilderProphecy->getResourceObjectType($graphqlResourceMetadata, $operation, $propertyMetadata, ['input' => true, 'wrapped' => false, 'depth' => 1])->shouldBeCalled()->willReturn($expectedGraphqlType);
×
262

UNCOV
263
        $graphqlType = $this->typeConverter->convertPhpType($type, true, $operation, 'dummy', 'rootClass', 'dummyProperty', 1);
×
UNCOV
264
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
265
    }
266

267
    #[DataProvider('legacyConvertTypeResourceProvider')]
268
    #[IgnoreDeprecations]
269
    public function testConvertTypeCollectionResourceLegacy(LegacyType $type, ObjectType $expectedGraphqlType): void
270
    {
UNCOV
271
        $collectionOperation = new QueryCollection();
×
UNCOV
272
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummyValue', [
×
UNCOV
273
            (new ApiResource())->withShortName('DummyValue')->withGraphQlOperations(['collection_query' => $collectionOperation]),
×
UNCOV
274
        ]);
×
275

UNCOV
276
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(true);
×
UNCOV
277
        $this->resourceMetadataCollectionFactoryProphecy->create('dummyValue')->shouldBeCalled()->willReturn($graphqlResourceMetadata);
×
UNCOV
278
        $this->typeBuilderProphecy->getResourceObjectType($graphqlResourceMetadata, $collectionOperation, null, [
×
UNCOV
279
            'input' => false,
×
UNCOV
280
            'wrapped' => false,
×
UNCOV
281
            'depth' => 0,
×
UNCOV
282
        ])->shouldBeCalled()->willReturn($expectedGraphqlType);
×
283

UNCOV
284
        $rootOperation = (new Query())->withName('test');
×
UNCOV
285
        $graphqlType = $this->typeConverter->convertType($type, false, $rootOperation, 'resourceClass', 'rootClass', null, 0);
×
UNCOV
286
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
287
    }
288

289
    public static function legacyConvertTypeResourceProvider(): array
290
    {
UNCOV
291
        return [
×
UNCOV
292
            [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, null, true, null, new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummyValue')), new ObjectType(['name' => 'resourceObjectType', 'fields' => []])],
×
UNCOV
293
            [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, null, new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummyValue')), new ObjectType(['name' => 'resourceObjectType', 'fields' => []])],
×
UNCOV
294
        ];
×
295
    }
296

297
    #[DataProvider('convertTypeResourceProvider')]
298
    public function testConvertTypeCollectionResource(Type $type, ObjectType $expectedGraphqlType): void
299
    {
UNCOV
300
        $collectionOperation = new QueryCollection();
×
UNCOV
301
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummyValue', [
×
UNCOV
302
            (new ApiResource())->withShortName('DummyValue')->withGraphQlOperations(['collection_query' => $collectionOperation]),
×
UNCOV
303
        ]);
×
304

UNCOV
305
        $this->resourceMetadataCollectionFactoryProphecy->create('dummyValue')->shouldBeCalled()->willReturn($graphqlResourceMetadata);
×
UNCOV
306
        $this->typeBuilderProphecy->getResourceObjectType($graphqlResourceMetadata, $collectionOperation, null, [
×
UNCOV
307
            'input' => false,
×
UNCOV
308
            'wrapped' => false,
×
UNCOV
309
            'depth' => 0,
×
UNCOV
310
        ])->shouldBeCalled()->willReturn($expectedGraphqlType);
×
311

UNCOV
312
        $rootOperation = (new Query())->withName('test');
×
UNCOV
313
        $graphqlType = $this->typeConverter->convertPhpType($type, false, $rootOperation, 'resourceClass', 'rootClass', null, 0);
×
UNCOV
314
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
315
    }
316

317
    public static function convertTypeResourceProvider(): array
318
    {
UNCOV
319
        return [
×
UNCOV
320
            [Type::collection(Type::object('dummyValue'), Type::object('dummyValue')), new ObjectType(['name' => 'resourceObjectType', 'fields' => []])], // @phpstan-ignore-line
×
UNCOV
321
            [Type::array(Type::object('dummyValue')), new ObjectType(['name' => 'resourceObjectType', 'fields' => []])],
×
UNCOV
322
        ];
×
323
    }
324

325
    #[IgnoreDeprecations]
326
    public function testConvertTypeCollectionEnumLegacy(): void
327
    {
UNCOV
328
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, null, new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, GenderTypeEnum::class));
×
UNCOV
329
        $expectedGraphqlType = new EnumType(['name' => 'GenderTypeEnum', 'values' => []]);
×
UNCOV
330
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(true);
×
UNCOV
331
        $this->resourceMetadataCollectionFactoryProphecy->create(GenderTypeEnum::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(GenderTypeEnum::class, []));
×
UNCOV
332
        $this->typeBuilderProphecy->getEnumType(Argument::type(Operation::class))->willReturn($expectedGraphqlType);
×
333

UNCOV
334
        $rootOperation = (new Query())->withName('test');
×
UNCOV
335
        $graphqlType = $this->typeConverter->convertType($type, false, $rootOperation, 'resourceClass', 'rootClass', null, 0);
×
UNCOV
336
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
337
    }
338

339
    public function testConvertTypeCollectionEnum(): void
340
    {
UNCOV
341
        $type = Type::array(Type::object(GenderTypeEnum::class));
×
UNCOV
342
        $expectedGraphqlType = new EnumType(['name' => 'GenderTypeEnum', 'values' => []]);
×
UNCOV
343
        $this->resourceMetadataCollectionFactoryProphecy->create(GenderTypeEnum::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(GenderTypeEnum::class, []));
×
UNCOV
344
        $this->typeBuilderProphecy->getEnumType(Argument::type(Operation::class))->willReturn($expectedGraphqlType);
×
345

UNCOV
346
        $rootOperation = (new Query())->withName('test');
×
UNCOV
347
        $graphqlType = $this->typeConverter->convertPhpType($type, false, $rootOperation, 'resourceClass', 'rootClass', null, 0);
×
UNCOV
348
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
349
    }
350

351
    #[DataProvider('resolveTypeProvider')]
352
    public function testResolveType(string $type, string|GraphQLType $expectedGraphqlType): void
353
    {
UNCOV
354
        $this->typesContainerProphecy->has(\DateTime::class)->willReturn(true);
×
UNCOV
355
        $this->typesContainerProphecy->get(\DateTime::class)->willReturn(new DateTimeType());
×
356

UNCOV
357
        $this->assertEquals($expectedGraphqlType, $this->typeConverter->resolveType($type));
×
358
    }
359

360
    public static function resolveTypeProvider(): array
361
    {
UNCOV
362
        return [
×
UNCOV
363
            ['String', GraphQLType::string()],
×
UNCOV
364
            ['String!', GraphQLType::nonNull(GraphQLType::string())],
×
UNCOV
365
            ['Boolean', GraphQLType::boolean()],
×
UNCOV
366
            ['[Boolean]', GraphQLType::listOf(GraphQLType::boolean())],
×
UNCOV
367
            ['Int!', GraphQLType::nonNull(GraphQLType::int())],
×
UNCOV
368
            ['[Int!]', GraphQLType::listOf(GraphQLType::nonNull(GraphQLType::int()))],
×
UNCOV
369
            ['Float', GraphQLType::float()],
×
UNCOV
370
            ['[Float]!', GraphQLType::nonNull(GraphQLType::listOf(GraphQLType::float()))],
×
UNCOV
371
            [\DateTime::class, new DateTimeType()],
×
UNCOV
372
            ['[DateTime!]!', GraphQLType::nonNull(GraphQLType::listOf(GraphQLType::nonNull(new DateTimeType())))],
×
UNCOV
373
        ];
×
374
    }
375

376
    #[DataProvider('resolveTypeInvalidProvider')]
377
    public function testResolveTypeInvalid(string $type, string $expectedExceptionMessage): void
378
    {
UNCOV
379
        $this->typesContainerProphecy->has('UnknownType')->willReturn(false);
×
380

UNCOV
381
        $this->expectExceptionMessage($expectedExceptionMessage);
×
382

UNCOV
383
        $this->typeConverter->resolveType($type);
×
384
    }
385

386
    public static function resolveTypeInvalidProvider(): array
387
    {
UNCOV
388
        return [
×
UNCOV
389
            ['float?', '"float?" is not a valid GraphQL type.'],
×
UNCOV
390
            ['UnknownType', 'The type "UnknownType" was not resolved.'],
×
UNCOV
391
            ['UnknownType!', 'The type "UnknownType!" was not resolved.'],
×
UNCOV
392
        ];
×
393
    }
394
}
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

© 2026 Coveralls, Inc