Skip to content

Commit 15fa089

Browse files
author
pierrick
committed
Provide UT that reproduces issue protocolbuffers#3
1 parent eeab3d1 commit 15fa089

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
3+
import 'google/protobuf/any.proto';
4+
import 'google/protobuf/wrappers.proto';
5+
import 'google/protobuf/struct.proto';
6+
7+
package foo.errors;
8+
9+
message AuthenticationErrorEnum {
10+
enum AuthenticationError {
11+
UNSPECIFIED = 0;
12+
UNKNOWN = 1;
13+
AUTHENTICATION_ERROR = 2;
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
syntax = "proto3";
2+
3+
import 'google/protobuf/any.proto';
4+
import 'google/protobuf/wrappers.proto';
5+
import 'google/protobuf/struct.proto';
6+
import 'proto/errors/authentication_error.proto';
7+
8+
package foo.errors;
9+
10+
message ErrorCode {
11+
oneof error_code {
12+
AuthenticationErrorEnum.AuthenticationError authentication_error = 1;
13+
}
14+
}

php/tests/test2/EncodeDecodeTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
use Google\Protobuf\RepeatedField;
77
use Google\Protobuf\GPBType;
8+
use Foo\Errors\ErrorCode;
9+
use Foo\Errors\AuthenticationErrorEnum\AuthenticationError;
810
use Foo\TestInt32Value;
911
use Foo\TestInt64Value;
1012
use Foo\TestUInt32Value;
@@ -37,6 +39,14 @@
3739

3840
class EncodeDecodeTest extends TestBase
3941
{
42+
public function testIssue3()
43+
{
44+
$m = new ErrorCode([
45+
'authentication_error' => AuthenticationError::AUTHENTICATION_ERROR
46+
]);
47+
$this->assertSame('{"authenticationError":"AUTHENTICATION_ERROR"}', $m->serializeToJsonString());
48+
}
49+
4050
public function testDecodeJsonSimple()
4151
{
4252
$m = new TestMessage();
@@ -326,12 +336,6 @@ public function testEncodeDecodeOneof()
326336

327337
}
328338

329-
public function testJsonEncodeEnumFromInitializer()
330-
{
331-
$m = new TestMessage(['oneof_enum' => TestEnum::TWO]);
332-
$this->assertSame('{"oneofEnum":"TWO"}', $m->serializeToJsonString());
333-
}
334-
335339
public function testJsonEncodeDecodeOneof()
336340
{
337341
$m = new TestMessage();

0 commit comments

Comments
 (0)