1#!/bin/bash 2 3function generate_proto() { 4 PROTOC1=$1 5 PROTOC2=$2 6 7 rm -rf generated 8 mkdir generated 9 10 $PROTOC1 --php_out=generated proto/test_include.proto 11 $PROTOC2 --php_out=generated \ 12 -I../../src -I. \ 13 proto/empty/echo.proto \ 14 proto/test.proto \ 15 proto/test_no_namespace.proto \ 16 proto/test_prefix.proto \ 17 proto/test_php_namespace.proto \ 18 proto/test_empty_php_namespace.proto \ 19 proto/test_reserved_enum_lower.proto \ 20 proto/test_reserved_enum_upper.proto \ 21 proto/test_reserved_enum_value_lower.proto \ 22 proto/test_reserved_enum_value_upper.proto \ 23 proto/test_reserved_message_lower.proto \ 24 proto/test_reserved_message_upper.proto \ 25 proto/test_service.proto \ 26 proto/test_service_namespace.proto \ 27 proto/test_wrapper_type_setters.proto \ 28 proto/test_descriptors.proto 29 30 pushd ../../src 31 $PROTOC2 --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto 32 popd 33} 34 35# Remove tests to expect error. These were added to API tests by mistake. 36function remove_error_test() { 37 local TEMPFILE=`tempfile` 38 cat $1 | \ 39 awk -v file=`basename $1` -v dir=`basename $(dirname $1)` ' 40 BEGIN { 41 show = 1 42 } 43 /@expectedException PHPUnit_Framework_Error/ { show = 0; next; } 44 / *\*\// { print; next; } 45 / *}/ { 46 if (!show) { 47 show = 1; 48 next; 49 } 50 } 51 show { print } 52 ' > $TEMPFILE 53 cp $TEMPFILE $1 54} 55 56set -ex 57 58# Change to the script's directory. 59cd $(dirname $0) 60 61OLD_VERSION=$1 62OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe 63 64# Extract the latest protobuf version number. 65VERSION_NUMBER=`grep "PHP_PROTOBUF_VERSION" ../ext/google/protobuf/protobuf.h | sed "s|#define PHP_PROTOBUF_VERSION \"\(.*\)\"|\1|"` 66 67echo "Running compatibility tests between current $VERSION_NUMBER and released $OLD_VERSION" 68 69# Check protoc 70[ -f ../../src/protoc ] || { 71 echo "[ERROR]: Please build protoc first." 72 exit 1 73} 74 75# Download old test. 76rm -rf protobuf 77git clone https://github.com/protocolbuffers/protobuf.git 78pushd protobuf 79git checkout v$OLD_VERSION 80popd 81 82# Build and copy the new runtime 83pushd ../ext/google/protobuf 84make clean || true 85phpize && ./configure && make 86popd 87 88rm -rf protobuf/php/ext 89rm -rf protobuf/php/src 90cp -r ../ext protobuf/php/ext/ 91cp -r ../src protobuf/php/src/ 92 93# Download old version protoc compiler (for linux) 94wget $OLD_VERSION_PROTOC -O old_protoc 95chmod +x old_protoc 96 97NEW_PROTOC=`pwd`/../../src/protoc 98OLD_PROTOC=`pwd`/old_protoc 99cd protobuf/php 100composer install 101 102# Remove implementation detail tests. 103# TODO(teboring): Temporarily disable encode_decode_test.php. In 3.13.0-rc1, 104# repeated primitive field encoding is changed to packed, which is a bug fix. 105# However, this fails the compatibility test which hard coded old encoding. 106# Will reenable the test after making a release. After the version bump, the 107# compatibility test will use the updated test code. 108tests=( array_test.php generated_class_test.php map_field_test.php well_known_test.php ) 109sed -i.bak '/php_implementation_test.php/d' phpunit.xml 110sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml 111sed -i.bak '/encode_decode_test.php/d' phpunit.xml 112sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh 113sed -i.bak 's/generated_service_test.php//g' tests/test.sh 114sed -i.bak 's/encode_decode_test.php//g' tests/test.sh 115sed -i.bak '/memory_leak_test.php/d' tests/test.sh 116sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php 117sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php 118sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php 119sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php 120for t in "${tests[@]}" 121do 122 remove_error_test tests/$t 123done 124 125cd tests 126 127# Test A.1: 128# proto set 1: use old version 129# proto set 2 which may import protos in set 1: use old version 130generate_proto $OLD_PROTOC $OLD_PROTOC 131./test.sh 132pushd .. 133./vendor/bin/phpunit 134popd 135 136# Test A.2: 137# proto set 1: use new version 138# proto set 2 which may import protos in set 1: use old version 139generate_proto $NEW_PROTOC $OLD_PROTOC 140./test.sh 141pushd .. 142./vendor/bin/phpunit 143popd 144 145# Test A.3: 146# proto set 1: use old version 147# proto set 2 which may import protos in set 1: use new version 148generate_proto $OLD_PROTOC $NEW_PROTOC 149./test.sh 150pushd .. 151./vendor/bin/phpunit 152popd 153