@@ -107,7 +107,40 @@ public function validOptionalTypeReferenceIsValid(): void
107107 /**
108108 * @test
109109 */
110- public function typeReferenceCannotBeArrayAndOptionalSimultaneously (): void
110+ public function validUnionTypeReferenceIsValid (): void
111+ {
112+ $ typeReferenceNode = new TypeReferenceNode (
113+ attributes: $ this ->dummyAttributes ,
114+ names: new TypeNameNodes (
115+ new TypeNameNode (
116+ attributes: $ this ->dummyAttributes ,
117+ value: TypeName::from ('Foo ' )
118+ ),
119+ new TypeNameNode (
120+ attributes: $ this ->dummyAttributes ,
121+ value: TypeName::from ('Bar ' )
122+ ),
123+ new TypeNameNode (
124+ attributes: $ this ->dummyAttributes ,
125+ value: TypeName::from ('Baz ' )
126+ )
127+ ),
128+ isArray: false ,
129+ isOptional: false
130+ );
131+
132+ $ this ->assertEquals (3 , $ typeReferenceNode ->names ->getSize ());
133+ $ this ->assertEquals ('Foo ' , $ typeReferenceNode ->names ->items [0 ]->value ->value );
134+ $ this ->assertEquals ('Bar ' , $ typeReferenceNode ->names ->items [1 ]->value ->value );
135+ $ this ->assertEquals ('Baz ' , $ typeReferenceNode ->names ->items [2 ]->value ->value );
136+ $ this ->assertFalse ($ typeReferenceNode ->isArray );
137+ $ this ->assertFalse ($ typeReferenceNode ->isOptional );
138+ }
139+
140+ /**
141+ * @test
142+ */
143+ public function mustNotBeArrayAndOptionalSimultaneously (): void
111144 {
112145 $ name = TypeName::from ('Foo ' );
113146
@@ -130,4 +163,74 @@ public function typeReferenceCannotBeArrayAndOptionalSimultaneously(): void
130163 isOptional: true
131164 );
132165 }
166+
167+ /**
168+ * @test
169+ */
170+ public function mustNotBeUnionAndArraySimultaneously (): void
171+ {
172+ $ typeNameNodes = new TypeNameNodes (
173+ new TypeNameNode (
174+ attributes: $ this ->dummyAttributes ,
175+ value: TypeName::from ('Foo ' )
176+ ),
177+ new TypeNameNode (
178+ attributes: $ this ->dummyAttributes ,
179+ value: TypeName::from ('Bar ' )
180+ ),
181+ new TypeNameNode (
182+ attributes: $ this ->dummyAttributes ,
183+ value: TypeName::from ('Baz ' )
184+ )
185+ );
186+
187+ $ this ->expectExceptionObject (
188+ InvalidTypeReferenceNode::becauseItWasUnionAndArrayAtTheSameTime (
189+ affectedTypeNames: $ typeNameNodes ->toTypeNames (),
190+ attributesOfAffectedNode: $ this ->dummyAttributes
191+ )
192+ );
193+
194+ new TypeReferenceNode (
195+ attributes: $ this ->dummyAttributes ,
196+ names: $ typeNameNodes ,
197+ isArray: true ,
198+ isOptional: false
199+ );
200+ }
201+
202+ /**
203+ * @test
204+ */
205+ public function mustNotBeUnionAndOptionalSimultaneously (): void
206+ {
207+ $ typeNameNodes = new TypeNameNodes (
208+ new TypeNameNode (
209+ attributes: $ this ->dummyAttributes ,
210+ value: TypeName::from ('Foo ' )
211+ ),
212+ new TypeNameNode (
213+ attributes: $ this ->dummyAttributes ,
214+ value: TypeName::from ('Bar ' )
215+ ),
216+ new TypeNameNode (
217+ attributes: $ this ->dummyAttributes ,
218+ value: TypeName::from ('Baz ' )
219+ )
220+ );
221+
222+ $ this ->expectExceptionObject (
223+ InvalidTypeReferenceNode::becauseItWasUnionAndOptionalAtTheSameTime (
224+ affectedTypeNames: $ typeNameNodes ->toTypeNames (),
225+ attributesOfAffectedNode: $ this ->dummyAttributes
226+ )
227+ );
228+
229+ new TypeReferenceNode (
230+ attributes: $ this ->dummyAttributes ,
231+ names: $ typeNameNodes ,
232+ isArray: false ,
233+ isOptional: true
234+ );
235+ }
133236}
0 commit comments