Skip to content

Commit 0af0f2b

Browse files
committed
Ensure int based PHP enum works
1 parent 04daa88 commit 0af0f2b

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace GraphQL\Tests\Type\PhpEnumType;
4+
5+
enum IntPhpEnum: int
6+
{
7+
case A = 1;
8+
}

tests/Type/PhpEnumTypeTest.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use GraphQL\GraphQL;
88
use GraphQL\Tests\TestCaseBase;
99
use GraphQL\Tests\Type\PhpEnumType\DocBlockPhpEnum;
10+
use GraphQL\Tests\Type\PhpEnumType\IntPhpEnum;
1011
use GraphQL\Tests\Type\PhpEnumType\MultipleDeprecationsPhpEnum;
1112
use GraphQL\Tests\Type\PhpEnumType\MultipleDescriptionsCasePhpEnum;
1213
use GraphQL\Tests\Type\PhpEnumType\MultipleDescriptionsPhpEnum;
@@ -31,42 +32,45 @@ protected function setUp(): void
3132
public function testConstructEnumTypeFromPhpEnum(): void
3233
{
3334
$enumType = new PhpEnumType(PhpEnum::class);
34-
self::assertSame(
35-
<<<'GRAPHQL'
35+
self::assertSame(<<<'GRAPHQL'
3636
"foo"
3737
enum PhpEnum {
3838
"bar"
3939
A
4040
B @deprecated
4141
C @deprecated(reason: "baz")
4242
}
43-
GRAPHQL,
44-
SchemaPrinter::printType($enumType)
45-
);
43+
GRAPHQL, SchemaPrinter::printType($enumType));
44+
}
45+
46+
public function testConstructEnumTypeFromIntPhpEnum(): void
47+
{
48+
$enumType = new PhpEnumType(IntPhpEnum::class);
49+
self::assertSame(<<<'GRAPHQL'
50+
enum IntPhpEnum {
51+
A
52+
}
53+
GRAPHQL, SchemaPrinter::printType($enumType));
4654
}
4755

4856
public function testConstructEnumTypeFromPhpEnumWithCustomName(): void
4957
{
5058
$enumType = new PhpEnumType(PhpEnum::class, 'CustomNamedPhpEnum');
51-
self::assertSame(
52-
<<<'GRAPHQL'
59+
self::assertSame(<<<'GRAPHQL'
5360
"foo"
5461
enum CustomNamedPhpEnum {
5562
"bar"
5663
A
5764
B @deprecated
5865
C @deprecated(reason: "baz")
5966
}
60-
GRAPHQL,
61-
SchemaPrinter::printType($enumType)
62-
);
67+
GRAPHQL, SchemaPrinter::printType($enumType));
6368
}
6469

6570
public function testConstructEnumTypeFromPhpEnumWithDocBlockDescriptions(): void
6671
{
6772
$enumType = new PhpEnumType(DocBlockPhpEnum::class);
68-
self::assertSame(
69-
<<<'GRAPHQL'
73+
self::assertSame(<<<'GRAPHQL'
7074
"foo"
7175
enum DocBlockPhpEnum {
7276
"preferred"
@@ -78,9 +82,7 @@ enum DocBlockPhpEnum {
7882
"""
7983
B
8084
}
81-
GRAPHQL,
82-
SchemaPrinter::printType($enumType)
83-
);
85+
GRAPHQL, SchemaPrinter::printType($enumType));
8486
}
8587

8688
public function testMultipleDescriptionsDisallowed(): void
@@ -126,14 +128,11 @@ public function testExecutesWithEnumTypeFromPhpEnum(): void
126128
]),
127129
]);
128130

129-
self::assertSame(
130-
[
131-
'data' => [
132-
'foo' => 'A',
133-
],
131+
self::assertSame([
132+
'data' => [
133+
'foo' => 'A',
134134
],
135-
GraphQL::executeQuery($schema, '{ foo(bar: A) }')->toArray()
136-
);
135+
], GraphQL::executeQuery($schema, '{ foo(bar: A) }')->toArray());
137136
}
138137

139138
public function testFailsToSerializeNonEnum(): void

0 commit comments

Comments
 (0)