Skip to content

Commit

Permalink
Provide UT that reproduces issue protocolbuffers#7
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrick committed May 28, 2020
1 parent b15ccb0 commit 169414c
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
34 changes: 34 additions & 0 deletions php/tests/proto/tester/tester.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";

package foo.tester;

import "google/protobuf/wrappers.proto";
import "google/protobuf/field_mask.proto";

message TestSuite {
repeated TestCase test_cases = 1;
}

message TestCase {
string description = 1;
Resource original_resource = 2;
Resource modified_resource = 3;
google.protobuf.FieldMask expected_mask = 4;
}

message Resource {
google.protobuf.StringValue wrapper = 1;
Foo foo = 2;
repeated Foo foos = 3;
}

message Foo {
int64 num = 1;
Bar bar = 2;
repeated Bar bars = 3;
}

message Bar {
int64 num = 1;
google.protobuf.BoolValue nested_wrapper = 2;
}
12 changes: 12 additions & 0 deletions php/tests/test2/EncodeDecodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Google\Protobuf\GPBType;
use Foo\Errors\ErrorCode;
use Foo\Errors\AuthenticationErrorEnum\AuthenticationError;
use Foo\Tester\TestSuite;
use Foo\TestInt32Value;
use Foo\TestInt64Value;
use Foo\TestUInt32Value;
Expand Down Expand Up @@ -39,6 +40,17 @@

class EncodeDecodeTest extends TestBase
{
public function testIssue7()
{
$ts = new TestSuite();
$ts->mergeFromJsonString(file_get_contents(sprintf(
'%s%stest_cases.json',
dirname(dirname(__FILE__)),
DIRECTORY_SEPARATOR
)));
$this->assertEquals(9, $ts->getTestCases()->count());
}

public function testIssue3()
{
$m = new ErrorCode([
Expand Down
112 changes: 112 additions & 0 deletions php/tests/test_cases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"test_cases": [{
"description": "Modify scalar in a wrapper proto",
"original_resource": {
"wrapper": "a"
},
"modified_resource": {
"wrapper": "b"
},
"expected_mask": "wrapper"
}, {
"description": "Create wrapper proto",
"original_resource": {
},
"modified_resource": {
"wrapper": "a"
},
"expected_mask": "wrapper"
}, {
"description": "Modify element in a repeated field",
"original_resource": {
"foos": [{
"num": 1
}, {
"num": 2
}]
},
"modified_resource": {
"foos": [{
"num": 1
}, {
"num": 3
}]
},
"expected_mask": "foos"
}, {
"description": "Modify element in a nested repeated field",
"original_resource": {
"foos": [{
"bars": [{
"num": 1
}]
}]
},
"modified_resource": {
"foos": [{
"bars": [{
"num": 2
}]
}]
},
"expected_mask": "foos"
}, {
"description": "Create submessage",
"original_resource": {
},
"modified_resource": {
"foo": {
"num": 1
}
},
"expected_mask": "foo.num"
}, {
"description": "Modify submessage",
"original_resource": {
"foo": {
}
},
"modified_resource": {
"foo": {
"num": 1
}
},
"expected_mask": "foo.num"
}, {
"description": "Clear submessage",
"original_resource": {
"foo": {
}
},
"modified_resource": {
},
"expected_mask": "foo"
}, {
"description": "No change",
"original_resource": {
"wrapper": "a",
"foos": [{
"num": 1
}]
},
"modified_resource": {
"wrapper": "a",
"foos": [{
"num": 1
}]
},
"expected_mask": {}
}, {
"description": "Create message with nested wrapper",
"original_resource": {
},
"modified_resource": {
"foo": {
"bar": {
"nested_wrapper": true
}
}
},
"expected_mask": "foo.bar.nested_wrapper"
}
]}

0 comments on commit 169414c

Please sign in to comment.