diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-08-25 08:49:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-25 08:49:34 -0700 |
commit | c7457ef65a7a8584b1e3bd396c401ccf8e275ffa (patch) | |
tree | a142f1ed092807b1bd38683f57e37bcf852f665a /php/tests/well_known_test.php | |
parent | 98a3734b5aa680f565af10a5fd4430baa4b4aa10 (diff) | |
download | protobuf-c7457ef65a7a8584b1e3bd396c401ccf8e275ffa.tar.gz protobuf-c7457ef65a7a8584b1e3bd396c401ccf8e275ffa.tar.bz2 protobuf-c7457ef65a7a8584b1e3bd396c401ccf8e275ffa.zip |
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
Diffstat (limited to 'php/tests/well_known_test.php')
-rw-r--r-- | php/tests/well_known_test.php | 74 |
1 files changed, 73 insertions, 1 deletions
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 @@ <?php +require_once('test_base.php'); +require_once('test_util.php'); + use Google\Protobuf\GPBEmpty; +use Google\Protobuf\Any; + +use Foo\TestMessage; + +class NotMessage {} -class WellKnownTest extends PHPUnit_Framework_TestCase { +class WellKnownTest extends TestBase { public function testNone() { @@ -14,4 +22,68 @@ class WellKnownTest extends PHPUnit_Framework_TestCase { $msg = new TestImportDescriptorProto(); } + public function testAny() + { + // Create embed message + $embed = new TestMessage(); + $this->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(); + } } |