From 15fa0894b603f6d0ddb9181a8929e858e8bbdf6f Mon Sep 17 00:00:00 2001 From: pierrick Date: Tue, 26 May 2020 20:04:25 -0400 Subject: [PATCH] Provide UT that reproduces issue #3 --- .../proto/errors/authentication_error.proto | 15 +++++++++++++++ php/tests/proto/errors/errors.proto | 14 ++++++++++++++ php/tests/test2/EncodeDecodeTest.php | 16 ++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 php/tests/proto/errors/authentication_error.proto create mode 100644 php/tests/proto/errors/errors.proto diff --git a/php/tests/proto/errors/authentication_error.proto b/php/tests/proto/errors/authentication_error.proto new file mode 100644 index 000000000000..812ee816efaa --- /dev/null +++ b/php/tests/proto/errors/authentication_error.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +import 'google/protobuf/any.proto'; +import 'google/protobuf/wrappers.proto'; +import 'google/protobuf/struct.proto'; + +package foo.errors; + +message AuthenticationErrorEnum { + enum AuthenticationError { + UNSPECIFIED = 0; + UNKNOWN = 1; + AUTHENTICATION_ERROR = 2; + } +} \ No newline at end of file diff --git a/php/tests/proto/errors/errors.proto b/php/tests/proto/errors/errors.proto new file mode 100644 index 000000000000..e39b80717251 --- /dev/null +++ b/php/tests/proto/errors/errors.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +import 'google/protobuf/any.proto'; +import 'google/protobuf/wrappers.proto'; +import 'google/protobuf/struct.proto'; +import 'proto/errors/authentication_error.proto'; + +package foo.errors; + +message ErrorCode { + oneof error_code { + AuthenticationErrorEnum.AuthenticationError authentication_error = 1; + } +} \ No newline at end of file diff --git a/php/tests/test2/EncodeDecodeTest.php b/php/tests/test2/EncodeDecodeTest.php index d6b0d4260c90..31e9673261e0 100644 --- a/php/tests/test2/EncodeDecodeTest.php +++ b/php/tests/test2/EncodeDecodeTest.php @@ -5,6 +5,8 @@ use Google\Protobuf\RepeatedField; use Google\Protobuf\GPBType; +use Foo\Errors\ErrorCode; +use Foo\Errors\AuthenticationErrorEnum\AuthenticationError; use Foo\TestInt32Value; use Foo\TestInt64Value; use Foo\TestUInt32Value; @@ -37,6 +39,14 @@ class EncodeDecodeTest extends TestBase { + public function testIssue3() + { + $m = new ErrorCode([ + 'authentication_error' => AuthenticationError::AUTHENTICATION_ERROR + ]); + $this->assertSame('{"authenticationError":"AUTHENTICATION_ERROR"}', $m->serializeToJsonString()); + } + public function testDecodeJsonSimple() { $m = new TestMessage(); @@ -326,12 +336,6 @@ public function testEncodeDecodeOneof() } - public function testJsonEncodeEnumFromInitializer() - { - $m = new TestMessage(['oneof_enum' => TestEnum::TWO]); - $this->assertSame('{"oneofEnum":"TWO"}', $m->serializeToJsonString()); - } - public function testJsonEncodeDecodeOneof() { $m = new TestMessage();