Skip to content

Commit

Permalink
Merge pull request protocolbuffers#5 from PierrickVoulet/testIssue3
Browse files Browse the repository at this point in the history
Provide UT that reproduces issue protocolbuffers#3
  • Loading branch information
haberman authored May 27, 2020
2 parents eeab3d1 + 15fa089 commit 335e663
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
15 changes: 15 additions & 0 deletions php/tests/proto/errors/authentication_error.proto
Original file line number Diff line number Diff line change
@@ -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;
}
}
14 changes: 14 additions & 0 deletions php/tests/proto/errors/errors.proto
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 10 additions & 6 deletions php/tests/test2/EncodeDecodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 335e663

Please sign in to comment.