Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
17 changed files
with
105 additions
and
1,313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.