aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--php/tests/generated_class_test.php13
-rw-r--r--src/google/protobuf/compiler/php/php_generator.cc2
2 files changed, 15 insertions, 0 deletions
diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php
index 21ee8490..b42397bb 100644
--- a/php/tests/generated_class_test.php
+++ b/php/tests/generated_class_test.php
@@ -877,4 +877,17 @@ class GeneratedClassTest extends TestBase
$m = new \Foo\PBEmpty();
$m = new \PrefixEmpty();
}
+
+ #########################################################
+ # Test fluent setters.
+ #########################################################
+
+ public function testFluentSetters()
+ {
+ $m = (new TestMessage())
+ ->setOptionalInt32(1)
+ ->setOptionalInt64(2);
+ $this->assertSame(1, $m->getOptionalInt32());
+ $this->assertSame(2, $m->getOptionalInt64());
+ }
}
diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc
index ea850c0f..54fafc40 100644
--- a/src/google/protobuf/compiler/php/php_generator.cc
+++ b/src/google/protobuf/compiler/php/php_generator.cc
@@ -530,6 +530,8 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
"field_name", field->name());
}
+ printer->Print("\nreturn $this;\n");
+
Outdent(printer);
printer->Print(