@@ -249,6 +249,63 @@ public function testOptionalInt32Field()
249249 $ this ->assertSame (0 , $ m ->getTrueOptionalInt32 ());
250250 }
251251
252+ #########################################################
253+ # Test values that are converted by setter
254+ #########################################################
255+
256+ public function testConvertValueSetter ()
257+ {
258+ // convert null
259+ $ m_null = new TestMessage ();
260+
261+ $ m_null ->setOptionalBool (null );
262+ $ m_null ->setOptionalBytes (null );
263+ $ m_null ->setOptionalString (null );
264+ $ m_null ->setTrueOptionalBool (null );
265+ $ m_null ->setTrueOptionalBytes (null );
266+ $ m_null ->setTrueOptionalString (null );
267+ // allow null message
268+ $ m_null ->setOptionalMessage (null );
269+ $ m_null ->setTrueOptionalMessage (null );
270+
271+ $ this ->assertSame (false , $ m_null ->getOptionalBool ());
272+ $ this ->assertSame ('' , $ m_null ->getOptionalString ());
273+ $ this ->assertSame ('' , $ m_null ->getOptionalBytes ());
274+ $ this ->assertNull ($ m_null ->getOptionalMessage ());
275+
276+ $ this ->assertSame (false , $ m_null ->getTrueOptionalBool ());
277+ $ this ->assertSame ('' , $ m_null ->getTrueOptionalString ());
278+ $ this ->assertSame ('' , $ m_null ->getTrueOptionalBytes ());
279+ $ this ->assertNull ($ m_null ->getTrueOptionalMessage ());
280+
281+ // Convert int
282+ $ m_number = new TestMessage ();
283+
284+ $ m_number ->setOptionalBool (0 );
285+ $ m_number ->setOptionalBytes (0 );
286+ $ m_number ->setOptionalString (0 );
287+ $ m_number ->setTrueOptionalBool (1 );
288+ $ m_number ->setTrueOptionalBytes (1 );
289+ $ m_number ->setTrueOptionalString (1 );
290+
291+ $ this ->assertSame (false , $ m_number ->getOptionalBool ());
292+ $ this ->assertSame ('0 ' , $ m_number ->getOptionalString ());
293+ $ this ->assertSame ('0 ' , $ m_number ->getOptionalBytes ());
294+
295+ $ this ->assertSame (true , $ m_number ->getTrueOptionalBool ());
296+ $ this ->assertSame ('1 ' , $ m_number ->getTrueOptionalString ());
297+ $ this ->assertSame ('1 ' , $ m_number ->getTrueOptionalBytes ());
298+
299+ // Convert str
300+ $ m_number_str = new TestMessage ();
301+
302+ $ m_number_str ->setOptionalBool ('' );
303+ $ m_number_str ->setTrueOptionalBool ('STR ' );
304+
305+ $ this ->assertSame (false , $ m_number_str ->getOptionalBool ());
306+ $ this ->assertSame (true , $ m_number_str ->getTrueOptionalBool ());
307+ }
308+
252309 #########################################################
253310 # Test uint32 field.
254311 #########################################################
0 commit comments