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.
pull/8566/head
Joshua Haberman 4 years ago committed by GitHub
parent 114efc42d4
commit 8b87075924
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      Makefile.am
  2. 9
      php/composer.json
  3. 27
      php/generate_test_protos.sh
  4. 18
      php/phpunit.xml
  5. 2
      php/tests/DescriptorsTest.php
  6. 10
      php/tests/GeneratedClassTest.php
  7. 2
      php/tests/GeneratedPhpdocTest.php
  8. 2
      php/tests/PhpImplementationTest.php
  9. 27
      php/tests/autoload.php
  10. 5
      php/tests/bootstrap_phpunit.php
  11. 30
      php/tests/compile_extension.sh
  12. 14
      php/tests/force_c_ext.php
  13. 16
      php/tests/generate_protos.sh
  14. 52
      php/tests/memory_leak_test.php
  15. 72
      php/tests/test.sh
  16. 920
      php/tests/undefined_test.php
  17. 204
      tests.sh

@ -824,7 +824,7 @@ php_EXTRA_DIST= \
php/ext/google/protobuf/protobuf.h \ php/ext/google/protobuf/protobuf.h \
php/ext/google/protobuf/wkt.inc \ php/ext/google/protobuf/wkt.inc \
php/generate_descriptor_protos.sh \ php/generate_descriptor_protos.sh \
php/phpunit.xml \ php/generate_test_protos.sh \
php/prepare_c_extension.sh \ php/prepare_c_extension.sh \
php/release.sh \ php/release.sh \
php/src/GPBMetadata/Google/Protobuf/Any.php \ php/src/GPBMetadata/Google/Protobuf/Any.php \
@ -953,14 +953,12 @@ php_EXTRA_DIST= \
php/src/Google/Protobuf/Value.php \ php/src/Google/Protobuf/Value.php \
php/src/phpdoc.dist.xml \ php/src/phpdoc.dist.xml \
php/tests/ArrayTest.php \ php/tests/ArrayTest.php \
php/tests/autoload.php \
php/tests/bootstrap_phpunit.php \
php/tests/compatibility_test.sh \ php/tests/compatibility_test.sh \
php/tests/compile_extension.sh \ php/tests/compile_extension.sh \
php/tests/DescriptorsTest.php \ php/tests/DescriptorsTest.php \
php/tests/EncodeDecodeTest.php \ php/tests/EncodeDecodeTest.php \
php/tests/force_c_ext.php \
php/tests/gdb_test.sh \ php/tests/gdb_test.sh \
php/tests/generate_protos.sh \
php/tests/GeneratedClassTest.php \ php/tests/GeneratedClassTest.php \
php/tests/GeneratedPhpdocTest.php \ php/tests/GeneratedPhpdocTest.php \
php/tests/GeneratedServiceTest.php \ php/tests/GeneratedServiceTest.php \
@ -987,10 +985,8 @@ php_EXTRA_DIST= \
php/tests/proto/test_service.proto \ php/tests/proto/test_service.proto \
php/tests/proto/test_service_namespace.proto \ php/tests/proto/test_service_namespace.proto \
php/tests/proto/test_wrapper_type_setters.proto \ php/tests/proto/test_wrapper_type_setters.proto \
php/tests/test.sh \
php/tests/test_base.php \ php/tests/test_base.php \
php/tests/test_util.php \ php/tests/test_util.php \
php/tests/undefined_test.php \
php/tests/valgrind.supp \ php/tests/valgrind.supp \
php/tests/WellKnownTest.php \ php/tests/WellKnownTest.php \
php/tests/WrapperTypeSettersTest.php php/tests/WrapperTypeSettersTest.php

@ -6,7 +6,7 @@
"homepage": "https://developers.google.com/protocol-buffers/", "homepage": "https://developers.google.com/protocol-buffers/",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"require": { "require": {
"php": ">=5.5.0" "php": ">=7.0.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": ">=5.0.0" "phpunit/phpunit": ">=5.0.0"
@ -19,11 +19,12 @@
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"": "tests/generated" "": "tmp"
} }
}, },
"scripts": { "scripts": {
"test": "tests/generate_protos.sh && 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",
"aggregate_metadata_test": "tests/generate_protos.sh --aggregate_metadata && vendor/bin/phpunit" "test": "./generate_test_protos.sh && vendor/bin/phpunit tests",
"aggregate_metadata_test": "./generate_test_protos.sh --aggregate_metadata && vendor/bin/phpunit tests"
} }
} }

@ -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"

@ -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>

@ -1,7 +1,5 @@
<?php <?php
require_once('generated/Descriptors/TestDescriptorsEnum.php');
require_once('generated/Descriptors/TestDescriptorsMessage.php');
require_once('test_base.php'); require_once('test_base.php');
require_once('test_util.php'); require_once('test_util.php');

