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

api-platform / core / 19799380020

30 Nov 2025 01:09PM UTC coverage: 0.0%. Remained the same
19799380020

push

github

soyuka
Merge 4.2

0 of 306 new or added lines in 35 files covered. (0.0%)

22 existing lines in 15 files now uncovered.

0 of 57173 relevant lines covered (0.0%)

0.0 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);
×
62
        $this->resourceMetadataCollectionFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
63
        $this->propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
64
        $this->typeConverter = new TypeConverter($this->typeBuilderProphecy->reveal(), $this->typesContainerProphecy->reveal(), $this->resourceMetadataCollectionFactoryProphecy->reveal(), $this->propertyMetadataFactoryProphecy->reveal());
×
65
    }
66

67
    #[IgnoreDeprecations]
68
    public function testConvertTypeLegacy(): void
69
    {
NEW
70
        if (!class_exists(LegacyType::class)) {
×
NEW
71
            $this->markTestSkipped();
×
72
        }
73

NEW
74
        $testCases = [
×
75
            [new LegacyType(LegacyType::BUILTIN_TYPE_BOOL), false, 0, GraphQLType::boolean()],
×
76
            [new LegacyType(LegacyType::BUILTIN_TYPE_INT), false, 0, GraphQLType::int()],
×
77
            [new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT), false, 0, GraphQLType::float()],
×
78
            [new LegacyType(LegacyType::BUILTIN_TYPE_STRING), false, 0, GraphQLType::string()],
×
79
            [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY), false, 0, 'Iterable'],
×
80
            [new LegacyType(LegacyType::BUILTIN_TYPE_ITERABLE), false, 0, 'Iterable'],
×
81
            [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, \DateTimeInterface::class), false, 0, GraphQLType::string()],
×
82
            [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, GenderTypeEnum::class), false, 0, new EnumType(['name' => 'GenderTypeEnum', 'values' => []])],
×
83
            [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT), false, 0, null],
×
84
            [new LegacyType(LegacyType::BUILTIN_TYPE_CALLABLE), false, 0, null],
×
85
            [new LegacyType(LegacyType::BUILTIN_TYPE_NULL), false, 0, null],
×
86
            [new LegacyType(LegacyType::BUILTIN_TYPE_RESOURCE), false, 0, null],
×
87
        ];
×
88

NEW
89
        foreach ($testCases as [$type, $input, $depth, $expectedGraphqlType]) {
×
90
            /* @var LegacyType $type */
91
            /* @var bool $input */
92
            /* @var int $depth */
93
            /* @var GraphQLType|string|null $expectedGraphqlType */
NEW
94
            $this->expectUserDeprecationMessage('Since api-platform/graphql 4.2: The "ApiPlatform\GraphQl\Type\TypeConverter::convertType()" method is deprecated, use "ApiPlatform\GraphQl\Type\TypeConverter::convertPhpType()" instead.');
×
95

NEW
96
            $this->typeBuilderProphecy->isCollection($type)->willReturn(false);
×
NEW
97
            $this->resourceMetadataCollectionFactoryProphecy->create(Argument::type('string'))->willReturn(new ResourceMetadataCollection('resourceClass'));
×
NEW
98
            $this->typeBuilderProphecy->getEnumType(Argument::type(Operation::class))->willReturn($expectedGraphqlType);
×
99

NEW
100
            $operation = (new Query())->withName('test');
×
NEW
101
            $graphqlType = $this->typeConverter->convertType($type, $input, $operation, 'resourceClass', 'rootClass', null, $depth);
×
NEW
102
            $this->assertSame($expectedGraphqlType, $graphqlType);
×
103
        }
104
    }
105

106
    #[DataProvider('convertTypeProvider')]
107
    public function testConvertType(Type $type, bool $input, int $depth, GraphQLType|string|null $expectedGraphqlType): void
108
    {
109
        $this->resourceMetadataCollectionFactoryProphecy->create(Argument::type('string'))->willReturn(new ResourceMetadataCollection('resourceClass'));
×
110
        $this->typeBuilderProphecy->getEnumType(Argument::type(Operation::class))->willReturn($expectedGraphqlType);
×
111

112
        $operation = (new Query())->withName('test');
×
113
        $graphqlType = $this->typeConverter->convertPhpType($type, $input, $operation, 'resourceClass', 'rootClass', null, $depth);
×
114
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
115
    }
