Fixed clone for Message, RepeatedField, and MapField. (#8245)
Also updated the code to use a TypeInfo struct for convenient
passing of type and desc together. This simplified a lot of code
and made this change easier to write.
diff --git a/php/tests/GeneratedClassTest.php b/php/tests/GeneratedClassTest.php
index d1836a9..f2a9fb0 100644
--- a/php/tests/GeneratedClassTest.php
+++ b/php/tests/GeneratedClassTest.php
@@ -1526,6 +1526,28 @@
}
#########################################################
+ # Test clone.
+ #########################################################
+
+ public function testClone()
+ {
+ $m = new TestMessage([
+ 'optional_int32' => -42,
+ 'optional_int64' => -43,
+ 'optional_message' => new Sub([
+ 'a' => 33
+ ]),
+ 'map_int32_message' => [1 => new Sub(['a' => 36])],
+ ]);
+ $m2 = clone $m;
+ $this->assertEquals($m->getOptionalInt32(), $m2->getOptionalInt32());
+ $this->assertEquals($m->getOptionalInt64(), $m2->getOptionalInt64());
+ $this->assertSame($m->getOptionalMessage(), $m2->getOptionalMessage());
+ $this->assertSame($m->getMapInt32Message()[1], $m2->getMapInt32Message()[1]);
+ $this->assertEquals($m->serializeToJsonString(), $m2->serializeToJsonString());
+ }
+
+ #########################################################
# Test message equals.
#########################################################