File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ private function selectDropdown(): Element
125125 {
126126 $ elements = [];
127127 foreach ($ this ->options as $ value => $ content ) {
128+ $ value = strval ($ value );
128129 $ option = Element::option ($ content )->props ('value ' . $ value );
129130 if ($ this ->isSelected ($ value )) {
130131 $ option = $ option ->prop ('selected selected ' );
@@ -150,6 +151,7 @@ private function selectOther(): Element
150151 $ type = 'checkbox ' ;
151152 }
152153 foreach ($ this ->options as $ value => $ content ) {
154+ $ value = strval ($ value );
153155 $ id = $ this ->name . '- ' . $ value ;
154156 $ label = Element::label ($ content )->props ('for ' . $ id );
155157 $ input = Element::input ()->omitEndTag ()->props (
Original file line number Diff line number Diff line change @@ -118,4 +118,25 @@ public function is_expected_base(): void // phpcs:ignore
118118
119119 $ this ->assertSame ($ expected , $ result );
120120 }
121+
122+ /**
123+ * @test
124+ */
125+ public function error_is_selected_value_always_string (): void // phpcs:ignore
126+ {
127+ $ expected = <<<html
128+ <div><label for="select">Select your option</label><select id="select" name="select"><option value="0">display</option></select></div>
129+ html ;
130+
131+ // Even with strict types, number-based keys become integers
132+ $ result = (string ) Select::create (
133+ 'Select your option ' ,
134+ 'select ' ,
135+ [
136+ '0 ' => 'display '
137+ ]
138+ );
139+
140+ $ this ->assertSame ($ expected , $ result );
141+ }
121142}
You can’t perform that action at this time.
0 commit comments