116

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

135
    #[IgnoreDeprecations]
136
    public function testConvertTypeNoGraphQlResourceMetadataLegacy(): void
137
    {
NEW
138
        if (!class_exists(LegacyType::class)) {
×
NEW
139
            $this->markTestSkipped();
×
140
        }
141

UNCOV
142
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummy');
×
143

144
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(false);
×
145
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('dummy', [new ApiResource()]));
×
146

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

152
    public function testConvertTypeNoGraphQlResourceMetadata(): void
153
    {
154
        $type = Type::object('dummy');
×
155

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

158
        $operation = (new Query())->withName('test');
×
159
        $graphqlType = $this->typeConverter->convertPhpType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
160
        $this->assertNull($graphqlType);
×
161
    }
162

163
    #[IgnoreDeprecations]
164
    public function testConvertTypeNodeResourceLegacy(): void
165
    {
NEW
166
        if (!class_exists(LegacyType::class)) {
×
NEW
167
            $this->markTestSkipped();
×
168
        }
UNCOV
169
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'node');
×
170

171
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(false);
×
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

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

181
    public function testConvertTypeNodeResource(): void
182
    {
183
        $type = Type::object('node');
×
184

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

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

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

194
    #[IgnoreDeprecations]
195
    public function testConvertTypeResourceClassNotFoundLegacy(): void
196
    {
NEW
197
        if (!class_exists(LegacyType::class)) {
×
NEW
198
            $this->markTestSkipped();
×
199
        }
UNCOV
200
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummy');
×
201

202
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(false);
×
203
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->shouldBeCalled()->willThrow(new ResourceClassNotFoundException());
×
204

205
        $operation = (new Query())->withName('test');
×
206
        $graphqlType = $this->typeConverter->convertType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
207
        $this->assertNull($graphqlType);
×
208
    }
209

210
    public function testConvertTypeResourceClassNotFound(): void
211
    {
212
        $type = Type::object('dummy');
×
213

214
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->shouldBeCalled()->willThrow(new ResourceClassNotFoundException());
×
215

216
        $operation = (new Query())->withName('test');
×
217
        $graphqlType = $this->typeConverter->convertPhpType($type, false, $operation, 'resourceClass', 'rootClass', null, 0);
×
218
        $this->assertNull($graphqlType);
×
219
    }
220

221
    #[IgnoreDeprecations]
222
    public function testConvertTypeResourceIriLegacy(): void
223
    {
NEW
224
        if (!class_exists(LegacyType::class)) {
×
NEW
225
            $this->markTestSkipped();
×
226
        }
UNCOV
227
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummy');
×
228

229
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummy', [(new ApiResource())->withGraphQlOperations(['test' => new Query()])]);
×
230
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->willReturn($graphqlResourceMetadata);
×
231
        $this->typeBuilderProphecy->isCollection($type)->willReturn(false);
×
232
        $this->propertyMetadataFactoryProphecy->create('rootClass', 'dummyProperty', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withWritableLink(false));
×
233

234
        $operation = (new Query())->withName('test');
×
235
        $graphqlType = $this->typeConverter->convertType($type, true, $operation, 'dummy', 'rootClass', 'dummyProperty', 1);
×
236
        $this->assertSame(GraphQLType::string(), $graphqlType);
×
237
    }
238

239
    public function testConvertTypeResourceIri(): void
240
    {
241
        $type = Type::object('dummy');
×
242

243
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummy', [(new ApiResource())->withGraphQlOperations(['test' => new Query()])]);
×
244
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->willReturn($graphqlResourceMetadata);
×
245
        $this->propertyMetadataFactoryProphecy->create('rootClass', 'dummyProperty', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withWritableLink(false));
×
246

247
        $operation = (new Query())->withName('test');
×
248
        $graphqlType = $this->typeConverter->convertPhpType($type, true, $operation, 'dummy', 'rootClass', 'dummyProperty', 1);
×
249
        $this->assertSame(GraphQLType::string(), $graphqlType);
×
250
    }
251

252
    #[IgnoreDeprecations]
253
    public function testConvertTypeInputResourceLegacy(): void
254
    {
NEW
255
        if (!class_exists(LegacyType::class)) {
×
NEW
256
            $this->markTestSkipped();
×
257
        }
258
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummy');
×
259
        $operation = new Query();
×
260
        $propertyMetadata = (new ApiProperty())->withWritableLink(true);
×
261
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummy', [(new ApiResource())->withGraphQlOperations(['item_query' => $operation])]);
×
262
        $expectedGraphqlType = new ObjectType(['name' => 'resourceObjectType', 'fields' => []]);
×
263

264
        $this->resourceMetadataCollectionFactoryProphecy->create('dummy')->willReturn($graphqlResourceMetadata);
×
265
        $this->typeBuilderProphecy->isCollection($type)->willReturn(false);
×
266
        $this->propertyMetadataFactoryProphecy->create('rootClass', 'dummyProperty', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withWritableLink(true));
×
267
        $this->typeBuilderProphecy->getResourceObjectType($graphqlResourceMetadata, $operation, $propertyMetadata, ['input' => true, 'wrapped' => false, 'depth' => 1])->shouldBeCalled()->willReturn($expectedGraphqlType);
×
268

269
        $graphqlType = $this->typeConverter->convertType($type, true, $operation, 'dummy', 'rootClass', 'dummyProperty', 1);
×
270
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
271
    }
272

273
    public function testConvertTypeInputResource(): void
274
    {
275
        $type = Type::object('dummy');
×
276
        $operation = new Query();
×
277
        $propertyMetadata = (new ApiProperty())->withWritableLink(true);
×
278
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummy', [(new ApiResource())->withGraphQlOperations(['item_query' => $operation])]);
×
279
        $expectedGraphqlType = new ObjectType(['name' => 'resourceObjectType', 'fields' => []]);
×
280

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

285
        $graphqlType = $this->typeConverter->convertPhpType($type, true, $operation, 'dummy', 'rootClass', 'dummyProperty', 1);
×
286
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
287
    }
288

289
    #[IgnoreDeprecations]
290
    public function testConvertTypeCollectionResourceLegacy(): void
291
    {
NEW
292
        if (!class_exists(LegacyType::class)) {
×
NEW
293
            $this->markTestSkipped();
×
294
        }
NEW
295
        $fixtures = [
×
296
            [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, null, true, null, new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummyValue')), new ObjectType(['name' => 'resourceObjectType', 'fields' => []])],
×
297
            [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, null, new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'dummyValue')), new ObjectType(['name' => 'resourceObjectType', 'fields' => []])],
×
298
        ];
×
299

NEW
300
        foreach ($fixtures as [$type, $expectedGraphqlType]) {
×
NEW
301
            $collectionOperation = new QueryCollection();
×
NEW
302
            $graphqlResourceMetadata = new ResourceMetadataCollection('dummyValue', [
×
NEW
303
                (new ApiResource())->withShortName('DummyValue')->withGraphQlOperations(['collection_query' => $collectionOperation]),
×
NEW
304
            ]);
×
305

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

NEW
314
            $rootOperation = (new Query())->withName('test');
×
NEW
315
            $graphqlType = $this->typeConverter->convertType($type, false, $rootOperation, 'resourceClass', 'rootClass', null, 0);
×
NEW
316
            $this->assertSame($expectedGraphqlType, $graphqlType);
×
317
        }
318
    }
