aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/tests/compatibility_test.sh
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2017-05-05 11:14:11 -0700
committerGravatar GitHub <noreply@github.com>2017-05-05 11:14:11 -0700
commit25abd7b7e7a6e7f3dfabe6b3a762e2346b2ae185 (patch)
tree295af0fef9c2a8240d06de6920eaa7fd453564d9 /php/tests/compatibility_test.sh
parent483396068d7788efca4d51584d160dc4da28c99d (diff)
Add compatibility test for php. (#3041)
* Add compatibility test for php. * Revert API incompatible change.
Diffstat (limited to 'php/tests/compatibility_test.sh')
-rwxr-xr-xphp/tests/compatibility_test.sh111
1 files changed, 111 insertions, 0 deletions
diff --git a/php/tests/compatibility_test.sh b/php/tests/compatibility_test.sh
new file mode 100755
index 00000000..e05b2af1
--- /dev/null
+++ b/php/tests/compatibility_test.sh
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+use_php() {
+ VERSION=$1
+ PHP=`which php`
+ PHP_CONFIG=`which php-config`
+ PHPIZE=`which phpize`
+ ln -sfn "/usr/local/php-${VERSION}/bin/php" $PHP
+ ln -sfn "/usr/local/php-${VERSION}/bin/php-config" $PHP_CONFIG
+ ln -sfn "/usr/local/php-${VERSION}/bin/phpize" $PHPIZE
+}
+
+generate_proto() {
+ PROTOC1=$1
+ PROTOC2=$2
+
+ rm -rf generated
+ mkdir generated
+
+ $PROTOC1 --php_out=generated proto/test_include.proto
+ $PROTOC2 --php_out=generated proto/test.proto proto/test_no_namespace.proto proto/test_prefix.proto
+ pushd ../../src
+ $PROTOC2 --php_out=../php/tests/generated google/protobuf/empty.proto
+ $PROTOC2 --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto
+ popd
+}
+
+set -ex
+
+# Change to the script's directory.
+cd $(dirname $0)
+
+# The old version of protobuf that we are testing compatibility against.
+case "$1" in
+ ""|3.3.0)
+ OLD_VERSION=3.3.0
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.3.0/protoc-3.3.0-linux-x86_64.exe
+ ;;
+ *)
+ echo "[ERROR]: Unknown version number: $1"
+ exit 1
+ ;;
+esac
+
+# Extract the latest protobuf version number.
+VERSION_NUMBER=`grep "PHP_PROTOBUF_VERSION" ../ext/google/protobuf/protobuf.h | sed "s|#define PHP_PROTOBUF_VERSION \"\(.*\)\"|\1|"`
+
+echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"
+
+# Check protoc
+[ -f ../../src/protoc ] || {
+ echo "[ERROR]: Please build protoc first."
+ exit 1
+}
+
+# Download old test.
+rm -rf protobuf
+git clone https://github.com/google/protobuf.git
+pushd protobuf
+git checkout v$OLD_VERSION
+popd
+
+# Build and copy the new runtime
+use_php 5.5
+pushd ../ext/google/protobuf
+make clean || true
+phpize && ./configure && make
+popd
+
+rm -rf protobuf/php/ext
+rm -rf protobuf/php/src
+cp -r ../ext protobuf/php/ext/
+cp -r ../src protobuf/php/src/
+
+# Download old version protoc compiler (for linux)
+wget $OLD_VERSION_PROTOC -O old_protoc
+chmod +x old_protoc
+
+NEW_PROTOC=`pwd`/../../src/protoc
+OLD_PROTOC=`pwd`/old_protoc
+cd protobuf/php
+cp -r /usr/local/vendor-5.5 vendor
+wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit
+cd tests
+
+# Test A.1:
+# proto set 1: use old version
+# proto set 2 which may import protos in set 1: use old version
+generate_proto $OLD_PROTOC $OLD_PROTOC
+./test.sh
+pushd ..
+phpunit
+popd
+
+# Test A.2:
+# proto set 1: use new version
+# proto set 2 which may import protos in set 1: use old version
+generate_proto $NEW_PROTOC $OLD_PROTOC
+./test.sh
+pushd ..
+phpunit
+popd
+
+# Test A.3:
+# proto set 1: use old version
+# proto set 2 which may import protos in set 1: use new version
+generate_proto $OLD_PROTOC $NEW_PROTOC
+./test.sh
+pushd ..
+phpunit
+popd