Exemplo n.º 1
0
 public function testConvertMapEntry()
 {
     $setEntry = new ProtoBuf\MapEntry();
     $setField = new ProtoBuf\MapField();
     $mapEntry = new ProtoBuf\MapEntry();
     $mapField = new ProtoBuf\MapField();
     $flagEntry = new ProtoBuf\MapEntry();
     $flagField = new ProtoBuf\MapField();
     $counterEntry = new ProtoBuf\MapEntry();
     $counterField = new ProtoBuf\MapField();
     $registerEntry = new ProtoBuf\MapEntry();
     $registerField = new ProtoBuf\MapField();
     $mapEntryValues[0] = new ProtoBuf\MapEntry();
     $mapEntryValues[0]->setField(new ProtoBuf\MapField());
     $mapEntryValues[0]->field->setName('sub_map_field');
     $mapEntryValues[0]->field->setType(MapFieldType::REGISTER);
     $mapEntryValues[0]->setRegisterValue('sub-map-register-val');
     $mapEntry->setField($mapField);
     $mapEntry->setMapValue($mapEntryValues);
     $mapField->setName('map_field');
     $mapField->setType(MapFieldType::MAP);
     $setEntry->setField($setField);
     $setEntry->setSetValue([1, 2, 3]);
     $setField->setName('set_field');
     $setField->setType(MapFieldType::SET);
     $flagEntry->setField($flagField);
     $flagEntry->setFlagValue(ProtoBuf\MapUpdate\FlagOp::ENABLE);
     $flagField->setName('flag_field');
     $flagField->setType(MapFieldType::FLAG);
     $counterEntry->setField($counterField);
     $counterEntry->setCounterValue(10);
     $counterField->setName('counter_field');
     $counterField->setType(MapFieldType::COUNTER);
     $registerEntry->setField($registerField);
     $registerEntry->setRegisterValue('register-val');
     $registerField->setName('register_field');
     $registerField->setType(MapFieldType::REGISTER);
     $mapResult = $this->instance->convertMapEntry($mapEntry);
     $setResult = $this->instance->convertMapEntry($setEntry);
     $flagResult = $this->instance->convertMapEntry($flagEntry);
     $counterResult = $this->instance->convertMapEntry($counterEntry);
     $registerResult = $this->instance->convertMapEntry($registerEntry);
     $this->assertTrue($flagResult);
     $this->assertEquals(10, $counterResult);
     $this->assertEquals([1, 2, 3], $setResult);
     $this->assertEquals('register-val', $registerResult);
     $this->assertArrayHasKey('sub_map_field', $mapResult);
     $this->assertEquals('sub-map-register-val', $mapResult['sub_map_field']);
 }