From c7457ef65a7a8584b1e3bd396c401ccf8e275ffa Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 25 Aug 2017 08:49:34 -0700 Subject: Add any support in php runtime. (#3486) * Add any support in php runtime. * Remove unused file in config.m4 * Fix comments * Fix error for tsrmls build * Add newly added file to Makefile.am --- php/tests/gdb_test.sh | 2 +- php/tests/well_known_test.php | 74 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) (limited to 'php/tests') diff --git a/php/tests/gdb_test.sh b/php/tests/gdb_test.sh index 484e2edf..0809bef3 100755 --- a/php/tests/gdb_test.sh +++ b/php/tests/gdb_test.sh @@ -3,7 +3,7 @@ # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which # phpunit` --bootstrap autoload.php tmp_test.php # -gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php encode_decode_test.php +gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php well_known_test.php # # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php # diff --git a/php/tests/well_known_test.php b/php/tests/well_known_test.php index 0c2aec13..bdf41bfb 100644 --- a/php/tests/well_known_test.php +++ b/php/tests/well_known_test.php @@ -1,8 +1,16 @@ setFields($embed); + $data = $embed->serializeToString(); + + // Set any via normal setter. + $any = new Any(); + + $this->assertSame( + $any, $any->setTypeUrl("type.googleapis.com/foo.TestMessage")); + $this->assertSame("type.googleapis.com/foo.TestMessage", + $any->getTypeUrl()); + + $this->assertSame($any, $any->setValue($data)); + $this->assertSame($data, $any->getValue()); + + // Test unpack. + $msg = $any->unpack(); + $this->assertTrue($msg instanceof TestMessage); + $this->expectFields($msg); + + // Test pack. + $any = new Any(); + $any->pack($embed); + $this->assertSame($data, $any->getValue()); + $this->assertSame("type.googleapis.com/foo.TestMessage", $any->getTypeUrl()); + + // Test is. + $this->assertTrue($any->is(TestMessage::class)); + $this->assertFalse($any->is(Any::class)); + } + + /** + * @expectedException Exception + */ + public function testAnyUnpackInvalidTypeUrl() + { + $any = new Any(); + $any->setTypeUrl("invalid"); + $any->unpack(); + } + + /** + * @expectedException Exception + */ + public function testAnyUnpackMessageNotAdded() + { + $any = new Any(); + $any->setTypeUrl("type.googleapis.com/MessageNotAdded"); + $any->unpack(); + } + + /** + * @expectedException Exception + */ + public function testAnyUnpackDecodeError() + { + $any = new Any(); + $any->setTypeUrl("type.googleapis.com/foo.TestMessage"); + $any->setValue("abc"); + $any->unpack(); + } } -- cgit v1.2.3