@ -1,7 +1,5 @@
<?php <?php
require_once('generated/NoNamespaceEnum.php');
require_once('generated/NoNamespaceMessage.php');
require_once('test_base.php'); require_once('test_base.php');
require_once('test_util.php'); require_once('test_util.php');
@ -759,10 +757,10 @@ class GeneratedClassTest extends TestBase
public function testMessageWithoutNamespace() public function testMessageWithoutNamespace()
{ {
$m = new TestMessage(); $m = new TestMessage();
$n = new NoNameSpaceMessage(); $n = new NoNamespaceMessage();
$m->setOptionalNoNamespaceMessage($n); $m->setOptionalNoNamespaceMessage($n);
$repeatedNoNamespaceMessage = $m->getRepeatedNoNamespaceMessage(); $repeatedNoNamespaceMessage = $m->getRepeatedNoNamespaceMessage();
$repeatedNoNamespaceMessage[] = new NoNameSpaceMessage(); $repeatedNoNamespaceMessage[] = new NoNamespaceMessage();
$m->setRepeatedNoNamespaceMessage($repeatedNoNamespaceMessage); $m->setRepeatedNoNamespaceMessage($repeatedNoNamespaceMessage);
// test nested messages // test nested messages
@ -775,9 +773,9 @@ class GeneratedClassTest extends TestBase
public function testEnumWithoutNamespace() public function testEnumWithoutNamespace()
{ {
$m = new TestMessage(); $m = new TestMessage();
$m->setOptionalNoNamespaceEnum(NoNameSpaceEnum::VALUE_A); $m->setOptionalNoNamespaceEnum(NoNamespaceEnum::VALUE_A);
$repeatedNoNamespaceEnum = $m->getRepeatedNoNamespaceEnum(); $repeatedNoNamespaceEnum = $m->getRepeatedNoNamespaceEnum();
$repeatedNoNamespaceEnum[] = NoNameSpaceEnum::VALUE_A; $repeatedNoNamespaceEnum[] = NoNamespaceEnum::VALUE_A;
$m->setRepeatedNoNamespaceEnum($repeatedNoNamespaceEnum); $m->setRepeatedNoNamespaceEnum($repeatedNoNamespaceEnum);
$this->assertTrue(true); $this->assertTrue(true);
} }

@ -1,7 +1,5 @@
<?php <?php
require_once('generated/NoNamespaceEnum.php');
require_once('generated/NoNamespaceMessage.php');
require_once('test_base.php'); require_once('test_base.php');
require_once('test_util.php'); require_once('test_util.php');

@ -18,7 +18,7 @@ use Google\Protobuf\Internal\CodedOutputStream;
* Please note, this test is only intended to be run without the protobuf C * Please note, this test is only intended to be run without the protobuf C
* extension. * extension.
*/ */
class ImplementationTest extends TestBase class PhpImplementationTest extends TestBase
{ {
/** /**
* Avoid calling setUp, which has void return type (not avalialbe in php7.0). * Avoid calling setUp, which has void return type (not avalialbe in php7.0).

@ -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;
}
}

@ -1,5 +0,0 @@
<?php
require_once("vendor/autoload.php");
error_reporting(E_ALL);

@ -1,20 +1,26 @@
#!/bin/bash #!/bin/bash
set -ex set -e
cd $(dirname $0) cd $(dirname $0)
../prepare_c_extension.sh ../prepare_c_extension.sh
pushd ../ext/google/protobuf pushd ../ext/google/protobuf > /dev/null
phpize --clean
rm -f configure.in configure.ac CONFIGURE_OPTIONS=("./configure" "--with-php-config=$(which php-config)")
phpize
if [ "$1" = "--release" ]; then if [ "$1" != "--release" ]; then
./configure --with-php-config=$(which php-config) CONFIGURE_OPTIONS+=("CFLAGS=-g -O0 -Wall")
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"
fi 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 make
popd popd > /dev/null

@ -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);

@ -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

@ -2,57 +2,7 @@
# phpunit has memory leak by itself. Thus, it cannot be used to test memory leak. # phpunit has memory leak by itself. Thus, it cannot be used to test memory leak.
require_once('generated/NoNamespaceEnum.php'); require_once('../vendor/autoload.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('test_util.php'); require_once('test_util.php');
use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\RepeatedField;

@ -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

@ -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;
}
}

@ -467,14 +467,8 @@ use_php() {
internal_build_cpp internal_build_cpp
} }
use_php_zts() { build_php() {
VERSION=$1 use_php $1
export PATH=/usr/local/php-${VERSION}-zts/bin:$PATH
internal_build_cpp
}
build_php5.6() {
use_php 5.6
pushd php pushd php
rm -rf vendor rm -rf vendor
composer update composer update
@ -483,41 +477,18 @@ build_php5.6() {
(cd conformance && make test_php) (cd conformance && make test_php)
} }
build_php7.0() { test_php_c() {
use_php 7.0
pushd php pushd php
rm -rf vendor rm -rf vendor
composer update composer update
composer test composer test_c
popd
(cd conformance && make test_php)
}
build_php7.0_c() {
use_php 7.0
php/tests/test.sh
pushd conformance
make test_php_c
popd
}
build_php7.0_mixed() {
use_php 7.0
pushd php
rm -rf vendor
composer update
tests/compile_extension.sh
tests/generate_protos.sh
php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
popd popd
(cd conformance && make test_php_c)
} }
build_php7.0_zts_c() { build_php_c() {
use_php_zts 7.0 use_php $1
php/tests/test.sh test_php_c
pushd conformance
make test_php_c
popd
} }
build_php7.0_mac() { build_php7.0_mac() {
@ -528,14 +499,17 @@ build_php7.0_mac() {
test ! -z "$PHP_FOLDER" test ! -z "$PHP_FOLDER"
export PATH="$PHP_FOLDER/bin:$PATH" export PATH="$PHP_FOLDER/bin:$PATH"
# Install Composer
wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/local/bin/composer
chmod a+x /usr/local/bin/composer
# Install valgrind # Install valgrind
echo "#! /bin/bash" > valgrind echo "#! /bin/bash" > valgrind
chmod ug+x valgrind chmod ug+x valgrind
sudo mv valgrind /usr/local/bin/valgrind sudo mv valgrind /usr/local/bin/valgrind
# Test # Test
php/tests/test.sh test_php_c
(cd conformance && make test_php_c)
} }
build_php7.3_mac() { build_php7.3_mac() {
@ -548,14 +522,17 @@ build_php7.3_mac() {
test ! -z "$PHP_FOLDER" test ! -z "$PHP_FOLDER"
export PATH="$PHP_FOLDER/bin:$PATH" export PATH="$PHP_FOLDER/bin:$PATH"
# Install Composer
wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/local/bin/composer
chmod a+x /usr/local/bin/composer
# Install valgrind # Install valgrind
echo "#! /bin/bash" > valgrind echo "#! /bin/bash" > valgrind
chmod ug+x valgrind chmod ug+x valgrind
sudo mv valgrind /usr/local/bin/valgrind sudo mv valgrind /usr/local/bin/valgrind
# Test # Test
php/tests/test.sh test_php_c
(cd conformance && make test_php_c)
} }
build_php_compatibility() { build_php_compatibility() {
@ -568,137 +545,25 @@ build_php_multirequest() {
php/tests/multirequest.sh php/tests/multirequest.sh
} }
build_php7.1() {
use_php 7.1
pushd php
rm -rf vendor
composer update
composer test
popd
(cd conformance && make test_php)
}
build_php7.1_c() {
use_php 7.1
php/tests/test.sh
pushd conformance
make test_php_c
popd
}
build_php7.1_mixed() {
use_php 7.1
pushd php
rm -rf vendor
composer update
tests/compile_extension.sh
tests/generate_protos.sh
php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
popd
}
build_php7.1_zts_c() {
use_php_zts 7.1
php/tests/test.sh
pushd conformance
make test_php_c
popd
}
build_php7.4() {
use_php 7.4
pushd php
rm -rf vendor
composer update
composer test
popd
(cd conformance && make test_php)
}
build_php7.4_c() {
use_php 7.4
php/tests/test.sh
pushd conformance
make test_php_c
popd
}
build_php7.4_mixed() {
use_php 7.4
pushd php
rm -rf vendor
composer update
tests/compile_extension.sh
tests/generate_protos.sh
php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
popd
}
build_php7.4_zts_c() {
use_php_zts 7.4
php/tests/test.sh
pushd conformance
make test_php_c
popd
}
build_php8.0() {
use_php 8.0
pushd php
rm -rf vendor
composer update
composer test
popd
(cd conformance && make test_php)
}
build_php8.0_c() {
use_php 8.0
php/tests/test.sh
pushd conformance
make test_php_c
popd
}
build_php8.0_c_64() {
build_php8.0_c true
}
build_php8.0_mixed() {
use_php 8.0
pushd php
rm -rf vendor
composer update
tests/compile_extension.sh
tests/generate_protos.sh
php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
popd
}
build_php8.0_all() { build_php8.0_all() {
build_php8.0 build_php 8.0
build_php8.0_c_64 build_php_c 8.0
build_php8.0_mixed
} }
build_php_all_32() { build_php_all_32() {
build_php5.6 build_php 7.0
build_php7.0 build_php 7.1
build_php7.1 build_php 7.4
build_php7.4 build_php_c 7.0
build_php7.0_c $1 build_php_c 7.1
build_php7.1_c $1 build_php_c 7.4
build_php7.4_c $1 build_php_c 7.1-zts
build_php7.0_mixed build_php_c 7.2-zts
build_php7.1_mixed build_php_c 7.5-zts
build_php7.4_mixed
build_php7.0_zts_c $1
build_php7.1_zts_c $1
build_php7.4_zts_c $1
} }
build_php_all() { build_php_all() {
build_php_all_32 true build_php_all_32
build_php_multirequest build_php_multirequest
build_php_compatibility build_php_compatibility
} }
@ -737,13 +602,10 @@ Usage: $0 { cpp |
ruby30 | ruby30 |
jruby | jruby |
ruby_all | ruby_all |
php7.0 |
php7.0_c |
php_compatibility |
php7.1 |
php7.1_c |
php_all | php_all |
php8.0_all | php_all_32 |
php7.0_mac |
php7.3_mac |
dist_install | dist_install |
benchmark) benchmark)
" "

Loading…
Cancel
Save