public function testWriteComplexMessage()
 {
     $phone1 = new PhoneNumber();
     $phone2 = new PhoneNumber();
     $phone3 = new PhoneNumber();
     $book = new AddressBook();
     $person1 = new Person();
     $person2 = new Person();
     $person1->setId(2051);
     $person1->setName('John Doe');
     $person1->setEmail('*****@*****.**');
     $person2->setId(23);
     $person2->setName('Iván Montes');
     $person2->setEmail('*****@*****.**');
     $book->addPerson($person1);
     $book->addPerson($person2);
     $person1->addPhone($phone1);
     $person1->addPhone($phone2);
     $phone1->setNumber('1231231212');
     $phone1->setType(PhoneType::HOME());
     $phone2->setNumber('55512321312');
     $phone2->setType(PhoneType::MOBILE());
     $phone3->setNumber('3493123123');
     $phone3->setType(PhoneType::WORK());
     $person2->addPhone($phone3);
     $expected = $this->getProtoContent('addressbook.bin');
     $actual = $book->toStream();
     $this->assertEquals($expected, (string) $actual);
     $this->assertSerializedMessageSize($expected, $book);
 }
Example #2
0
 public function testFormatComplexMessage()
 {
     $book = new AddressBook();
     $person = new Person();
     $person->setId(2051);
     $person->setName('John Doe');
     $person->setEmail('*****@*****.**');
     $phone = new Person\PhoneNumber();
     $phone->setNumber('1231231212');
     $phone->setType(Person\PhoneType::HOME());
     $person->addPhone($phone);
     $phone = new Person\PhoneNumber();
     $phone->setNumber('55512321312');
     $phone->setType(Person\PhoneType::MOBILE());
     $person->addPhone($phone);
     $book->addPerson($person);
     $person = new Person();
     $person->setId(23);
     $person->setName('Iván Montes');
     $person->setEmail('*****@*****.**');
     $phone = new Person\PhoneNumber();
     $phone->setNumber('3493123123');
     $phone->setType(Person\PhoneType::WORK());
     $person->addPhone($phone);
     $book->addPerson($person);
     $expected = $this->getProtoContent('addressbook.txt');
     $actual = $this->textFormat->encodeMessage($book);
     $this->assertEquals($expected, (string) $actual);
 }