diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-06-05 00:10:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-05 00:10:18 -0700 |
commit | 6f325805c0bc956f927b0e2dbfb4dd8133b4ed69 (patch) | |
tree | 2f7d596b8e19933b67868d7378bb663960b75f87 /php/tests | |
parent | fbaad3617fbfadafbcc653a621620a5081df64eb (diff) |
Add new file option php_namespace. (#3162)
* Add new file option php_namespace.
Use this option to change the namespace of php generated classes.
Default is empty. When this option is empty, the package name will be
used for determining the namespace.
* Uncomment commented tests
* Revert gdb test change
* Update csharp descriptor.
* Add test for empty php_namespace.
Diffstat (limited to 'php/tests')
-rw-r--r-- | php/tests/generated_class_test.php | 21 | ||||
-rw-r--r-- | php/tests/memory_leak_test.php | 5 | ||||
-rw-r--r-- | php/tests/proto/test.proto | 7 | ||||
-rw-r--r-- | php/tests/proto/test_empty_php_namespace.proto | 8 | ||||
-rw-r--r-- | php/tests/proto/test_php_namespace.proto | 8 |
5 files changed, 49 insertions, 0 deletions
diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index be641b6e..f7e645b3 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -9,9 +9,11 @@ use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\MapField; use Google\Protobuf\Internal\GPBType; use Foo\TestEnum; +use Foo\TestIncludeNamespaceMessage; use Foo\TestIncludePrefixMessage; use Foo\TestMessage; use Foo\TestMessage_Sub; +use Php\Test\TestNamespace; class GeneratedClassTest extends TestBase { @@ -868,6 +870,25 @@ class GeneratedClassTest extends TestBase } ######################################################### + # Test message with given namespace. + ######################################################### + + public function testNamespaceMessage() + { + $m = new TestIncludeNamespaceMessage(); + + $n = new TestNamespace(); + $n->setA(1); + $m->setNamespaceMessage($n); + $this->assertSame(1, $m->getNamespaceMessage()->getA()); + + $n = new TestEmptyNamespace(); + $n->setA(1); + $m->setEmptyNamespaceMessage($n); + $this->assertSame(1, $m->getEmptyNamespaceMessage()->getA()); + } + + ######################################################### # Test prefix for reserved words. ######################################################### diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index 5eac56f0..4f951a89 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -7,10 +7,12 @@ require_once('generated/NoNamespaceMessage.php'); require_once('generated/NoNamespaceMessage_NestedEnum.php'); require_once('generated/PrefixEmpty.php'); require_once('generated/PrefixTestPrefix.php'); +require_once('generated/TestEmptyNamespace.php'); require_once('generated/Bar/TestInclude.php'); require_once('generated/Foo/PBARRAY.php'); require_once('generated/Foo/PBEmpty.php'); require_once('generated/Foo/TestEnum.php'); +require_once('generated/Foo/TestIncludeNamespaceMessage.php'); require_once('generated/Foo/TestIncludePrefixMessage.php'); require_once('generated/Foo/TestMessage.php'); require_once('generated/Foo/TestMessage_Empty.php'); @@ -20,9 +22,12 @@ require_once('generated/Foo/TestPackedMessage.php'); require_once('generated/Foo/TestPhpDoc.php'); require_once('generated/Foo/TestUnpackedMessage.php'); require_once('generated/GPBMetadata/Proto/Test.php'); +require_once('generated/GPBMetadata/Proto/TestEmptyPhpNamespace.php'); require_once('generated/GPBMetadata/Proto/TestInclude.php'); require_once('generated/GPBMetadata/Proto/TestNoNamespace.php'); +require_once('generated/GPBMetadata/Proto/TestPhpNamespace.php'); require_once('generated/GPBMetadata/Proto/TestPrefix.php'); +require_once('generated/Php/Test/TestNamespace.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 583bf8e1..dada8b48 100644 --- a/php/tests/proto/test.proto +++ b/php/tests/proto/test.proto @@ -2,6 +2,8 @@ syntax = "proto3"; import 'proto/test_include.proto'; import 'proto/test_no_namespace.proto'; +import 'proto/test_php_namespace.proto'; +import 'proto/test_empty_php_namespace.proto'; import 'proto/test_prefix.proto'; package foo; @@ -174,3 +176,8 @@ message TestPhpDoc { message TestIncludePrefixMessage { TestPrefix prefix_message = 1; } + +message TestIncludeNamespaceMessage { + TestNamespace namespace_message = 1; + TestEmptyNamespace empty_namespace_message = 2; +} diff --git a/php/tests/proto/test_empty_php_namespace.proto b/php/tests/proto/test_empty_php_namespace.proto new file mode 100644 index 00000000..7b4bc74d --- /dev/null +++ b/php/tests/proto/test_empty_php_namespace.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +package foo; +option php_namespace = ""; + +message TestEmptyNamespace { + int32 a = 1; +} diff --git a/php/tests/proto/test_php_namespace.proto b/php/tests/proto/test_php_namespace.proto new file mode 100644 index 00000000..713187b9 --- /dev/null +++ b/php/tests/proto/test_php_namespace.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +package foo; +option php_namespace = "Php\\Test"; + +message TestNamespace { + int32 a = 1; +} |