Commit 703cd8e1 authored by Ryan Gordon's avatar Ryan Gordon Committed by Paul Yang

Switch to addEnumType to fix fatal error (#3225)

* Switch to addEnumType to fix fatal error

* Fixing more cases of HHVM incompatibility

* Updating tests to be hhvm compatible

* Fixing tests

* Fixing merge

* Don't use call_user_func, should hopefully fix tests

* Fixing spelling

* Fixing another misspelling in a test

* Fixing placement of append and kvUpdate functions

* Actually fix function helpers

* Remove double addEnumType. How did this ever work?

* Fixing a couple more tests

* Only use the setter if the return value isn't an object
parent 13255889
...@@ -78,7 +78,6 @@ class FileDescriptor ...@@ -78,7 +78,6 @@ class FileDescriptor
$message_proto, $proto, "")); $message_proto, $proto, ""));
} }
foreach ($proto->getEnumType() as $enum_proto) { foreach ($proto->getEnumType() as $enum_proto) {
$file->getEnumType()[] =
$file->addEnumType( $file->addEnumType(
EnumDescriptor::buildFromProto( EnumDescriptor::buildFromProto(
$enum_proto, $enum_proto,
......
...@@ -373,7 +373,7 @@ class Message ...@@ -373,7 +373,7 @@ class Message
$getter = $field->getGetter(); $getter = $field->getGetter();
while ($input->bytesUntilLimit() > 0) { while ($input->bytesUntilLimit() > 0) {
self::parseFieldFromStreamNoTag($input, $field, $value); self::parseFieldFromStreamNoTag($input, $field, $value);
$this->$getter()[] = $value; $this->appendHelper($field, $value);
} }
$input->popLimit($limit); $input->popLimit($limit);
return; return;
...@@ -382,11 +382,9 @@ class Message ...@@ -382,11 +382,9 @@ class Message
} }
if ($field->isMap()) { if ($field->isMap()) {
$getter = $field->getGetter(); $this->kvUpdateHelper($field, $value->getKey(), $value->getValue());
$this->$getter()[$value->getKey()] = $value->getValue();
} else if ($field->isRepeated()) { } else if ($field->isRepeated()) {
$getter = $field->getGetter(); $this->appendHelper($field, $value);
$this->$getter()[] = $value;
} else { } else {
$setter = $field->getSetter(); $setter = $field->getSetter();
$this->$setter($value); $this->$setter($value);
...@@ -533,9 +531,10 @@ class Message ...@@ -533,9 +531,10 @@ class Message
$klass = $value_field->getMessageType()->getClass(); $klass = $value_field->getMessageType()->getClass();
$copy = new $klass; $copy = new $klass;
$copy->mergeFrom($value); $copy->mergeFrom($value);
$this->$getter()[$key] = $copy;
$this->kvUpdateHelper($field, $key, $copy);
} else { } else {
$this->$getter()[$key] = $value; $this->kvUpdateHelper($field, $key, $value);
} }
} }
} }
...@@ -546,9 +545,9 @@ class Message ...@@ -546,9 +545,9 @@ class Message
$klass = $field->getMessageType()->getClass(); $klass = $field->getMessageType()->getClass();
$copy = new $klass; $copy = new $klass;
$copy->mergeFrom($tmp); $copy->mergeFrom($tmp);
$this->$getter()[] = $copy; $this->appendHelper($field, $copy);
} else { } else {
$this->$getter()[] = $tmp; $this->appendHelper($field, $tmp);
} }
} }
} }
...@@ -896,4 +895,30 @@ class Message ...@@ -896,4 +895,30 @@ class Message
} }
return $size; return $size;
} }
private function appendHelper($field, $append_value)
{
$getter = $field->getGetter();
$setter = $field->getSetter();
$field_arr_value = $this->$getter();
$field_arr_value[] = $append_value;
if (!is_object($field_arr_value)) {
$this->$setter($field_arr_value);
}
}
private function kvUpdateHelper($field, $update_key, $update_value)
{
$getter = $field->getGetter();
$setter = $field->getSetter();
$field_arr_value = $this->$getter();
$field_arr_value[$update_key] = $update_value;
if (!is_object($field_arr_value)) {
$this->$setter($field_arr_value);
}
}
} }
...@@ -743,24 +743,44 @@ class GeneratedClassTest extends TestBase ...@@ -743,24 +743,44 @@ class GeneratedClassTest extends TestBase
$n->setOptionalInt32(100); $n->setOptionalInt32(100);
$sub1 = new TestMessage_Sub(); $sub1 = new TestMessage_Sub();
$sub1->setA(101); $sub1->setA(101);
$sub1->getB()[] = 102;
$b = $sub1->getB();
$b[] = 102;
$sub1->setB($b);
$n->setOptionalMessage($sub1); $n->setOptionalMessage($sub1);
// Repeated // Repeated
$n->getRepeatedInt32()[] = 200; $repeatedInt32 = $n->getRepeatedInt32();
$n->getRepeatedString()[] = 'abc'; $repeatedInt32[] = 200;
$n->setRepeatedInt32($repeatedInt32);
$repeatedString = $n->getRepeatedString();
$repeatedString[] = 'abc';
$n->setRepeatedString($repeatedString);
$sub2 = new TestMessage_Sub(); $sub2 = new TestMessage_Sub();
$sub2->setA(201); $sub2->setA(201);
$n->getRepeatedMessage()[] = $sub2; $repeatedMessage = $n->getRepeatedMessage();
$repeatedMessage[] = $sub2;
$n->setRepeatedMessage($repeatedMessage);
// Map // Map
$n->getMapInt32Int32()[1] = 300; $mapInt32Int32 = $n->getMapInt32Int32();
$n->getMapInt32Int32()[-62] = 301; $mapInt32Int32[1] = 300;
$n->getMapStringString()['def'] = 'def'; $mapInt32Int32[-62] = 301;
$n->getMapInt32Message()[1] = new TestMessage_Sub(); $n->setMapInt32Int32($mapInt32Int32);
$n->getMapInt32Message()[1]->setA(302);
$n->getMapInt32Message()[2] = new TestMessage_Sub(); $mapStringString = $n->getMapStringString();
$n->getMapInt32Message()[2]->setA(303); $mapStringString['def'] = 'def';
$n->setMapStringString($mapStringString);
$mapInt32Message = $n->getMapInt32Message();
$mapInt32Message[1] = new TestMessage_Sub();
$mapInt32Message[1]->setA(302);
$mapInt32Message[2] = new TestMessage_Sub();
$mapInt32Message[2]->setA(303);
$n->setMapInt32Message($mapInt32Message);
$m->mergeFrom($n); $m->mergeFrom($n);
...@@ -795,9 +815,16 @@ class GeneratedClassTest extends TestBase ...@@ -795,9 +815,16 @@ class GeneratedClassTest extends TestBase
// Check sub-messages are copied by value. // Check sub-messages are copied by value.
$n->getOptionalMessage()->setA(-101); $n->getOptionalMessage()->setA(-101);
$this->assertSame(101, $m->getOptionalMessage()->getA()); $this->assertSame(101, $m->getOptionalMessage()->getA());
$n->getRepeatedMessage()[0]->setA(-201);
$repeatedMessage = $n->getRepeatedMessage();
$repeatedMessage[0]->setA(-201);
$n->setRepeatedMessage($repeatedMessage);
$this->assertSame(201, $m->getRepeatedMessage()[2]->getA()); $this->assertSame(201, $m->getRepeatedMessage()[2]->getA());
$n->getMapInt32Message()[1]->setA(-302);
$mapInt32Message = $n->getMapInt32Message();
$mapInt32Message[1]->setA(-302);
$n->setMapInt32Message($mapInt32Message);
$this->assertSame(302, $m->getMapInt32Message()[1]->getA()); $this->assertSame(302, $m->getMapInt32Message()[1]->getA());
// Test merge oneof. // Test merge oneof.
...@@ -843,7 +870,9 @@ class GeneratedClassTest extends TestBase ...@@ -843,7 +870,9 @@ class GeneratedClassTest extends TestBase
$m = new TestMessage(); $m = new TestMessage();
$sub = new NoNameSpaceMessage(); $sub = new NoNameSpaceMessage();
$m->setOptionalNoNamespaceMessage($sub); $m->setOptionalNoNamespaceMessage($sub);
$m->getRepeatedNoNamespaceMessage()[] = new NoNameSpaceMessage(); $repeatedNoNamespaceMessage = $m->getRepeatedNoNamespaceMessage();
$repeatedNoNamespaceMessage[] = new NoNameSpaceMessage();
$m->setRepeatedNoNamespaceMessage($repeatedNoNamespaceMessage);
$n = new NoNamespaceMessage(); $n = new NoNamespaceMessage();
$n->setB(NoNamespaceMessage_NestedEnum::ZERO); $n->setB(NoNamespaceMessage_NestedEnum::ZERO);
...@@ -853,7 +882,9 @@ class GeneratedClassTest extends TestBase ...@@ -853,7 +882,9 @@ class GeneratedClassTest extends TestBase
{ {
$m = new TestMessage(); $m = new TestMessage();
$m->setOptionalNoNamespaceEnum(NoNameSpaceEnum::VALUE_A); $m->setOptionalNoNamespaceEnum(NoNameSpaceEnum::VALUE_A);
$m->getRepeatedNoNamespaceEnum()[] = NoNameSpaceEnum::VALUE_A; $repeatedNoNamespaceEnum = $m->getRepeatedNoNamespaceEnum();
$repeatedNoNamespaceEnum[] = NoNameSpaceEnum::VALUE_A;
$m->setRepeatedNoNamespaceEnum($repeatedNoNamespaceEnum);
} }
######################################################### #########################################################
......
...@@ -71,61 +71,61 @@ class TestUtil ...@@ -71,61 +71,61 @@ class TestUtil
$m->setOptionalMessage($sub); $m->setOptionalMessage($sub);
$m->getOptionalMessage()->SetA(33); $m->getOptionalMessage()->SetA(33);
$m->getRepeatedInt32() []= -42; self::appendHelper($m, 'RepeatedInt32', -42);
$m->getRepeatedInt64() []= -43; self::appendHelper($m, 'RepeatedInt64', -43);
$m->getRepeatedUint32() []= 42; self::appendHelper($m, 'RepeatedUint32', 42);
$m->getRepeatedUint64() []= 43; self::appendHelper($m, 'RepeatedUint64', 43);
$m->getRepeatedSint32() []= -44; self::appendHelper($m, 'RepeatedSint32', -44);
$m->getRepeatedSint64() []= -45; self::appendHelper($m, 'RepeatedSint64', -45);
$m->getRepeatedFixed32() []= 46; self::appendHelper($m, 'RepeatedFixed32', 46);
$m->getRepeatedFixed64() []= 47; self::appendHelper($m, 'RepeatedFixed64', 47);
$m->getRepeatedSfixed32() []= -46; self::appendHelper($m, 'RepeatedSfixed32', -46);
$m->getRepeatedSfixed64() []= -47; self::appendHelper($m, 'RepeatedSfixed64', -47);
$m->getRepeatedFloat() []= 1.5; self::appendHelper($m, 'RepeatedFloat', 1.5);
$m->getRepeatedDouble() []= 1.6; self::appendHelper($m, 'RepeatedDouble', 1.6);
$m->getRepeatedBool() []= true; self::appendHelper($m, 'RepeatedBool', true);
$m->getRepeatedString() []= 'a'; self::appendHelper($m, 'RepeatedString', 'a');
$m->getRepeatedBytes() []= 'b'; self::appendHelper($m, 'RepeatedBytes', 'b');
$m->getRepeatedEnum() []= TestEnum::ZERO; self::appendHelper($m, 'RepeatedEnum', TestEnum::ZERO);
$m->getRepeatedMessage() []= new TestMessage_Sub(); self::appendHelper($m, 'RepeatedMessage', new TestMessage_Sub());
$m->getRepeatedMessage()[0]->setA(34); $m->getRepeatedMessage()[0]->setA(34);
$m->getRepeatedInt32() []= -52; self::appendHelper($m, 'RepeatedInt32', -52);
$m->getRepeatedInt64() []= -53; self::appendHelper($m, 'RepeatedInt64', -53);
$m->getRepeatedUint32() []= 52; self::appendHelper($m, 'RepeatedUint32', 52);
$m->getRepeatedUint64() []= 53; self::appendHelper($m, 'RepeatedUint64', 53);
$m->getRepeatedSint32() []= -54; self::appendHelper($m, 'RepeatedSint32', -54);
$m->getRepeatedSint64() []= -55; self::appendHelper($m, 'RepeatedSint64', -55);
$m->getRepeatedFixed32() []= 56; self::appendHelper($m, 'RepeatedFixed32', 56);
$m->getRepeatedFixed64() []= 57; self::appendHelper($m, 'RepeatedFixed64', 57);
$m->getRepeatedSfixed32() []= -56; self::appendHelper($m, 'RepeatedSfixed32', -56);
$m->getRepeatedSfixed64() []= -57; self::appendHelper($m, 'RepeatedSfixed64', -57);
$m->getRepeatedFloat() []= 2.5; self::appendHelper($m, 'RepeatedFloat', 2.5);
$m->getRepeatedDouble() []= 2.6; self::appendHelper($m, 'RepeatedDouble', 2.6);
$m->getRepeatedBool() []= false; self::appendHelper($m, 'RepeatedBool', false);
$m->getRepeatedString() []= 'c'; self::appendHelper($m, 'RepeatedString', 'c');
$m->getRepeatedBytes() []= 'd'; self::appendHelper($m, 'RepeatedBytes', 'd');
$m->getRepeatedEnum() []= TestEnum::ONE; self::appendHelper($m, 'RepeatedEnum', TestEnum::ONE);
$m->getRepeatedMessage() []= new TestMessage_Sub(); self::appendHelper($m, 'RepeatedMessage', new TestMessage_Sub());
$m->getRepeatedMessage()[1]->SetA(35); $m->getRepeatedMessage()[1]->SetA(35);
$m->getMapInt32Int32()[-62] = -62; self::kvUpdateHelper($m, 'MapInt32Int32', -62, -62);
$m->getMapInt64Int64()[-63] = -63; self::kvUpdateHelper($m, 'MapInt64Int64', -63, -63);
$m->getMapUint32Uint32()[62] = 62; self::kvUpdateHelper($m, 'MapUint32Uint32', 62, 62);
$m->getMapUint64Uint64()[63] = 63; self::kvUpdateHelper($m, 'MapUint64Uint64', 63, 63);
$m->getMapSint32Sint32()[-64] = -64; self::kvUpdateHelper($m, 'MapSint32Sint32', -64, -64);
$m->getMapSint64Sint64()[-65] = -65; self::kvUpdateHelper($m, 'MapSint64Sint64', -65, -65);
$m->getMapFixed32Fixed32()[66] = 66; self::kvUpdateHelper($m, 'MapFixed32Fixed32', 66, 66);
$m->getMapFixed64Fixed64()[67] = 67; self::kvUpdateHelper($m, 'MapFixed64Fixed64', 67, 67);
$m->getMapSfixed32Sfixed32()[-68] = -68; self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -68, -68);
$m->getMapSfixed64Sfixed64()[-69] = -69; self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -69, -69);
$m->getMapInt32Float()[1] = 3.5; self::kvUpdateHelper($m, 'MapInt32Float', 1, 3.5);
$m->getMapInt32Double()[1] = 3.6; self::kvUpdateHelper($m, 'MapInt32Double', 1, 3.6);
$m->getMapBoolBool()[true] = true; self::kvUpdateHelper($m, 'MapBoolBool', true, true);
$m->getMapStringString()['e'] = 'e'; self::kvUpdateHelper($m, 'MapStringString', 'e', 'e');
$m->getMapInt32Bytes()[1] = 'f'; self::kvUpdateHelper($m, 'MapInt32Bytes', 1, 'f');
$m->getMapInt32Enum()[1] = TestEnum::ONE; self::kvUpdateHelper($m, 'MapInt32Enum', 1, TestEnum::ONE);
$m->getMapInt32Message()[1] = new TestMessage_Sub(); self::kvUpdateHelper($m, 'MapInt32Message', 1, new TestMessage_Sub());
$m->getMapInt32Message()[1]->SetA(36); $m->getMapInt32Message()[1]->SetA(36);
} }
...@@ -152,61 +152,61 @@ class TestUtil ...@@ -152,61 +152,61 @@ class TestUtil
$m->setOptionalMessage($sub); $m->setOptionalMessage($sub);
$m->getOptionalMessage()->SetA(133); $m->getOptionalMessage()->SetA(133);
$m->getRepeatedInt32() []= -142; self::appendHelper($m, 'RepeatedInt32', -142);
$m->getRepeatedInt64() []= -143; self::appendHelper($m, 'RepeatedInt64', -143);
$m->getRepeatedUint32() []= 142; self::appendHelper($m, 'RepeatedUint32', 142);
$m->getRepeatedUint64() []= 143; self::appendHelper($m, 'RepeatedUint64', 143);
$m->getRepeatedSint32() []= -144; self::appendHelper($m, 'RepeatedSint32', -144);
$m->getRepeatedSint64() []= -145; self::appendHelper($m, 'RepeatedSint64', -145);
$m->getRepeatedFixed32() []= 146; self::appendHelper($m, 'RepeatedFixed32', 146);
$m->getRepeatedFixed64() []= 147; self::appendHelper($m, 'RepeatedFixed64', 147);
$m->getRepeatedSfixed32() []= -146; self::appendHelper($m, 'RepeatedSfixed32', -146);
$m->getRepeatedSfixed64() []= -147; self::appendHelper($m, 'RepeatedSfixed64', -147);
$m->getRepeatedFloat() []= 11.5; self::appendHelper($m, 'RepeatedFloat', 11.5);
$m->getRepeatedDouble() []= 11.6; self::appendHelper($m, 'RepeatedDouble', 11.6);
$m->getRepeatedBool() []= false; self::appendHelper($m, 'RepeatedBool', false);
$m->getRepeatedString() []= 'aa'; self::appendHelper($m, 'RepeatedString', 'aa');
$m->getRepeatedBytes() []= 'bb'; self::appendHelper($m, 'RepeatedBytes', 'bb');
$m->getRepeatedEnum() []= TestEnum::TWO; self::appendHelper($m, 'RepeatedEnum', TestEnum::TWO);
$m->getRepeatedMessage() []= new TestMessage_Sub(); self::appendHelper($m, 'RepeatedMessage', new TestMessage_Sub());
$m->getRepeatedMessage()[0]->setA(134); $m->getRepeatedMessage()[0]->setA(134);
$m->getMapInt32Int32()[-62] = -162; self::kvUpdateHelper($m, 'MapInt32Int32', -62, -162);
$m->getMapInt64Int64()[-63] = -163; self::kvUpdateHelper($m, 'MapInt64Int64', -63, -163);
$m->getMapUint32Uint32()[62] = 162; self::kvUpdateHelper($m, 'MapUint32Uint32', 62, 162);
$m->getMapUint64Uint64()[63] = 163; self::kvUpdateHelper($m, 'MapUint64Uint64', 63, 163);
$m->getMapSint32Sint32()[-64] = -164; self::kvUpdateHelper($m, 'MapSint32Sint32', -64, -164);
$m->getMapSint64Sint64()[-65] = -165; self::kvUpdateHelper($m, 'MapSint64Sint64', -65, -165);
$m->getMapFixed32Fixed32()[66] = 166; self::kvUpdateHelper($m, 'MapFixed32Fixed32', 66, 166);
$m->getMapFixed64Fixed64()[67] = 167; self::kvUpdateHelper($m, 'MapFixed64Fixed64', 67, 167);
$m->getMapSfixed32Sfixed32()[-68] = -168; self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -68, -168);
$m->getMapSfixed64Sfixed64()[-69] = -169; self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -69, -169);
$m->getMapInt32Float()[1] = 13.5; self::kvUpdateHelper($m, 'MapInt32Float', 1, 13.5);
$m->getMapInt32Double()[1] = 13.6; self::kvUpdateHelper($m, 'MapInt32Double', 1, 13.6);
$m->getMapBoolBool()[true] = false; self::kvUpdateHelper($m, 'MapBoolBool', true, false);
$m->getMapStringString()['e'] = 'ee'; self::kvUpdateHelper($m, 'MapStringString', 'e', 'ee');
$m->getMapInt32Bytes()[1] = 'ff'; self::kvUpdateHelper($m, 'MapInt32Bytes', 1, 'ff');
$m->getMapInt32Enum()[1] = TestEnum::TWO; self::kvUpdateHelper($m, 'MapInt32Enum', 1, TestEnum::TWO);
$m->getMapInt32Message()[1] = new TestMessage_Sub(); self::kvUpdateHelper($m, 'MapInt32Message', 1, new TestMessage_Sub());
$m->getMapInt32Message()[1]->SetA(136); $m->getMapInt32Message()[1]->SetA(136);
$m->getMapInt32Int32()[-162] = -162; self::kvUpdateHelper($m, 'MapInt32Int32', -162, -162);
$m->getMapInt64Int64()[-163] = -163; self::kvUpdateHelper($m, 'MapInt64Int64', -163, -163);
$m->getMapUint32Uint32()[162] = 162; self::kvUpdateHelper($m, 'MapUint32Uint32', 162, 162);
$m->getMapUint64Uint64()[163] = 163; self::kvUpdateHelper($m, 'MapUint64Uint64', 163, 163);
$m->getMapSint32Sint32()[-164] = -164; self::kvUpdateHelper($m, 'MapSint32Sint32', -164, -164);
$m->getMapSint64Sint64()[-165] = -165; self::kvUpdateHelper($m, 'MapSint64Sint64', -165, -165);
$m->getMapFixed32Fixed32()[166] = 166; self::kvUpdateHelper($m, 'MapFixed32Fixed32', 166, 166);
$m->getMapFixed64Fixed64()[167] = 167; self::kvUpdateHelper($m, 'MapFixed64Fixed64', 167, 167);
$m->getMapSfixed32Sfixed32()[-168] = -168; self::kvUpdateHelper($m, 'MapSfixed32Sfixed32', -168, -168);
$m->getMapSfixed64Sfixed64()[-169] = -169; self::kvUpdateHelper($m, 'MapSfixed64Sfixed64', -169, -169);
$m->getMapInt32Float()[2] = 13.5; self::kvUpdateHelper($m, 'MapInt32Float', 2, 13.5);
$m->getMapInt32Double()[2] = 13.6; self::kvUpdateHelper($m, 'MapInt32Double', 2, 13.6);
$m->getMapBoolBool()[false] = false; self::kvUpdateHelper($m, 'MapBoolBool', false, false);
$m->getMapStringString()['ee'] = 'ee'; self::kvUpdateHelper($m, 'MapStringString', 'ee', 'ee');
$m->getMapInt32Bytes()[2] = 'ff'; self::kvUpdateHelper($m, 'MapInt32Bytes', 2, 'ff');
$m->getMapInt32Enum()[2] = TestEnum::TWO; self::kvUpdateHelper($m, 'MapInt32Enum', 2, TestEnum::TWO);
$m->getMapInt32Message()[2] = new TestMessage_Sub(); self::kvUpdateHelper($m, 'MapInt32Message', 2, new TestMessage_Sub());
$m->getMapInt32Message()[2]->SetA(136); $m->getMapInt32Message()[2]->SetA(136);
} }
...@@ -395,34 +395,34 @@ class TestUtil ...@@ -395,34 +395,34 @@ class TestUtil
public static function setTestPackedMessage($m) public static function setTestPackedMessage($m)
{ {
$m->getRepeatedInt32()[] = -42; self::appendHelper($m, 'RepeatedInt32', -42);
$m->getRepeatedInt32()[] = -52; self::appendHelper($m, 'RepeatedInt32', -52);
$m->getRepeatedInt64()[] = -43; self::appendHelper($m, 'RepeatedInt64', -43);
$m->getRepeatedInt64()[] = -53; self::appendHelper($m, 'RepeatedInt64', -53);
$m->getRepeatedUint32()[] = 42; self::appendHelper($m, 'RepeatedUint32', 42);
$m->getRepeatedUint32()[] = 52; self::appendHelper($m, 'RepeatedUint32', 52);
$m->getRepeatedUint64()[] = 43; self::appendHelper($m, 'RepeatedUint64', 43);
$m->getRepeatedUint64()[] = 53; self::appendHelper($m, 'RepeatedUint64', 53);
$m->getRepeatedSint32()[] = -44; self::appendHelper($m, 'RepeatedSint32', -44);
$m->getRepeatedSint32()[] = -54; self::appendHelper($m, 'RepeatedSint32', -54);
$m->getRepeatedSint64()[] = -45; self::appendHelper($m, 'RepeatedSint64', -45);
$m->getRepeatedSint64()[] = -55; self::appendHelper($m, 'RepeatedSint64', -55);
$m->getRepeatedFixed32()[] = 46; self::appendHelper($m, 'RepeatedFixed32', 46);
$m->getRepeatedFixed32()[] = 56; self::appendHelper($m, 'RepeatedFixed32', 56);
$m->getRepeatedFixed64()[] = 47; self::appendHelper($m, 'RepeatedFixed64', 47);
$m->getRepeatedFixed64()[] = 57; self::appendHelper($m, 'RepeatedFixed64', 57);
$m->getRepeatedSfixed32()[] = -46; self::appendHelper($m, 'RepeatedSfixed32', -46);
$m->getRepeatedSfixed32()[] = -56; self::appendHelper($m, 'RepeatedSfixed32', -56);
$m->getRepeatedSfixed64()[] = -47; self::appendHelper($m, 'RepeatedSfixed64', -47);
$m->getRepeatedSfixed64()[] = -57; self::appendHelper($m, 'RepeatedSfixed64', -57);
$m->getRepeatedFloat()[] = 1.5; self::appendHelper($m, 'RepeatedFloat', 1.5);
$m->getRepeatedFloat()[] = 2.5; self::appendHelper($m, 'RepeatedFloat', 2.5);
$m->getRepeatedDouble()[] = 1.6; self::appendHelper($m, 'RepeatedDouble', 1.6);
$m->getRepeatedDouble()[] = 2.6; self::appendHelper($m, 'RepeatedDouble', 2.6);
$m->getRepeatedBool()[] = true; self::appendHelper($m, 'RepeatedBool', true);
$m->getRepeatedBool()[] = false; self::appendHelper($m, 'RepeatedBool', false);
$m->getRepeatedEnum()[] = TestEnum::ONE; self::appendHelper($m, 'RepeatedEnum', TestEnum::ONE);
$m->getRepeatedEnum()[] = TestEnum::ZERO; self::appendHelper($m, 'RepeatedEnum', TestEnum::ZERO);
} }
public static function assertTestPackedMessage($m) public static function assertTestPackedMessage($m)
...@@ -524,4 +524,24 @@ class TestUtil ...@@ -524,4 +524,24 @@ class TestUtil
"B80601B80600" "B80601B80600"
); );
} }
private static function appendHelper($obj, $func_suffix, $value)
{
$getter_function = 'get'.$func_suffix;
$setter_function = 'set'.$func_suffix;
$arr = $obj->$getter_function();
$arr[] = $value;
$obj->$setter_function($arr);
}
private static function kvUpdateHelper($obj, $func_suffix, $key, $value)
{
$getter_function = 'get'.$func_suffix;
$setter_function = 'set'.$func_suffix;
$arr = $obj->$getter_function();
$arr[$key] = $value;
$obj->$setter_function($arr);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment