@@ -45,9 +45,7 @@ public function testOptionsSuccessPath(): void
4545
4646 public function testInputExpansionViaOptions (): void
4747 {
48- $ params = ($ this ->optionsParam )('/contact ' , 'onPost ' );
49- $ names = array_map (static fn (ParamMeta $ p ) => $ p ->name , $ params );
50- $ this ->skipIfInputNotExpanded ($ names );
48+ [$ names ] = $ this ->getExpandedContactParams ();
5149
5250 // OPTIONS success expands #[Input] ContactInput into individual properties
5351 $ this ->assertContains ('name ' , $ names );
@@ -58,14 +56,7 @@ public function testInputExpansionViaOptions(): void
5856
5957 public function testInputExpansionTypes (): void
6058 {
61- $ params = ($ this ->optionsParam )('/contact ' , 'onPost ' );
62- $ names = array_map (static fn (ParamMeta $ p ) => $ p ->name , $ params );
63- $ this ->skipIfInputNotExpanded ($ names );
64-
65- $ indexed = [];
66- foreach ($ params as $ param ) {
67- $ indexed [$ param ->name ] = $ param ;
68- }
59+ [, $ indexed ] = $ this ->getExpandedContactParams ();
6960
7061 $ this ->assertSame ('string ' , $ indexed ['name ' ]->type );
7162 $ this ->assertSame ('string ' , $ indexed ['email ' ]->type );
@@ -75,14 +66,7 @@ public function testInputExpansionTypes(): void
7566
7667 public function testInputExpansionOptionality (): void
7768 {
78- $ params = ($ this ->optionsParam )('/contact ' , 'onPost ' );
79- $ names = array_map (static fn (ParamMeta $ p ) => $ p ->name , $ params );
80- $ this ->skipIfInputNotExpanded ($ names );
81-
82- $ indexed = [];
83- foreach ($ params as $ param ) {
84- $ indexed [$ param ->name ] = $ param ;
85- }
69+ [, $ indexed ] = $ this ->getExpandedContactParams ();
8670
8771 // name, email, subject are required; age is optional (has default 0)
8872 $ this ->assertFalse ($ indexed ['name ' ]->isOptional );
@@ -93,14 +77,7 @@ public function testInputExpansionOptionality(): void
9377
9478 public function testInputExpansionDefault (): void
9579 {
96- $ params = ($ this ->optionsParam )('/contact ' , 'onPost ' );
97- $ names = array_map (static fn (ParamMeta $ p ) => $ p ->name , $ params );
98- $ this ->skipIfInputNotExpanded ($ names );
99-
100- $ indexed = [];
101- foreach ($ params as $ param ) {
102- $ indexed [$ param ->name ] = $ param ;
103- }
80+ [, $ indexed ] = $ this ->getExpandedContactParams ();
10481
10582 $ this ->assertSame ('0 ' , $ indexed ['age ' ]->default );
10683 $ this ->assertSame ('' , $ indexed ['name ' ]->default );
@@ -166,11 +143,20 @@ public function testFallbackNullDefault(): void
166143 $ this ->assertSame ('' , $ indexed ['firstName ' ]->default );
167144 }
168145
169- /** @param list<string> $names */
170- private function skipIfInputNotExpanded ( array $ names ): void
146+ /** @return array{ list<string>, array<string, ParamMeta>} */
147+ private function getExpandedContactParams ( ): array
171148 {
149+ $ params = ($ this ->optionsParam )('/contact ' , 'onPost ' );
150+ $ names = array_map (static fn (ParamMeta $ p ) => $ p ->name , $ params );
172151 if (in_array ('contact ' , $ names , true )) {
173152 $ this ->markTestSkipped ('#[Input] expansion not supported in this bear/resource version ' );
174153 }
154+
155+ $ indexed = [];
156+ foreach ($ params as $ param ) {
157+ $ indexed [$ param ->name ] = $ param ;
158+ }
159+
160+ return [$ names , $ indexed ];
175161 }
176162}
0 commit comments