Unverified Commit d2d4b403 authored by Paul Yang's avatar Paul Yang Committed by GitHub

Sync upb for unknown fix (#5240)

parent 39df66e1
This diff is collapsed.
......@@ -23,6 +23,7 @@ use Google\Protobuf\BytesValue;
use Google\Protobuf\Value;
use Google\Protobuf\ListValue;
use Google\Protobuf\Struct;
use Google\Protobuf\GPBEmpty;
class EncodeDecodeTest extends TestBase
{
......@@ -660,6 +661,129 @@ class EncodeDecodeTest extends TestBase
$this->assertSame("9a0400", bin2hex($to));
}
public function testJsonUnknown()
{
// Test unknown number
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":1,
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown bool
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":true,
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown string
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":\"abc\",
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown null
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":null,
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown array
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":[],
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown number array
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":[1],
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown bool array
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":[true],
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown string array
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":[\"a\"],
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown null array
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":[null],
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown array array
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":[[]],
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown object array
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":[{}],
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown double value array
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":[1, 2],
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown object
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":{},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown number object
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":{\"a\":1},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown bool object
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":{\"a\":true},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown string object
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":{\"a\":\"a\"},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown null object
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":{\"a\":null},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown array object
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":{\"a\":[]},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown object object
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":{\"a\":{}},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown double value object
$m = new TestMessage();
$m->mergeFromJsonString("{\"unknown\":{\"a\":1, \"b\":1},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
}
public function testJsonEncode()
{
$from = new TestMessage();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment