diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2018-08-13 13:36:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-13 13:36:08 -0700 |
commit | 585b24e9a6a902a3dda2091ae51f9c9463295c32 (patch) | |
tree | 24120d6f3e6e98c4223fd249c3e782461656af81 /php/tests | |
parent | ba8692fbade4ba329cc4531e286ab5a8e0821d97 (diff) | |
parent | e3ee7167f15206a6e1d27b22ac58c69fc4ceee2b (diff) | |
download | protobuf-585b24e9a6a902a3dda2091ae51f9c9463295c32.tar.gz protobuf-585b24e9a6a902a3dda2091ae51f9c9463295c32.tar.bz2 protobuf-585b24e9a6a902a3dda2091ae51f9c9463295c32.zip |
Merge pull request #5032 from TeBoring/json-wrapper
Fix json parsing of wrapper values
Diffstat (limited to 'php/tests')
-rw-r--r-- | php/tests/encode_decode_test.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index d36b883e..870dacab 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -11,9 +11,90 @@ use Foo\TestMessage\Sub; use Foo\TestPackedMessage; use Foo\TestRandomFieldOrder; use Foo\TestUnpackedMessage; +use Google\Protobuf\DoubleValue; +use Google\Protobuf\FloatValue; +use Google\Protobuf\Int32Value; +use Google\Protobuf\UInt32Value; +use Google\Protobuf\Int64Value; +use Google\Protobuf\UInt64Value; +use Google\Protobuf\BoolValue; +use Google\Protobuf\StringValue; +use Google\Protobuf\BytesValue; class EncodeDecodeTest extends TestBase { + public function testDecodeJsonSimple() + { + $m = new TestMessage(); + $m->mergeFromJsonString("{\"optionalInt32\":1}"); + } + + public function testDecodeTopLevelBoolValue() + { + $m = new BoolValue(); + + $m->mergeFromJsonString("true"); + $this->assertEquals(true, $m->getValue()); + + $m->mergeFromJsonString("false"); + $this->assertEquals(false, $m->getValue()); + } + + public function testDecodeTopLevelDoubleValue() + { + $m = new DoubleValue(); + $m->mergeFromJsonString("1.5"); + $this->assertEquals(1.5, $m->getValue()); + } + + public function testDecodeTopLevelFloatValue() + { + $m = new FloatValue(); + $m->mergeFromJsonString("1.5"); + $this->assertEquals(1.5, $m->getValue()); + } + + public function testDecodeTopLevelInt32Value() + { + $m = new Int32Value(); + $m->mergeFromJsonString("1"); + $this->assertEquals(1, $m->getValue()); + } + + public function testDecodeTopLevelUInt32Value() + { + $m = new UInt32Value(); + $m->mergeFromJsonString("1"); + $this->assertEquals(1, $m->getValue()); + } + + public function testDecodeTopLevelInt64Value() + { + $m = new Int64Value(); + $m->mergeFromJsonString("1"); + $this->assertEquals(1, $m->getValue()); + } + + public function testDecodeTopLevelUInt64Value() + { + $m = new UInt64Value(); + $m->mergeFromJsonString("1"); + $this->assertEquals(1, $m->getValue()); + } + + public function testDecodeTopLevelStringValue() + { + $m = new StringValue(); + $m->mergeFromJsonString("\"a\""); + $this->assertSame("a", $m->getValue()); + } + + public function testDecodeTopLevelBytesValue() + { + $m = new BytesValue(); + $m->mergeFromJsonString("\"YQ==\""); + $this->assertSame("a", $m->getValue()); + } public function testEncode() { |