From 7f9c4ae119f84016bf9ce77c5350b6bb993c9d41 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 12:57:57 -0700 Subject: [PATCH 01/11] 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. --- php/composer.json | 6 ++-- php/generate_test_protos.sh | 18 ++++++++++ php/phpunit.xml | 18 ---------- php/tests/DescriptorsTest.php | 2 -- php/tests/GeneratedClassTest.php | 10 +++--- php/tests/GeneratedPhpdocTest.php | 2 -- php/tests/PhpImplementationTest.php | 2 +- php/tests/autoload.php | 27 --------------- php/tests/bootstrap_phpunit.php | 5 --- php/tests/generate_protos.sh | 16 --------- php/tests/memory_leak_test.php | 52 +---------------------------- php/tests/test.sh | 43 ++---------------------- 12 files changed, 30 insertions(+), 171 deletions(-) create mode 100755 php/generate_test_protos.sh delete mode 100644 php/phpunit.xml delete mode 100644 php/tests/autoload.php delete mode 100644 php/tests/bootstrap_phpunit.php delete mode 100755 php/tests/generate_protos.sh diff --git a/php/composer.json b/php/composer.json index 4c1b5ac67582..cdbb4d93d34d 100644 --- a/php/composer.json +++ b/php/composer.json @@ -19,11 +19,11 @@ }, "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": "./generate_test_protos.sh && vendor/bin/phpunit tests", + "aggregate_metadata_test": "./generate_test_protos.sh --aggregate_metadata && vendor/bin/phpunit" } } diff --git a/php/generate_test_protos.sh b/php/generate_test_protos.sh new file mode 100755 index 000000000000..7c28f2a3f2dc --- /dev/null +++ b/php/generate_test_protos.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +cd `dirname $0` + +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 8e7583596bfb..000000000000 --- a/php/phpunit.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - tests/PhpImplementationTest.php - tests/ArrayTest.php - tests/EncodeDecodeTest.php - tests/GeneratedClassTest.php - tests/GeneratedPhpdocTest.php - tests/MapFieldTest.php - tests/WellKnownTest.php - tests/DescriptorsTest.php - tests/GeneratedServiceTest.php - tests/WrapperTypeSettersTest.php - - - diff --git a/php/tests/DescriptorsTest.php b/php/tests/DescriptorsTest.php index ca7e8f369061..4f17a49571f6 100644 --- a/php/tests/DescriptorsTest.php +++ b/php/tests/DescriptorsTest.php @@ -1,7 +1,5 @@ setOptionalNoNamespaceMessage($n); $repeatedNoNamespaceMessage = $m->getRepeatedNoNamespaceMessage(); - $repeatedNoNamespaceMessage[] = new NoNameSpaceMessage(); + $repeatedNoNamespaceMessage[] = new NoNamespaceMessage(); $m->setRepeatedNoNamespaceMessage($repeatedNoNamespaceMessage); // test nested messages @@ -775,9 +773,9 @@ public function testMessageWithoutNamespace() 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 18963a9b39cf..a0b912b5e11c 100644 --- a/php/tests/GeneratedPhpdocTest.php +++ b/php/tests/GeneratedPhpdocTest.php @@ -1,7 +1,5 @@ $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 8452f1589645..000000000000 --- a/php/tests/bootstrap_phpunit.php +++ /dev/null @@ -1,5 +0,0 @@ - Date: Mon, 3 May 2021 17:30:43 -0700 Subject: [PATCH 02/11] 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. --- php/composer.json | 3 ++- php/generate_test_protos.sh | 9 +++++++++ php/tests/compile_extension.sh | 30 +++++++++++++++++------------ php/tests/test.sh | 35 ---------------------------------- 4 files changed, 29 insertions(+), 48 deletions(-) delete mode 100755 php/tests/test.sh diff --git a/php/composer.json b/php/composer.json index cdbb4d93d34d..9953284d8710 100644 --- a/php/composer.json +++ b/php/composer.json @@ -23,7 +23,8 @@ } }, "scripts": { + "test_c": "./generate_test_protos.sh && ./tests/compile_extension.sh && php -dextension=ext/google/protobuf/modules/protobuf.so vendor/bin/phpunit tests", "test": "./generate_test_protos.sh && vendor/bin/phpunit tests", - "aggregate_metadata_test": "./generate_test_protos.sh --aggregate_metadata && vendor/bin/phpunit" + "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 index 7c28f2a3f2dc..8614c95fcccf 100755 --- a/php/generate_test_protos.sh +++ b/php/generate_test_protos.sh @@ -4,6 +4,15 @@ set -e cd `dirname $0` +if [[ -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 diff --git a/php/tests/compile_extension.sh b/php/tests/compile_extension.sh index 85c73c6eb5dd..d26fcb472ee9 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/test.sh b/php/tests/test.sh deleted file mode 100755 index 00690f0172ec..000000000000 --- a/php/tests/test.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -set -ex - -cd $(dirname $0) - -../generate_test_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 - -php -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap ../vendor/autoload.php . -php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap ../vendor/autoload.php . From c058d007aa862d36912cb7cd84138c83d37f8c1f Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 18:23:18 -0700 Subject: [PATCH 03/11] Added assertions to verify that the C test doesn't use PHP sources. --- php/composer.json | 4 ++-- php/tests/force_c_ext.php | 14 ++++++++++++++ tests.sh | 8 +++++--- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 php/tests/force_c_ext.php diff --git a/php/composer.json b/php/composer.json index 9953284d8710..5ea49edb2ec4 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" @@ -23,7 +23,7 @@ } }, "scripts": { - "test_c": "./generate_test_protos.sh && ./tests/compile_extension.sh && php -dextension=ext/google/protobuf/modules/protobuf.so vendor/bin/phpunit tests", + "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/tests/force_c_ext.php b/php/tests/force_c_ext.php new file mode 100644 index 000000000000..afc63c52fd9f --- /dev/null +++ b/php/tests/force_c_ext.php @@ -0,0 +1,14 @@ + Date: Mon, 3 May 2021 19:51:46 -0700 Subject: [PATCH 04/11] Updated tests.sh for the new PHP testing commands. --- tests.sh | 157 ++++++++++--------------------------------------------- 1 file changed, 29 insertions(+), 128 deletions(-) diff --git a/tests.sh b/tests.sh index 4005dfd996cb..a75951be364c 100755 --- a/tests.sh +++ b/tests.sh @@ -467,14 +467,8 @@ use_php() { internal_build_cpp } -use_php_zts() { - VERSION=$1 - export PATH=/usr/local/php-${VERSION}-zts/bin:$PATH - internal_build_cpp -} - -build_php5.6() { - use_php 5.6 +build_php() { + use_php $1 pushd php rm -rf vendor composer update @@ -483,18 +477,8 @@ build_php5.6() { (cd conformance && make test_php) } -build_php7.0() { - use_php 7.0 - pushd php - rm -rf vendor - composer update - composer test - popd - (cd conformance && make test_php) -} - -build_php7.0_c() { - use_php 7.0 +build_php_c() { + use_php $1 pushd php rm -rf vendor composer update @@ -503,23 +487,16 @@ build_php7.0_c() { (cd conformance && make test_php_c) } -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 +build_php7.0() { + build_php 7.0 +} + +build_php7.0_c() { + build_php_c 7.0 } build_php7.0_zts_c() { - use_php_zts 7.0 - php/tests/test.sh - pushd conformance - make test_php_c - popd + build_php_c 7.0-zts } build_php7.0_mac() { @@ -571,132 +548,56 @@ build_php_multirequest() { } build_php7.1() { - use_php 7.1 - pushd php - rm -rf vendor - composer update - composer test - popd - (cd conformance && make test_php) + build_php 7.1 } 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_php_c 7.1 } build_php7.1_zts_c() { - use_php_zts 7.1 - php/tests/test.sh - pushd conformance - make test_php_c - popd + build_php_c 7.1-zts } build_php7.4() { - use_php 7.4 - pushd php - rm -rf vendor - composer update - composer test - popd - (cd conformance && make test_php) + build_php 7.4 } 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_php_c 7.4 } build_php7.4_zts_c() { - use_php_zts 7.4 - php/tests/test.sh - pushd conformance - make test_php_c - popd + build_php_c 7.4-zts } build_php8.0() { - use_php 8.0 - pushd php - rm -rf vendor - composer update - composer test - popd - (cd conformance && make test_php) + build_php 8.0 } build_php8.0_c() { - use_php 8.0 - php/tests/test.sh - pushd conformance - make test_php_c - popd + build_php_c 8.0 } 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_php_c 8.0 } build_php8.0_all() { build_php8.0 build_php8.0_c_64 - build_php8.0_mixed } build_php_all_32() { - build_php5.6 - build_php7.0 - build_php7.1 - build_php7.4 - build_php7.0_c $1 - build_php7.1_c $1 - build_php7.4_c $1 - build_php7.0_mixed - build_php7.1_mixed - build_php7.4_mixed - build_php7.0_zts_c $1 - build_php7.1_zts_c $1 - build_php7.4_zts_c $1 + build_php 7.0 + build_php 7.1 + build_php 7.4 + build_php_c 7.0 + build_php_c 7.1 + build_php_c 7.4 + build_php_c 7.1-zts + build_php_c 7.2-zts + build_php_c 7.5-zts } build_php_all() { From f5ac4d1c6e56bd5a42a61655815d73edca32af1e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 20:05:18 -0700 Subject: [PATCH 05/11] Removed obsolete rules from tests.sh. --- tests.sh | 67 +++----------------------------------------------------- 1 file changed, 3 insertions(+), 64 deletions(-) diff --git a/tests.sh b/tests.sh index a75951be364c..e5b88ec5edd4 100755 --- a/tests.sh +++ b/tests.sh @@ -487,18 +487,6 @@ build_php_c() { (cd conformance && make test_php_c) } -build_php7.0() { - build_php 7.0 -} - -build_php7.0_c() { - build_php_c 7.0 -} - -build_php7.0_zts_c() { - build_php_c 7.0-zts -} - build_php7.0_mac() { internal_build_cpp # Install PHP @@ -547,48 +535,7 @@ build_php_multirequest() { php/tests/multirequest.sh } -build_php7.1() { - build_php 7.1 -} - -build_php7.1_c() { - build_php_c 7.1 -} - -build_php7.1_zts_c() { - build_php_c 7.1-zts -} - -build_php7.4() { - build_php 7.4 -} - -build_php7.4_c() { - build_php_c 7.4 -} - -build_php7.4_zts_c() { - build_php_c 7.4-zts -} - -build_php8.0() { - build_php 8.0 -} - -build_php8.0_c() { - build_php_c 8.0 -} - -build_php8.0_c_64() { - build_php_c 8.0 -} - -build_php8.0_all() { - build_php8.0 - build_php8.0_c_64 -} - -build_php_all_32() { +build_php_all() { build_php 7.0 build_php 7.1 build_php 7.4 @@ -598,10 +545,6 @@ build_php_all_32() { build_php_c 7.1-zts build_php_c 7.2-zts build_php_c 7.5-zts -} - -build_php_all() { - build_php_all_32 true build_php_multirequest build_php_compatibility } @@ -640,13 +583,9 @@ Usage: $0 { cpp | ruby30 | jruby | ruby_all | - php7.0 | - php7.0_c | - php_compatibility | - php7.1 | - php7.1_c | php_all | - php8.0_all | + php7.0_mac | + php7.3_mac | dist_install | benchmark) " From c4720b4b1c592bf9b0f0e8e69e4fa1ec706d7f20 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 20:49:52 -0700 Subject: [PATCH 06/11] Fixed generate_test_protos.sh for when tmp does not exist. Also removed undefined_test.php and fixed Makefile.am. --- Makefile.am | 7 +- php/generate_test_protos.sh | 2 +- php/tests/undefined_test.php | 920 ----------------------------------- 3 files changed, 2 insertions(+), 927 deletions(-) delete mode 100644 php/tests/undefined_test.php diff --git a/Makefile.am b/Makefile.am index ac308d897b53..4298e5ff687e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -824,7 +824,7 @@ php_EXTRA_DIST= \ php/ext/google/protobuf/protobuf.h \ php/ext/google/protobuf/wkt.inc \ php/generate_descriptor_protos.sh \ - php/phpunit.xml \ + php/generate_test_protos.sh \ php/prepare_c_extension.sh \ php/release.sh \ php/src/GPBMetadata/Google/Protobuf/Any.php \ @@ -953,14 +953,11 @@ php_EXTRA_DIST= \ php/src/Google/Protobuf/Value.php \ php/src/phpdoc.dist.xml \ php/tests/ArrayTest.php \ - php/tests/autoload.php \ - php/tests/bootstrap_phpunit.php \ php/tests/compatibility_test.sh \ php/tests/compile_extension.sh \ php/tests/DescriptorsTest.php \ php/tests/EncodeDecodeTest.php \ php/tests/gdb_test.sh \ - php/tests/generate_protos.sh \ php/tests/GeneratedClassTest.php \ php/tests/GeneratedPhpdocTest.php \ php/tests/GeneratedServiceTest.php \ @@ -987,10 +984,8 @@ php_EXTRA_DIST= \ php/tests/proto/test_service.proto \ php/tests/proto/test_service_namespace.proto \ php/tests/proto/test_wrapper_type_setters.proto \ - php/tests/test.sh \ php/tests/test_base.php \ php/tests/test_util.php \ - php/tests/undefined_test.php \ php/tests/valgrind.supp \ php/tests/WellKnownTest.php \ php/tests/WrapperTypeSettersTest.php diff --git a/php/generate_test_protos.sh b/php/generate_test_protos.sh index 8614c95fcccf..0aa4bdbe4314 100755 --- a/php/generate_test_protos.sh +++ b/php/generate_test_protos.sh @@ -4,7 +4,7 @@ set -e cd `dirname $0` -if [[ -z $(find tests/proto ../src/protoc -newer tmp) ]]; then +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 diff --git a/php/tests/undefined_test.php b/php/tests/undefined_test.php deleted file mode 100644 index 935d8be7d433..000000000000 --- a/php/tests/undefined_test.php +++ /dev/null @@ -1,920 +0,0 @@ -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; - } - -} From 82154df1fbfca16e768a7435a9c7047261c817d8 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 20:58:32 -0700 Subject: [PATCH 07/11] Added php8.0_all again which is still used. --- tests.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests.sh b/tests.sh index e5b88ec5edd4..498755585d36 100755 --- a/tests.sh +++ b/tests.sh @@ -535,6 +535,11 @@ build_php_multirequest() { php/tests/multirequest.sh } +build_php8.0_all() { + build_php 8.0 + build_php_c 8.0 +} + build_php_all() { build_php 7.0 build_php 7.1 From ba9539c7442220ae0f3a7a0a2afeaaaddc58b08b Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 21:01:00 -0700 Subject: [PATCH 08/11] Added missing file to Makefile.am. --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 4298e5ff687e..cab595ded3f6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -957,6 +957,7 @@ php_EXTRA_DIST= \ php/tests/compile_extension.sh \ php/tests/DescriptorsTest.php \ php/tests/EncodeDecodeTest.php \ + php/tests/force_c_ext.php \ php/tests/gdb_test.sh \ php/tests/GeneratedClassTest.php \ php/tests/GeneratedPhpdocTest.php \ From da2d7f39abc41da972128aa708d6ee91160f427e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 21:10:14 -0700 Subject: [PATCH 09/11] Re-added php_all_32 rule which is also still used. --- tests.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests.sh b/tests.sh index 498755585d36..4d8e5df980df 100755 --- a/tests.sh +++ b/tests.sh @@ -540,7 +540,7 @@ build_php8.0_all() { build_php_c 8.0 } -build_php_all() { +build_php_all_32() { build_php 7.0 build_php 7.1 build_php 7.4 @@ -550,6 +550,10 @@ build_php_all() { build_php_c 7.1-zts build_php_c 7.2-zts build_php_c 7.5-zts +} + +build_php_all() { + build_php_all_32 build_php_multirequest build_php_compatibility } @@ -589,6 +593,7 @@ Usage: $0 { cpp | jruby | ruby_all | php_all | + php_all_32 | php7.0_mac | php7.3_mac | dist_install | From f9e5b7c511f1d32f7e544abb0d2b2c27941bbf7d Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 21:59:32 -0700 Subject: [PATCH 10/11] Updated testing commands for macOS and download composer. --- tests.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests.sh b/tests.sh index 4d8e5df980df..cf3326c66606 100755 --- a/tests.sh +++ b/tests.sh @@ -477,8 +477,7 @@ build_php() { (cd conformance && make test_php) } -build_php_c() { - use_php $1 +test_php_c() { pushd php rm -rf vendor composer update @@ -487,6 +486,11 @@ build_php_c() { (cd conformance && make test_php_c) } +build_php_c() { + use_php $1 + test_php_c +} + build_php7.0_mac() { internal_build_cpp # Install PHP @@ -495,14 +499,17 @@ build_php7.0_mac() { test ! -z "$PHP_FOLDER" export PATH="$PHP_FOLDER/bin:$PATH" + # Install Composer + wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/bin/composer + chmod a+x /usr/bin/composer + # Install valgrind echo "#! /bin/bash" > valgrind chmod ug+x valgrind sudo mv valgrind /usr/local/bin/valgrind # Test - php/tests/test.sh - (cd conformance && make test_php_c) + test_php_c } build_php7.3_mac() { @@ -515,14 +522,17 @@ build_php7.3_mac() { test ! -z "$PHP_FOLDER" export PATH="$PHP_FOLDER/bin:$PATH" + # Install Composer + wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/bin/composer + chmod a+x /usr/bin/composer + # Install valgrind echo "#! /bin/bash" > valgrind chmod ug+x valgrind sudo mv valgrind /usr/local/bin/valgrind # Test - php/tests/test.sh - (cd conformance && make test_php_c) + test_php_c } build_php_compatibility() { From dc2d2b0383b3e21e98cb221946075a278bd74f31 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 3 May 2021 23:31:03 -0700 Subject: [PATCH 11/11] Use /usr/local/bin on mac instead of /usr/bin, since the latter is not writable. --- tests.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests.sh b/tests.sh index cf3326c66606..e9dbed7b50d4 100755 --- a/tests.sh +++ b/tests.sh @@ -500,8 +500,8 @@ build_php7.0_mac() { export PATH="$PHP_FOLDER/bin:$PATH" # Install Composer - wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/bin/composer - chmod a+x /usr/bin/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 echo "#! /bin/bash" > valgrind @@ -523,8 +523,8 @@ build_php7.3_mac() { export PATH="$PHP_FOLDER/bin:$PATH" # Install Composer - wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/bin/composer - chmod a+x /usr/bin/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 echo "#! /bin/bash" > valgrind