diff options
author | Bo Yang <teboring@google.com> | 2018-08-10 18:09:02 +0000 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2018-08-10 18:09:02 +0000 |
commit | e3ee7167f15206a6e1d27b22ac58c69fc4ceee2b (patch) | |
tree | cd5878e49531c97ab20d6f08eabc61dfdda2dd01 /php/tests/encode_decode_test.php | |
parent | bdcbcabe5e123067ad2474994df343d0458b63ea (diff) | |
download | protobuf-e3ee7167f15206a6e1d27b22ac58c69fc4ceee2b.tar.gz protobuf-e3ee7167f15206a6e1d27b22ac58c69fc4ceee2b.tar.bz2 protobuf-e3ee7167f15206a6e1d27b22ac58c69fc4ceee2b.zip |
Fix json parsing of wrapper values
Diffstat (limited to 'php/tests/encode_decode_test.php')
-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() { |