319

320
    #[DataProvider('convertTypeResourceProvider')]
321
    public function testConvertTypeCollectionResource(Type $type, ObjectType $expectedGraphqlType): void
322
    {
323
        $collectionOperation = new QueryCollection();
×
324
        $graphqlResourceMetadata = new ResourceMetadataCollection('dummyValue', [
×
325
            (new ApiResource())->withShortName('DummyValue')->withGraphQlOperations(['collection_query' => $collectionOperation]),
×
326
        ]);
×
327

328
        $this->resourceMetadataCollectionFactoryProphecy->create('dummyValue')->shouldBeCalled()->willReturn($graphqlResourceMetadata);
×
329
        $this->typeBuilderProphecy->getResourceObjectType($graphqlResourceMetadata, $collectionOperation, null, [
×
330
            'input' => false,
×
331
            'wrapped' => false,
×
332
            'depth' => 0,
×
333
        ])->shouldBeCalled()->willReturn($expectedGraphqlType);
×
334

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

340
    public static function convertTypeResourceProvider(): array
341
    {
342
        return [
×
343
            [Type::collection(Type::object('dummyValue'), Type::object('dummyValue')), new ObjectType(['name' => 'resourceObjectType', 'fields' => []])], // @phpstan-ignore-line
×
344
            [Type::array(Type::object('dummyValue')), new ObjectType(['name' => 'resourceObjectType', 'fields' => []])],
×
345
        ];
×
346
    }
347

348
    #[IgnoreDeprecations]
349
    public function testConvertTypeCollectionEnumLegacy(): void
350
    {
NEW
351
        if (!class_exists(LegacyType::class)) {
×
NEW
352
            $this->markTestSkipped();
×
353
        }
354
        $type = new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, null, new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, GenderTypeEnum::class));
