Updated and simplified PHP testing structure (#8558)
* Simplified PHP testing setup.
- Consolidated on a single autoloader, created by composer.
- Consolidated on a single phpunit invocation strategy: we run
phpunit on a directory, which will run all tests matching *Test.php
in that directory.
- We now rely on autoloading to import all test protos. require_once()
calls for test protos are removed.
- For now the valgrind tests are removed. A follow-up PR will re-enable
them in a more robust way.
* More improvements to PHP testing.
1. Replace custom PHPUnit-selection logic in test.sh with generic
composer version selection.
2. Optimized both test proto generation and the custom extension
build to avoid unnecessary work when the files are already up
to date.
* Added assertions to verify that the C test doesn't use PHP sources.
* Updated tests.sh for the new PHP testing commands.
* Removed obsolete rules from tests.sh.
* Fixed generate_test_protos.sh for when tmp does not exist.
Also removed undefined_test.php and fixed Makefile.am.
* Added php8.0_all again which is still used.
* Added missing file to Makefile.am.
* Re-added php_all_32 rule which is also still used.
* Updated testing commands for macOS and download composer.
* Use /usr/local/bin on mac instead of /usr/bin, since the latter is not writable.
diff --git a/php/composer.json b/php/composer.json
index 4c1b5ac..5ea49ed 100644
--- a/php/composer.json
+++ b/php/composer.json
@@ -6,7 +6,7 @@
"homepage": "https://developers.google.com/protocol-buffers/",
"license": "BSD-3-Clause",
"require": {
- "php": ">=5.5.0"
+ "php": ">=7.0.0"
},
"require-dev": {
"phpunit/phpunit": ">=5.0.0"
@@ -19,11 +19,12 @@
},
"autoload-dev": {
"psr-4": {
- "": "tests/generated"
+ "": "tmp"
}
},
"scripts": {
- "test": "tests/generate_protos.sh && vendor/bin/phpunit",
- "aggregate_metadata_test": "tests/generate_protos.sh --aggregate_metadata && vendor/bin/phpunit"
+ "test_c": "./generate_test_protos.sh && ./tests/compile_extension.sh && php -dextension=ext/google/protobuf/modules/protobuf.so vendor/bin/phpunit --bootstrap tests/force_c_ext.php tests",
+ "test": "./generate_test_protos.sh && vendor/bin/phpunit tests",
+ "aggregate_metadata_test": "./generate_test_protos.sh --aggregate_metadata && vendor/bin/phpunit tests"
}
}
diff --git a/php/generate_test_protos.sh b/php/generate_test_protos.sh
new file mode 100755
index 0000000..0aa4bdb
--- /dev/null
+++ b/php/generate_test_protos.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+set -e
+
+cd `dirname $0`
+
+if [[ -d tmp && -z $(find tests/proto ../src/protoc -newer tmp) ]]; then
+ # Generated protos are already present and up to date, so we can skip protoc.
+ #
+ # Protoc is very fast, but sometimes it is not available (like if we haven't
+ # built it in Docker). Skipping it helps us proceed in this case.
+ echo "Test protos are up-to-date, skipping protoc."
+ exit 0
+fi
+
+rm -rf tmp
+mkdir -p tmp
+
+find tests/proto -type f -name "*.proto"| xargs ../src/protoc --php_out=tmp -I../src -Itests
+
+if [ "$1" = "--aggregate_metadata" ]; then
+ # Overwrite some of the files to use aggregation.
+ AGGREGATED_FILES="tests/proto/test.proto tests/proto/test_include.proto tests/proto/test_import_descriptor_proto.proto"
+ ../src/protoc --php_out=aggregate_metadata=foo#bar:tmp -I../src -Itests $AGGREGATED_FILES
+fi
+
+echo "Generated test protos from tests/proto -> tmp"
diff --git a/php/phpunit.xml b/php/phpunit.xml
deleted file mode 100644
index 8e75835..0000000
--- a/php/phpunit.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<phpunit bootstrap="./tests/bootstrap_phpunit.php"
- colors="true">
- <testsuites>
- <testsuite name="protobuf-tests">
- <file>tests/PhpImplementationTest.php</file>
- <file>tests/ArrayTest.php</file>
- <file>tests/EncodeDecodeTest.php</file>
- <file>tests/GeneratedClassTest.php</file>
- <file>tests/GeneratedPhpdocTest.php</file>
- <file>tests/MapFieldTest.php</file>
- <file>tests/WellKnownTest.php</file>
- <file>tests/DescriptorsTest.php</file>
- <file>tests/GeneratedServiceTest.php</file>
- <file>tests/WrapperTypeSettersTest.php</file>
- </testsuite>
- </testsuites>
-</phpunit>
diff --git a/php/tests/DescriptorsTest.php b/php/tests/DescriptorsTest.php
index ca7e8f3..4f17a49 100644
--- a/php/tests/DescriptorsTest.php
+++ b/php/tests/DescriptorsTest.php
@@ -1,7 +1,5 @@
<?php
-require_once('generated/Descriptors/TestDescriptorsEnum.php');
-require_once('generated/Descriptors/TestDescriptorsMessage.php');
require_once('test_base.php');
require_once('test_util.php');
diff --git a/php/tests/GeneratedClassTest.php b/php/tests/GeneratedClassTest.php
index f2a9fb0..8759391 100644
--- a/php/tests/GeneratedClassTest.php
+++ b/php/tests/GeneratedClassTest.php
@@ -1,7 +1,5 @@
<?php
-require_once('generated/NoNamespaceEnum.php');
-require_once('generated/NoNamespaceMessage.php');
require_once('test_base.php');
require_once('test_util.php');
@@ -759,10 +757,10 @@
public function testMessageWithoutNamespace()
{
$m = new TestMessage();
- $n = new NoNameSpaceMessage();
+ $n = new NoNamespaceMessage();
$m->setOptionalNoNamespaceMessage($n);
$repeatedNoNamespaceMessage = $m->getRepeatedNoNamespaceMessage();
- $repeatedNoNamespaceMessage[] = new NoNameSpaceMessage();
+ $repeatedNoNamespaceMessage[] = new NoNamespaceMessage();
$m->setRepeatedNoNamespaceMessage($repeatedNoNamespaceMessage);
// test nested messages
@@ -775,9 +773,9 @@
public function testEnumWithoutNamespace()
{
$m = new TestMessage();
- $m->setOptionalNoNamespaceEnum(NoNameSpaceEnum::VALUE_A);
+ $m->setOptionalNoNamespaceEnum(NoNamespaceEnum::VALUE_A);
$repeatedNoNamespaceEnum = $m->getRepeatedNoNamespaceEnum();
- $repeatedNoNamespaceEnum[] = NoNameSpaceEnum::VALUE_A;
+ $repeatedNoNamespaceEnum[] = NoNamespaceEnum::VALUE_A;
$m->setRepeatedNoNamespaceEnum($repeatedNoNamespaceEnum);
$this->assertTrue(true);
}
diff --git a/php/tests/GeneratedPhpdocTest.php b/php/tests/GeneratedPhpdocTest.php
index 18963a9..a0b912b 100644
--- a/php/tests/GeneratedPhpdocTest.php
+++ b/php/tests/GeneratedPhpdocTest.php
@@ -1,7 +1,5 @@
<?php
-require_once('generated/NoNamespaceEnum.php');
-require_once('generated/NoNamespaceMessage.php');
require_once('test_base.php');
require_once('test_util.php');
diff --git a/php/tests/PhpImplementationTest.php b/php/tests/PhpImplementationTest.php
index 82d0c5a..7187315 100644
--- a/php/tests/PhpImplementationTest.php
+++ b/php/tests/PhpImplementationTest.php
@@ -18,7 +18,7 @@
* Please note, this test is only intended to be run without the protobuf C
* extension.
*/
-class ImplementationTest extends TestBase
+class PhpImplementationTest extends TestBase
{
/**
* Avoid calling setUp, which has void return type (not avalialbe in php7.0).
diff --git a/php/tests/autoload.php b/php/tests/autoload.php
deleted file mode 100644
index b98b13a..0000000
--- a/php/tests/autoload.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-
-error_reporting(E_ALL);
-
-function getGeneratedFiles($dir, &$results = array())
-{
- $files = scandir($dir);
-
- foreach ($files as $key => $value) {
- $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
- if (!is_dir($path)) {
- $results[] = $path;
- } else if ($value != "." && $value != "..") {
- getGeneratedFiles($path, $results);
- }
- }
- return $results;
-}
-
-foreach (getGeneratedFiles("generated") as $filename)
-{
- if (!is_dir($filename)) {
- include_once $filename;
- }
-
-}
-
diff --git a/php/tests/bootstrap_phpunit.php b/php/tests/bootstrap_phpunit.php
deleted file mode 100644
index 8452f15..0000000
--- a/php/tests/bootstrap_phpunit.php
+++ /dev/null
@@ -1,5 +0,0 @@
-<?php
-
-require_once("vendor/autoload.php");
-
-error_reporting(E_ALL);
diff --git a/php/tests/compile_extension.sh b/php/tests/compile_extension.sh
index 85c73c6..d26fcb4 100755
--- a/php/tests/compile_extension.sh
+++ b/php/tests/compile_extension.sh
@@ -1,20 +1,26 @@
#!/bin/bash
-set -ex
+set -e
cd $(dirname $0)
../prepare_c_extension.sh
-pushd ../ext/google/protobuf
-phpize --clean
-rm -f configure.in configure.ac
-phpize
-if [ "$1" = "--release" ]; then
- ./configure --with-php-config=$(which php-config)
-else
- # To get debugging symbols in PHP itself, build PHP with:
- # $ ./configure --enable-debug CFLAGS='-g -O0'
- ./configure --with-php-config=$(which php-config) CFLAGS="-g -O0 -Wall"
+pushd ../ext/google/protobuf > /dev/null
+
+CONFIGURE_OPTIONS=("./configure" "--with-php-config=$(which php-config)")
+
+if [ "$1" != "--release" ]; then
+ CONFIGURE_OPTIONS+=("CFLAGS=-g -O0 -Wall")
fi
+
+# If the PHP interpreter we are building against or the arguments
+# have changed, we must regenerated the Makefile.
+if [[ ! -f Makefile ]] || [[ "$(grep ' \$ ./configure' config.log)" != " $ ${CONFIGURE_OPTIONS[@]}" ]]; then
+ phpize --clean
+ rm -f configure.in configure.ac
+ phpize
+ "${CONFIGURE_OPTIONS[@]}"
+fi
+
make
-popd
+popd > /dev/null
diff --git a/php/tests/force_c_ext.php b/php/tests/force_c_ext.php
new file mode 100644
index 0000000..afc63c5
--- /dev/null
+++ b/php/tests/force_c_ext.php
@@ -0,0 +1,14 @@
+<?php
+
+// We have to test this because the command-line argument will fail silently
+// if the extension could not be loaded:
+// php -dextension=ext/google/protobuf/modules/protouf.so
+if (!extension_loaded("protobuf")) {
+ throw new Exception("Protobuf extension not loaded");
+}
+
+spl_autoload_register(function($class) {
+ if (strpos($class, "Google\\Protobuf") === 0) {
+ throw new Exception("When using the C extension, we should not load runtime class: " . $class);
+ }
+}, true, true);
diff --git a/php/tests/generate_protos.sh b/php/tests/generate_protos.sh
deleted file mode 100755
index e83c3c1..0000000
--- a/php/tests/generate_protos.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-set -ex
-
-cd `dirname $0`
-
-rm -rf generated
-mkdir -p generated
-
-find proto -type f -name "*.proto"| xargs ../../src/protoc --experimental_allow_proto3_optional --php_out=generated -I../../src -I.
-
-if [ "$1" = "--aggregate_metadata" ]; then
- # Overwrite some of the files to use aggregation.
- AGGREGATED_FILES="proto/test.proto proto/test_include.proto proto/test_import_descriptor_proto.proto"
- ../../src/protoc --experimental_allow_proto3_optional --php_out=aggregate_metadata=foo#bar:generated -I../../src -I. $AGGREGATED_FILES
-fi
diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php
index a9c292d..1f2d095 100644
--- a/php/tests/memory_leak_test.php
+++ b/php/tests/memory_leak_test.php
@@ -2,57 +2,7 @@
# phpunit has memory leak by itself. Thus, it cannot be used to test memory leak.
-require_once('generated/NoNamespaceEnum.php');
-require_once('generated/NoNamespaceMessage.php');
-require_once('generated/NoNamespaceMessage/NestedEnum.php');
-require_once('generated/NoNamespaceMessage/NestedMessage.php');
-require_once('generated/PrefixEmpty.php');
-require_once('generated/PrefixTestPrefix.php');
-require_once('generated/PrefixTestPrefix/PrefixNestedEnum.php');
-require_once('generated/PrefixTestPrefix/PrefixNestedMessage.php');
-require_once('generated/TestEmptyNamespace.php');
-require_once('generated/TestEmptyNamespace/NestedEnum.php');
-require_once('generated/TestEmptyNamespace/NestedMessage.php');
-require_once('generated/Bar/TestInclude.php');
-require_once('generated/Bar/TestLegacyMessage.php');
-require_once('generated/Bar/TestLegacyMessage/NestedEnum.php');
-require_once('generated/Bar/TestLegacyMessage/NestedMessage.php');
-require_once('generated/Foo/PBARRAY.php');
-require_once('generated/Foo/PBEmpty.php');
-require_once('generated/Foo/TestAny.php');
-require_once('generated/Foo/TestBoolValue.php');
-require_once('generated/Foo/TestBytesValue.php');
-require_once('generated/Foo/TestEnum.php');
-require_once('generated/Foo/TestIncludeNamespaceMessage.php');
-require_once('generated/Foo/TestIncludePrefixMessage.php');
-require_once('generated/Foo/TestInt32Value.php');
-require_once('generated/Foo/TestInt64Value.php');
-require_once('generated/Foo/TestMessage.php');
-require_once('generated/Foo/TestMessage/PBEmpty.php');
-require_once('generated/Foo/TestMessage/NestedEnum.php');
-require_once('generated/Foo/TestMessage/Sub.php');
-require_once('generated/Foo/TestPackedMessage.php');
-require_once('generated/Foo/TestPhpDoc.php');
-require_once('generated/Foo/TestRandomFieldOrder.php');
-require_once('generated/Foo/TestReverseFieldOrder.php');
-require_once('generated/Foo/TestStringValue.php');
-require_once('generated/Foo/TestUInt32Value.php');
-require_once('generated/Foo/TestUInt64Value.php');
-require_once('generated/Foo/TestUnpackedMessage.php');
-require_once('generated/Foo/testLowerCaseMessage.php');
-require_once('generated/Foo/testLowerCaseEnum.php');
-require_once('generated/GPBMetadata/Proto/Test.php');
-require_once('generated/TestEmptyPhpNamespace.php');
-require_once('generated/GPBMetadata/Proto/TestInclude.php');
-require_once('generated/TestNoNamespace.php');
-require_once('generated/Metadata/Php/Test/TestPhpNamespace.php');
-require_once('generated/GPBMetadata/Proto/TestPrefix.php');
-require_once('generated/Php/Test/TestNamespace.php');
-require_once('generated/Php/Test/TestNamespace/PBEmpty.php');
-require_once('generated/Php/Test/TestNamespace/PBEmpty/NestedEnum.php');
-require_once('generated/Php/Test/TestNamespace/PBEmpty/NestedMessage.php');
-require_once('generated/Php/Test/TestNamespace/NestedEnum.php');
-require_once('generated/Php/Test/TestNamespace/NestedMessage.php');
+require_once('../vendor/autoload.php');
require_once('test_util.php');
use Google\Protobuf\Internal\RepeatedField;
diff --git a/php/tests/test.sh b/php/tests/test.sh
deleted file mode 100755
index d04f36a..0000000
--- a/php/tests/test.sh
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/bin/bash
-
-set -ex
-
-cd $(dirname $0)
-
-./generate_protos.sh
-./compile_extension.sh
-
-PHP_VERSION=$(php -r "echo PHP_VERSION;")
-
-# Each version of PHPUnit supports a fairly narrow range of PHP versions.
-case "$PHP_VERSION" in
- 7.0.*)
- PHPUNIT=phpunit-6.phar
- ;;
- 7.1.*|7.2.*)
- PHPUNIT=phpunit-7.5.0.phar
- ;;
- 7.3.*|7.4.*)
- PHPUNIT=phpunit-8.phar
- ;;
- 8.0.*)
- PHPUNIT=phpunit-9.phar
- ;;
- *)
- echo "ERROR: Unsupported PHP version $PHP_VERSION"
- exit 1
- ;;
-esac
-
-[ -f $PHPUNIT ] || wget https://phar.phpunit.de/$PHPUNIT
-
-tests=( ArrayTest.php EncodeDecodeTest.php GeneratedClassTest.php MapFieldTest.php WellKnownTest.php DescriptorsTest.php WrapperTypeSettersTest.php)
-
-for t in "${tests[@]}"
-do
- echo "****************************"
- echo "* $t"
- echo "****************************"
- php -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
- echo ""
-done
-
-for t in "${tests[@]}"
-do
- echo "****************************"
- echo "* $t persistent"
- echo "****************************"
- php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
- echo ""
-done
-
-# # Make sure to run the memory test in debug mode.
-# php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
-
-export ZEND_DONT_UNLOAD_MODULES=1
-export USE_ZEND_ALLOC=0
-valgrind --suppressions=valgrind.supp --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
-valgrind --suppressions=valgrind.supp --leak-check=yes php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
-
-# TODO(teboring): Only for debug (phpunit has memory leak which blocks this beging used by
-# regression test.)
-
-# for t in "${tests[@]}"
-# do
-# echo "****************************"
-# echo "* $t (memory leak)"
-# echo "****************************"
-# valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
-# echo ""
-# done
diff --git a/php/tests/undefined_test.php b/php/tests/undefined_test.php
deleted file mode 100644
index 935d8be..0000000
--- a/php/tests/undefined_test.php
+++ /dev/null
@@ -1,920 +0,0 @@
-<?php
-
-require_once('test_util.php');
-
-use Google\Protobuf\Internal\RepeatedField;
-use Google\Protobuf\Internal\GPBType;
-use Foo\TestMessage;
-use Foo\TestMessage\Sub;
-
-class UndefinedTest extends PHPUnit_Framework_TestCase
-{
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32AppendStringFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
- $arr[] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32SetStringFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
- $arr[] = 0;
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32AppendMessageFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
- $arr[] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32SetMessageFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
- $arr[] = 0;
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32AppendStringFail()
- {
- $arr = new RepeatedField(GPBType::UINT32);
- $arr[] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32SetStringFail()
- {
- $arr = new RepeatedField(GPBType::UINT32);
- $arr[] = 0;
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32AppendMessageFail()
- {
- $arr = new RepeatedField(GPBType::UINT32);
- $arr[] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32SetMessageFail()
- {
- $arr = new RepeatedField(GPBType::UINT32);
- $arr[] = 0;
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64AppendStringFail()
- {
- $arr = new RepeatedField(GPBType::INT64);
- $arr[] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64SetStringFail()
- {
- $arr = new RepeatedField(GPBType::INT64);
- $arr[] = 0;
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64AppendMessageFail()
- {
- $arr = new RepeatedField(GPBType::INT64);
- $arr[] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64SetMessageFail()
- {
- $arr = new RepeatedField(GPBType::INT64);
- $arr[] = 0;
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64AppendStringFail()
- {
- $arr = new RepeatedField(GPBType::UINT64);
- $arr[] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64SetStringFail()
- {
- $arr = new RepeatedField(GPBType::UINT64);
- $arr[] = 0;
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64AppendMessageFail()
- {
- $arr = new RepeatedField(GPBType::UINT64);
- $arr[] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64SetMessageFail()
- {
- $arr = new RepeatedField(GPBType::UINT64);
- $arr[] = 0;
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testFloatAppendStringFail()
- {
- $arr = new RepeatedField(GPBType::FLOAT);
- $arr[] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testFloatSetStringFail()
- {
- $arr = new RepeatedField(GPBType::FLOAT);
- $arr[] = 0.0;
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testFloatAppendMessageFail()
- {
- $arr = new RepeatedField(GPBType::FLOAT);
- $arr[] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testFloatSetMessageFail()
- {
- $arr = new RepeatedField(GPBType::FLOAT);
- $arr[] = 0.0;
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testDoubleAppendStringFail()
- {
- $arr = new RepeatedField(GPBType::DOUBLE);
- $arr[] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testDoubleSetStringFail()
- {
- $arr = new RepeatedField(GPBType::DOUBLE);
- $arr[] = 0.0;
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testDoubleAppendMessageFail()
- {
- $arr = new RepeatedField(GPBType::DOUBLE);
- $arr[] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testDoubleSetMessageFail()
- {
- $arr = new RepeatedField(GPBType::DOUBLE);
- $arr[] = 0.0;
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testBoolAppendMessageFail()
- {
- $arr = new RepeatedField(GPBType::BOOL);
- $arr[] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testBoolSetMessageFail()
- {
- $arr = new RepeatedField(GPBType::BOOL);
- $arr[] = true;
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringAppendMessageFail()
- {
- $arr = new RepeatedField(GPBType::STRING);
- $arr[] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringSetMessageFail()
- {
- $arr = new RepeatedField(GPBType::STRING);
- $arr[] = 'abc';
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringAppendInvalidUTF8Fail()
- {
- $arr = new RepeatedField(GPBType::STRING);
- $hex = hex2bin("ff");
- $arr[] = $hex;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringSetInvalidUTF8Fail()
- {
- $arr = new RepeatedField(GPBType::STRING);
- $arr[] = 'abc';
- $hex = hex2bin("ff");
- $arr[0] = $hex;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageAppendIntFail()
- {
- $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
- $arr[] = 1;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageSetIntFail()
- {
- $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
- $arr[] = new Sub;
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageAppendStringFail()
- {
- $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
- $arr[] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageSetStringFail()
- {
- $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
- $arr[] = new Sub;
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageAppendOtherMessageFail()
- {
- $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
- $arr[] = new TestMessage;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageAppendNullFail()
- {
- $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
- $null = null;
- $arr[] = $null;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageSetNullFail()
- {
- $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
- $arr[] = new Sub();
- $null = null;
- $arr[0] = $null;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testRemoveMiddleFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
-
- $arr[] = 0;
- $arr[] = 1;
- $arr[] = 2;
- $this->assertSame(3, count($arr));
-
- unset($arr[1]);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testRemoveEmptyFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
-
- unset($arr[0]);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageOffsetFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
- $arr[] = 0;
- $arr[new Sub()] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringOffsetFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
- $arr[] = 0;
- $arr['abc'] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testSetNonExistedOffsetFail()
- {
- $arr = new RepeatedField(GPBType::INT32);
- $arr[0] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32FieldInvalidTypeFail()
- {
- $m = new TestMessage();
- $m->setOptionalInt32(new TestMessage());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32FieldInvalidStringFail()
- {
- $m = new TestMessage();
- $m->setOptionalInt32('abc');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32FieldInvalidTypeFail()
- {
- $m = new TestMessage();
- $m->setOptionalUint32(new TestMessage());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32FieldInvalidStringFail()
- {
- $m = new TestMessage();
- $m->setOptionalUint32('abc');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64FieldInvalidTypeFail()
- {
- $m = new TestMessage();
- $m->setOptionalInt64(new TestMessage());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64FieldInvalidStringFail()
- {
- $m = new TestMessage();
- $m->setOptionalInt64('abc');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64FieldInvalidTypeFail()
- {
- $m = new TestMessage();
- $m->setOptionalUint64(new TestMessage());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64FieldInvalidStringFail()
- {
- $m = new TestMessage();
- $m->setOptionalUint64('abc');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testFloatFieldInvalidTypeFail()
- {
- $m = new TestMessage();
- $m->setOptionalFloat(new TestMessage());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testFloatFieldInvalidStringFail()
- {
- $m = new TestMessage();
- $m->setOptionalFloat('abc');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testDoubleFieldInvalidTypeFail()
- {
- $m = new TestMessage();
- $m->setOptionalDouble(new TestMessage());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testDoubleFieldInvalidStringFail()
- {
- $m = new TestMessage();
- $m->setOptionalDouble('abc');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testBoolFieldInvalidStringFail()
- {
- $m = new TestMessage();
- $m->setOptionalBool(new TestMessage());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringFieldInvalidUTF8Fail()
- {
- $m = new TestMessage();
- $hex = hex2bin("ff");
- $m->setOptionalString($hex);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageFieldWrongTypeFail()
- {
- $m = new TestMessage();
- $a = 1;
- $m->setOptionalMessage($a);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageFieldWrongClassFail()
- {
- $m = new TestMessage();
- $m->setOptionalMessage(new TestMessage());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testRepeatedFieldWrongTypeFail()
- {
- $m = new TestMessage();
- $a = 1;
- $m->setRepeatedInt32($a);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testRepeatedFieldWrongObjectFail()
- {
- $m = new TestMessage();
- $m->setRepeatedInt32($m);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testRepeatedFieldWrongRepeatedTypeFail()
- {
- $m = new TestMessage();
-
- $repeated_int32 = new RepeatedField(GPBType::UINT32);
- $m->setRepeatedInt32($repeated_int32);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testRepeatedFieldWrongRepeatedMessageClassFail()
- {
- $m = new TestMessage();
-
- $repeated_message = new RepeatedField(GPBType::MESSAGE,
- TestMessage::class);
- $m->setRepeatedMessage($repeated_message);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMapFieldWrongTypeFail()
- {
- $m = new TestMessage();
- $a = 1;
- $m->setMapInt32Int32($a);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMapFieldWrongObjectFail()
- {
- $m = new TestMessage();
- $m->setMapInt32Int32($m);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMapFieldWrongRepeatedTypeFail()
- {
- $m = new TestMessage();
-
- $map_uint32_uint32 = new MapField(GPBType::UINT32, GPBType::UINT32);
- $m->setMapInt32Int32($map_uint32_uint32);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMapFieldWrongRepeatedMessageClassFail()
- {
- $m = new TestMessage();
-
- $map_int32_message = new MapField(GPBType::INT32,
- GPBType::MESSAGE,
- TestMessage::class);
- $m->setMapInt32Message($map_int32_message);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageMergeFromInvalidTypeFail()
- {
- $m = new TestMessage();
- $n = new Sub();
- $m->mergeFrom($n);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32SetStringKeyFail()
- {
- $arr = new MapField(GPBType::INT32, GPBType::INT32);
- $arr['abc'] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32SetStringValueFail()
- {
- $arr = new MapField(GPBType::INT32, GPBType::INT32);
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32SetMessageKeyFail()
- {
- $arr = new MapField(GPBType::INT32, GPBType::INT32);
- $arr[new Sub()] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt32SetMessageValueFail()
- {
- $arr = new MapField(GPBType::INT32, GPBType::INT32);
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32SetStringKeyFail()
- {
- $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
- $arr['abc'] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32SetStringValueFail()
- {
- $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32SetMessageKeyFail()
- {
- $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
- $arr[new Sub()] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint32SetMessageValueFail()
- {
- $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64SetStringKeyFail()
- {
- $arr = new MapField(GPBType::INT64, GPBType::INT64);
- $arr['abc'] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64SetStringValueFail()
- {
- $arr = new MapField(GPBType::INT64, GPBType::INT64);
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64SetMessageKeyFail()
- {
- $arr = new MapField(GPBType::INT64, GPBType::INT64);
- $arr[new Sub()] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testInt64SetMessageValueFail()
- {
- $arr = new MapField(GPBType::INT64, GPBType::INT64);
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64SetStringKeyFail()
- {
- $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
- $arr['abc'] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64SetStringValueFail()
- {
- $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64SetMessageKeyFail()
- {
- $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
- $arr[new Sub()] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testUint64SetMessageValueFail()
- {
- $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testDoubleSetStringValueFail()
- {
- $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testDoubleSetMessageValueFail()
- {
- $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testBoolSetMessageKeyFail()
- {
- $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
- $arr[new Sub()] = true;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testBoolSetMessageValueFail()
- {
- $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
- $arr[true] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringSetInvalidUTF8KeyFail()
- {
- $arr = new MapField(GPBType::STRING, GPBType::STRING);
- $arr[hex2bin("ff")] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringSetInvalidUTF8ValueFail()
- {
- $arr = new MapField(GPBType::STRING, GPBType::STRING);
- $arr['abc'] = hex2bin("ff");
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringSetMessageKeyFail()
- {
- $arr = new MapField(GPBType::STRING, GPBType::STRING);
- $arr[new Sub()] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testStringSetMessageValueFail()
- {
- $arr = new MapField(GPBType::STRING, GPBType::STRING);
- $arr['abc'] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageSetIntValueFail()
- {
- $arr =
- new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
- $arr[0] = 0;
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageSetStringValueFail()
- {
- $arr =
- new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
- $arr[0] = 'abc';
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageSetOtherMessageValueFail()
- {
- $arr =
- new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
- $arr[0] = new Sub();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- */
- public function testMessageSetNullFailMap()
- {
- $arr =
- new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
- $null = NULL;
- $arr[0] = $null;
- }
-
-}