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