×
355
        $expectedGraphqlType = new EnumType(['name' => 'GenderTypeEnum', 'values' => []]);
×
356
        $this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(true);
×
357
        $this->resourceMetadataCollectionFactoryProphecy->create(GenderTypeEnum::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(GenderTypeEnum::class, []));
×
358
        $this->typeBuilderProphecy->getEnumType(Argument::type(Operation::class))->willReturn($expectedGraphqlType);
×
359

360
        $rootOperation = (new Query())->withName('test');
×
361
        $graphqlType = $this->typeConverter->convertType($type, false, $rootOperation, 'resourceClass', 'rootClass', null, 0);
×
362
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
363
    }
364

365
    public function testConvertTypeCollectionEnum(): void
366
    {
367
        $type = Type::array(Type::object(GenderTypeEnum::class));
×
368
        $expectedGraphqlType = new EnumType(['name' => 'GenderTypeEnum', 'values' => []]);
×
369
        $this->resourceMetadataCollectionFactoryProphecy->create(GenderTypeEnum::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(GenderTypeEnum::class, []));
×
370
        $this->typeBuilderProphecy->getEnumType(Argument::type(Operation::class))->willReturn($expectedGraphqlType);
×
371

372
        $rootOperation = (new Query())->withName('test');
×
373
        $graphqlType = $this->typeConverter->convertPhpType($type, false, $rootOperation, 'resourceClass', 'rootClass', null, 0);
×
374
        $this->assertSame($expectedGraphqlType, $graphqlType);
×
375
    }
376

377
    #[DataProvider('resolveTypeProvider')]
378
    public function testResolveType(string $type, string|GraphQLType $expectedGraphqlType): void
379
    {
380
        $this->typesContainerProphecy->has(\DateTime::class)->willReturn(true);
×
381
        $this->typesContainerProphecy->get(\DateTime::class)->willReturn(new DateTimeType());
×
382

383
        $this->assertEquals($expectedGraphqlType, $this->typeConverter->resolveType($type));
×
384
    }
385

386
    public static function resolveTypeProvider(): array
387
    {
388
        return [
×
389
            ['String', GraphQLType::string()],
×
390
            ['String!', GraphQLType::nonNull(GraphQLType::string())],
×
391
            ['Boolean', GraphQLType::boolean()],
×
392
            ['[Boolean]', GraphQLType::listOf(GraphQLType::boolean())],
×
393
            ['Int!', GraphQLType::nonNull(GraphQLType::int())],
×
394
            ['[Int!]', GraphQLType::listOf(GraphQLType::nonNull(GraphQLType::int()))],
×
395
            ['Float', GraphQLType::float()],
×
396
            ['[Float]!', GraphQLType::nonNull(GraphQLType::listOf(GraphQLType::float()))],
×
397
            [\DateTime::class, new DateTimeType()],
×
398
            ['[DateTime!]!', GraphQLType::nonNull(GraphQLType::listOf(GraphQLType::nonNull(new DateTimeType())))],
×
399
        ];
×
400
    }
401

402
    #[DataProvider('resolveTypeInvalidProvider')]
403
    public function testResolveTypeInvalid(string $type, string $expectedExceptionMessage): void
404
    {
405
        $this->typesContainerProphecy->has('UnknownType')->willReturn(false);
×
406

407
        $this->expectExceptionMessage($expectedExceptionMessage);
×
408

409
        $this->typeConverter->resolveType($type);
×
410
    }
411

412
    public static function resolveTypeInvalidProvider(): array
413
    {
414
        return [
×
415
            ['float?', '"float?" is not a valid GraphQL type.'],
×
416
            ['UnknownType', 'The type "UnknownType" was not resolved.'],
×
417
            ['UnknownType!', 'The type "UnknownType!" was not resolved.'],
×
418
        ];
×
419
    }
420
}
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