@@ -209,6 +209,63 @@ public function testOptionalInt32Field()
209209 $ this ->assertSame (0 , $ m ->getTrueOptionalInt32 ());
210210 }
211211
212+ #########################################################
213+ # Test values that are converted by setter
214+ #########################################################
215+
216+ public function testConvertValueSetter ()
217+ {
218+ // convert null
219+ $ m_null = new TestMessage ();
220+
221+ $ m_null ->setOptionalBool (null );
222+ $ m_null ->setOptionalBytes (null );
223+ $ m_null ->setOptionalString (null );
224+ $ m_null ->setTrueOptionalBool (null );
225+ $ m_null ->setTrueOptionalBytes (null );
226+ $ m_null ->setTrueOptionalString (null );
227+ // allow null message
228+ $ m_null ->setOptionalMessage (null );
229+ $ m_null ->setTrueOptionalMessage (null );
230+
231+ $ this ->assertSame (false , $ m_null ->getOptionalBool ());
232+ $ this ->assertSame ('' , $ m_null ->getOptionalString ());
233+ $ this ->assertSame ('' , $ m_null ->getOptionalBytes ());
234+ $ this ->assertNull ($ m_null ->getOptionalMessage ());
235+
236+ $ this ->assertSame (false , $ m_null ->getTrueOptionalBool ());
237+ $ this ->assertSame ('' , $ m_null ->getTrueOptionalString ());
238+ $ this ->assertSame ('' , $ m_null ->getTrueOptionalBytes ());
239+ $ this ->assertNull ($ m_null ->getTrueOptionalMessage ());
240+
241+ // Convert int
242+ $ m_number = new TestMessage ();
243+
244+ $ m_number ->setOptionalBool (0 );
245+ $ m_number ->setOptionalBytes (0 );
246+ $ m_number ->setOptionalString (0 );
247+ $ m_number ->setTrueOptionalBool (1 );
248+ $ m_number ->setTrueOptionalBytes (1 );
249+ $ m_number ->setTrueOptionalString (1 );
250+
251+ $ this ->assertSame (false , $ m_number ->getOptionalBool ());
252+ $ this ->assertSame ('0 ' , $ m_number ->getOptionalString ());
253+ $ this ->assertSame ('0 ' , $ m_number ->getOptionalBytes ());
254+
255+ $ this ->assertSame (true , $ m_number ->getTrueOptionalBool ());
256+ $ this ->assertSame ('1 ' , $ m_number ->getTrueOptionalString ());
257+ $ this ->assertSame ('1 ' , $ m_number ->getTrueOptionalBytes ());
258+
259+ // Convert str
260+ $ m_number_str = new TestMessage ();
261+
262+ $ m_number_str ->setOptionalBool ('' );
263+ $ m_number_str ->setTrueOptionalBool ('STR ' );
264+
265+ $ this ->assertSame (false , $ m_number_str ->getOptionalBool ());
266+ $ this ->assertSame (true , $ m_number_str ->getTrueOptionalBool ());
267+ }
268+
212269 #########################################################
213270 # Test uint32 field.
214271 #########################################################
0 commit comments