@@ -59,6 +59,29 @@ public function testMapObjectUnionWorks(): void
5959 $ this ->assertEquals ('TestObject ' , $ unionTypes [0 ]->name );
6060 $ this ->assertEquals ('TestObject2 ' , $ unionTypes [1 ]->name );
6161 }
62+ /**
63+ * @requires PHP >= 8.0
64+ */
65+ public function testMapObjectNullableUnionWorks (): void
66+ {
67+ $ typeMapper = new TypeHandler ($ this ->getArgumentResolver (), $ this ->getRootTypeMapper (), $ this ->getTypeResolver ());
68+
69+ $ cachedDocBlockFactory = new CachedDocBlockFactory (new Psr16Cache (new ArrayAdapter ()));
70+
71+ $ refMethod = new ReflectionMethod (UnionOutputType::class, 'nullableObjectUnion ' );
72+ $ docBlockObj = $ cachedDocBlockFactory ->getDocBlock ($ refMethod );
73+
74+ $ gqType = $ typeMapper ->mapReturnType ($ refMethod , $ docBlockObj );
75+ $ this ->assertNotInstanceOf (NonNull::class, $ gqType );
76+ assert (!($ gqType instanceof NonNull));
77+ $ this ->assertInstanceOf (UnionType::class, $ gqType );
78+ assert ($ gqType instanceof UnionType);
79+ $ unionTypes = $ gqType ->getTypes ();
80+ $ this ->assertEquals (2 , count ($ unionTypes ));
81+ $ this ->assertEquals ('TestObject ' , $ unionTypes [0 ]->name );
82+ $ this ->assertEquals ('TestObject2 ' , $ unionTypes [1 ]->name );
83+
84+ }
6285
6386 public function testHideParameter (): void
6487 {
@@ -99,21 +122,24 @@ public function testHideParameterException(): void
99122 /**
100123 * @return int|string
101124 */
102- private function dummy () {
125+ private function dummy ()
126+ {
103127
104128 }
105129
106130 /**
107131 * @HideParameter(for="$foo")
108132 */
109- private function withDefaultValue ($ foo = 24 ) {
133+ private function withDefaultValue ($ foo = 24 )
134+ {
110135
111136 }
112137
113138 /**
114139 * @HideParameter(for="$foo")
115140 */
116- private function withoutDefaultValue ($ foo ) {
141+ private function withoutDefaultValue ($ foo )
142+ {
117143
118144 }
119145}
0 commit comments