aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/tests
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2017-03-17 11:08:06 -0700
committerGravatar GitHub <noreply@github.com>2017-03-17 11:08:06 -0700
commit6b27c1f981a9a93918e4039f236ead27165a8e91 (patch)
tree980c622c849bc84be49b70996ce4e19979ba9122 /php/tests
parentc0871aa49c685e3aca19244c67d54ff321a62865 (diff)
Add file option php_class_prefix (#2849)
This option will be prepended to generated classes of all messages in the containing file.
Diffstat (limited to 'php/tests')
-rw-r--r--php/tests/encode_decode_test.php6
-rwxr-xr-xphp/tests/gdb_test.sh2
-rw-r--r--php/tests/generated_class_test.php14
-rw-r--r--php/tests/memory_leak_test.php3
-rw-r--r--php/tests/proto/test.proto5
-rw-r--r--php/tests/proto/test_prefix.proto7
6 files changed, 33 insertions, 4 deletions
diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php
index ba4fff69..94adf793 100644
--- a/php/tests/encode_decode_test.php
+++ b/php/tests/encode_decode_test.php
@@ -194,7 +194,7 @@ class EncodeDecodeTest extends TestBase
{
$m = new TestMessage();
$m->setOptionalInt32(-1);
- $data = $m->encode();
+ $data = $m->serializeToString();
$this->assertSame("08ffffffffffffffffff01", bin2hex($data));
}
@@ -202,12 +202,12 @@ class EncodeDecodeTest extends TestBase
{
$m = new TestMessage();
$this->assertEquals(0, $m->getOptionalInt32());
- $m->decode(hex2bin("08ffffffffffffffffff01"));
+ $m->mergeFromString(hex2bin("08ffffffffffffffffff01"));
$this->assertEquals(-1, $m->getOptionalInt32());
$m = new TestMessage();
$this->assertEquals(0, $m->getOptionalInt32());
- $m->decode(hex2bin("08ffffffff0f"));
+ $m->mergeFromString(hex2bin("08ffffffff0f"));
$this->assertEquals(-1, $m->getOptionalInt32());
}
diff --git a/php/tests/gdb_test.sh b/php/tests/gdb_test.sh
index 3c0d97a2..45a2841f 100755
--- a/php/tests/gdb_test.sh
+++ b/php/tests/gdb_test.sh
@@ -3,7 +3,7 @@
# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which
# phpunit` --bootstrap autoload.php tmp_test.php
#
-gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php encode_decode_test.php
+gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php array_test.php
#
# # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so
# memory_leak_test.php
diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php
index 4c3bca2d..39e6c6c4 100644
--- a/php/tests/generated_class_test.php
+++ b/php/tests/generated_class_test.php
@@ -9,6 +9,7 @@ use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\MapField;
use Google\Protobuf\Internal\GPBType;
use Foo\TestEnum;
+use Foo\TestIncludePrefixMessage;
use Foo\TestMessage;
use Foo\TestMessage_Sub;
@@ -838,4 +839,17 @@ class GeneratedClassTest extends TestBase
{
$m = new NoNameSpaceEnum();
}
+
+ #########################################################
+ # Test message with given prefix.
+ #########################################################
+
+ public function testPrefixMessage()
+ {
+ $m = new TestIncludePrefixMessage();
+ $n = new PrefixTestPrefix();
+ $n->setA(1);
+ $m->setPrefixMessage($n);
+ $this->assertSame(1, $m->getPrefixMessage()->getA());
+ }
}
diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php
index cfcbe62e..5dd79519 100644
--- a/php/tests/memory_leak_test.php
+++ b/php/tests/memory_leak_test.php
@@ -2,8 +2,10 @@
# phpunit has memory leak by itself. Thus, it cannot be used to test memory leak.
+require_once('generated/PrefixTestPrefix.php');
require_once('generated/Bar/TestInclude.php');
require_once('generated/Foo/TestEnum.php');
+require_once('generated/Foo/TestIncludePrefixMessage.php');
require_once('generated/Foo/TestMessage.php');
require_once('generated/Foo/TestMessage_Sub.php');
require_once('generated/Foo/TestPackedMessage.php');
@@ -11,6 +13,7 @@ require_once('generated/Foo/TestPhpDoc.php');
require_once('generated/Foo/TestUnpackedMessage.php');
require_once('generated/GPBMetadata/Proto/Test.php');
require_once('generated/GPBMetadata/Proto/TestInclude.php');
+require_once('generated/GPBMetadata/Proto/TestPrefix.php');
require_once('test_util.php');
use Google\Protobuf\Internal\RepeatedField;
diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto
index e5dee0fb..1a47a3f2 100644
--- a/php/tests/proto/test.proto
+++ b/php/tests/proto/test.proto
@@ -1,6 +1,7 @@
syntax = "proto3";
import 'proto/test_include.proto';
+import 'proto/test_prefix.proto';
package foo;
@@ -142,3 +143,7 @@ message TestUnpackedMessage {
message TestPhpDoc {
int32 a = 1;
}
+
+message TestIncludePrefixMessage {
+ TestPrefix prefix_message = 1;
+}
diff --git a/php/tests/proto/test_prefix.proto b/php/tests/proto/test_prefix.proto
new file mode 100644
index 00000000..04582121
--- /dev/null
+++ b/php/tests/proto/test_prefix.proto
@@ -0,0 +1,7 @@
+syntax = "proto3";
+
+option php_class_prefix = "Prefix";
+
+message TestPrefix {
+ int32 a = 1;
+}