Skip to content

Commit 1b272af

Browse files
authored
fix: php version check (GoogleCloudPlatform#1563)
1 parent 4051088 commit 1b272af

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

functions/helloworld_pubsub/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"require": {
3+
"php": ">= 7.4",
34
"cloudevents/sdk-php": "^1.0",
45
"google/cloud-functions-framework": "^1.1"
56
},

testing/check_version.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
require __DIR__ . '/vendor/autoload.php';
4+
5+
if (count($argv) > 2) {
6+
die('Usage: check_version.php CONSTRAINT' . PHP_EOL);
7+
}
8+
9+
if ('null' === $argv[1]) {
10+
// If there is no php constraint, it satisfies
11+
echo '0';
12+
return;
13+
}
14+
15+
echo Composer\Semver\Semver::satisfies(PHP_VERSION, $argv[1]) ? '0' : '1';

testing/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"google/cloud-tools": "dev-master",
99
"guzzlehttp/guzzle": "^7.0",
1010
"phpunit/phpunit": "^7|^8",
11-
"friendsofphp/php-cs-fixer": "^3.0"
11+
"friendsofphp/php-cs-fixer": "^3.0",
12+
"composer/semver": "^3.2"
1213
}
1314
}

testing/run_test_suite.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ do
170170
# Generate the lock file (required for check-platform-reqs)
171171
composer update --ignore-platform-reqs
172172
# If the PHP required version is too low, skip the test
173-
if composer check-platform-reqs | grep "requires php" | grep failed ; then
173+
EXPLICITLY_SKIPPED=$(php $TESTDIR/check_version.php "$(cat composer.json | jq -r .require.php)");
174+
if composer check-platform-reqs | grep "requires php" | grep failed && [ "$EXPLICITLY_SKIPPED" -eq "1" ]; then
174175
echo "Skipping tests in $DIR (incompatible PHP version)"
175176
else
176177
# Run composer without "-q"

0 commit comments

Comments
 (0)