From e1cef70f66a2fbce5aa5d84e9242709734295063 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 16 Oct 2024 09:25:08 +0200 Subject: [PATCH] PHPLIB-1502: Test with PHP 8.4 (#1484) * PHPLIB-1502: Test with PHP 8.4 * Remove psalm from dependencies on PHP 8.4 * Suppress deprecations in tests expecting no output * Skip test failing due to PHPUnit deprecations * Skip failing test on PHP 8.4 --- .evergreen/config/functions.yml | 6 +- .evergreen/config/generate-config.php | 5 +- .../build/build-extension-next-minor.yml | 10 +++ .../generated/build/build-extension.yml | 28 +++++++++ .../test-variant/modern-php-full.yml | 61 +++++++++++++++++++ .evergreen/install-composer.sh | 5 ++ tests/GridFS/BucketFunctionalTest.php | 6 ++ tests/Model/CodecCursorFunctionalTest.php | 6 ++ .../Constraint/MatchesTest.php | 6 ++ 9 files changed, 129 insertions(+), 4 deletions(-) diff --git a/.evergreen/config/functions.yml b/.evergreen/config/functions.yml index f53dba0e1..34f7c3960 100644 --- a/.evergreen/config/functions.yml +++ b/.evergreen/config/functions.yml @@ -325,9 +325,9 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - file="${PROJECT_DIRECTORY}/.evergreen/install-composer.sh" - # Don't use ${file} syntax here because evergreen treats it as an empty expansion. - [ -f "$file" ] && DEPENDENCIES=${DEPENDENCIES} bash $file || echo "$file not available, skipping" + DEPENDENCIES=${DEPENDENCIES} \ + PHP_VERSION=${PHP_VERSION} \ + bash ${PROJECT_DIRECTORY}/.evergreen/install-composer.sh "start load balancer": - command: shell.exec diff --git a/.evergreen/config/generate-config.php b/.evergreen/config/generate-config.php index f80c54a84..227813b8b 100644 --- a/.evergreen/config/generate-config.php +++ b/.evergreen/config/generate-config.php @@ -3,6 +3,7 @@ // Supported PHP versions. Add new versions to the beginning of the list $modernPhpVersions = [ + '8.4', '8.3', '8.2', '8.1', @@ -13,7 +14,9 @@ ]; $supportedPhpVersions = array_merge($modernPhpVersions, $legacyPhpVersions); -$latestPhpVersion = max($supportedPhpVersions); +// TODO: use max() once PHP 8.4 is stable +//$latestPhpVersion = max($supportedPhpVersions); +$latestPhpVersion = '8.3'; $lowestPhpVersion = min($supportedPhpVersions); // Supported MongoDB versions. Add new versions after "rapid" diff --git a/.evergreen/config/generated/build/build-extension-next-minor.yml b/.evergreen/config/generated/build/build-extension-next-minor.yml index 5bac183b8..98996f211 100644 --- a/.evergreen/config/generated/build/build-extension-next-minor.yml +++ b/.evergreen/config/generated/build/build-extension-next-minor.yml @@ -1,5 +1,15 @@ # This file is generated automatically - please edit the "templates/build/build-extension-next-minor.yml" template file instead. tasks: + - name: "build-php-8.4-next-minor" + tags: ["build", "php8.4", "next-minor"] + commands: + - func: "locate PHP binaries" + vars: + PHP_VERSION: "8.4" + - func: "compile extension" + vars: + EXTENSION_BRANCH: "v1.x" + - func: "upload extension" - name: "build-php-8.3-next-minor" tags: ["build", "php8.3", "next-minor"] commands: diff --git a/.evergreen/config/generated/build/build-extension.yml b/.evergreen/config/generated/build/build-extension.yml index 1240edccd..bf348f550 100644 --- a/.evergreen/config/generated/build/build-extension.yml +++ b/.evergreen/config/generated/build/build-extension.yml @@ -1,5 +1,33 @@ # This file is generated automatically - please edit the "templates/build/build-extension.yml" template file instead. tasks: + - name: "build-php-8.4" + tags: ["build", "php8.4", "stable", "pr", "tag"] + commands: + - func: "locate PHP binaries" + vars: + PHP_VERSION: "8.4" + - func: "compile extension" + - func: "upload extension" + - name: "build-php-8.4-lowest" + tags: ["build", "php8.4", "lowest", "pr", "tag"] + commands: + - func: "locate PHP binaries" + vars: + PHP_VERSION: "8.4" + - func: "compile extension" + vars: + EXTENSION_VERSION: "1.20.0" + - func: "upload extension" + - name: "build-php-8.4-next-stable" + tags: ["build", "php8.4", "next-stable", "pr", "tag"] + commands: + - func: "locate PHP binaries" + vars: + PHP_VERSION: "8.4" + - func: "compile extension" + vars: + EXTENSION_BRANCH: "v1.20" + - func: "upload extension" - name: "build-php-8.3" tags: ["build", "php8.3", "stable", "pr", "tag"] commands: diff --git a/.evergreen/config/generated/test-variant/modern-php-full.yml b/.evergreen/config/generated/test-variant/modern-php-full.yml index 37845f33e..24c0a6f8d 100644 --- a/.evergreen/config/generated/test-variant/modern-php-full.yml +++ b/.evergreen/config/generated/test-variant/modern-php-full.yml @@ -1,6 +1,67 @@ # This file is generated automatically - please edit the "templates/test-variant/modern-php-full.yml" template file instead. buildvariants: # Test MongoDB >= 7.0 + - name: test-debian12-php-8.4-local + tags: ["test", "debian", "x64", "php8.4", "pr", "tag"] + display_name: "Test: Debian 12, PHP 8.4" + run_on: debian12-small + expansions: + FETCH_BUILD_VARIANT: "build-debian12" + FETCH_BUILD_TASK: "build-php-8.4" + PHP_VERSION: "8.4" + VARIANT: debian12 + depends_on: + - variant: "build-debian12" + name: "build-php-8.4" + tasks: + - ".standalone .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".replicaset .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".sharded .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".loadbalanced .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - "test_serverless_task_group" + - "test_serverless_proxy_task_group" + - "test-atlas-data-lake" + + # Test MongoDB 5.0 and 6.0 + - name: test-debian11-php-8.4-local + tags: ["test", "debian", "x64", "php8.4", "pr", "tag"] + display_name: "Test: Debian 11, PHP 8.4" + run_on: debian11-small + expansions: + FETCH_BUILD_VARIANT: "build-debian11" + FETCH_BUILD_TASK: "build-php-8.4" + PHP_VERSION: "8.4" + depends_on: + - variant: "build-debian11" + name: "build-php-8.4" + tasks: + # Remember to add new major versions here as they are released + - ".standalone .local !.csfle !.4.0 !.4.2 !.4.4 !.7.0 !.8.0 !.rapid !.latest" + - ".replicaset .local !.csfle !.4.0 !.4.2 !.4.4 !.7.0 !.8.0 !.rapid !.latest" + - ".sharded .local !.csfle !.4.0 !.4.2 !.4.4 !.7.0 !.8.0 !.rapid !.latest" + - ".loadbalanced .local !.csfle !.4.0 !.4.2 !.4.4 !.7.0 !.8.0 !.rapid !.latest" + + # Test versions < 5.0 + - name: test-rhel80-php-8.4 + tags: ["test", "debian", "x64", "php8.4", "pr", "tag"] + display_name: "Test: RHEL 8.0, PHP 8.4" + run_on: rhel80-small + expansions: + FETCH_BUILD_VARIANT: "build-rhel80" + FETCH_BUILD_TASK: "build-php-8.4" + PHP_VERSION: "8.4" + depends_on: + - variant: "build-rhel80" + name: "build-php-8.4" + tasks: + # Remember to add new major versions here as they are released + - ".standalone .local !.csfle !.6.0 !.7.0 !.8.0 !.rapid !.latest" + - ".replicaset .local !.csfle !.6.0 !.7.0 !.8.0 !.rapid !.latest" + - ".sharded .local !.csfle !.6.0 !.7.0 !.8.0 !.rapid !.latest" + - ".loadbalanced .local !.csfle !.6.0 !.7.0 !.8.0 !.rapid !.latest" + - "test_atlas_task_group" + - ".csfle" + # Test MongoDB >= 7.0 - name: test-debian12-php-8.3-local tags: ["test", "debian", "x64", "php8.3", "pr", "tag"] display_name: "Test: Debian 12, PHP 8.3" diff --git a/.evergreen/install-composer.sh b/.evergreen/install-composer.sh index 625d1be27..771644e56 100644 --- a/.evergreen/install-composer.sh +++ b/.evergreen/install-composer.sh @@ -38,4 +38,9 @@ php --ri mongodb install_composer +# Remove psalm as it's not compatible with PHP 8.4: https://github.com/vimeo/psalm/pull/10928 +if [ "$PHP_VERSION" == "8.4" ]; then + php composer.phar remove --no-update --dev vimeo/psalm +fi + php composer.phar update $COMPOSER_FLAGS diff --git a/tests/GridFS/BucketFunctionalTest.php b/tests/GridFS/BucketFunctionalTest.php index 46c0c9294..9498e586d 100644 --- a/tests/GridFS/BucketFunctionalTest.php +++ b/tests/GridFS/BucketFunctionalTest.php @@ -860,6 +860,9 @@ public function testDanglingOpenWritableStream(): void $code = <<<'PHP' require '%s'; require '%s'; + // Don't report deprecations - if the issue exists this code will + // result in a fatal error + error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED); $client = MongoDB\Tests\FunctionalTestCase::createTestClient(); $database = $client->selectDatabase(getenv('MONGODB_DATABASE') ?: 'phplib_test'); $gridfs = $database->selectGridFSBucket(); @@ -903,6 +906,9 @@ public function testDanglingOpenWritableStreamWithGlobalStreamWrapperAlias(): vo $code = <<<'PHP' require '%s'; require '%s'; + // Don't report deprecations - if the issue exists this code will + // result in a fatal error + error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED); $client = MongoDB\Tests\FunctionalTestCase::createTestClient(); $database = $client->selectDatabase(getenv('MONGODB_DATABASE') ?: 'phplib_test'); $database->selectGridFSBucket()->registerGlobalStreamWrapperAlias('alias'); diff --git a/tests/Model/CodecCursorFunctionalTest.php b/tests/Model/CodecCursorFunctionalTest.php index 432d71732..6a6a763e5 100644 --- a/tests/Model/CodecCursorFunctionalTest.php +++ b/tests/Model/CodecCursorFunctionalTest.php @@ -8,8 +8,10 @@ use MongoDB\Model\CodecCursor; use MongoDB\Tests\FunctionalTestCase; +use function phpversion; use function restore_error_handler; use function set_error_handler; +use function version_compare; use const E_DEPRECATED; use const E_USER_DEPRECATED; @@ -25,6 +27,10 @@ public function setUp(): void public function testSetTypeMap(): void { + if (version_compare(phpversion(), '8.4', '>=')) { + $this->markTestIncomplete('Test fails on PHP 8.4 due to deprecations'); + } + $collection = self::createTestClient()->selectCollection($this->getDatabaseName(), $this->getCollectionName()); $cursor = $collection->find(); diff --git a/tests/UnifiedSpecTests/Constraint/MatchesTest.php b/tests/UnifiedSpecTests/Constraint/MatchesTest.php index 53a7643a4..1cae59531 100644 --- a/tests/UnifiedSpecTests/Constraint/MatchesTest.php +++ b/tests/UnifiedSpecTests/Constraint/MatchesTest.php @@ -9,7 +9,9 @@ use stdClass; use function hex2bin; +use function phpversion; use function preg_quote; +use function version_compare; class MatchesTest extends FunctionalTestCase { @@ -69,6 +71,10 @@ public function testOperatorExists(): void public function testOperatorType(): void { + if (version_compare(phpversion(), '8.4', '>=')) { + $this->markTestIncomplete('Test fails on PHP 8.4 due to deprecations'); + } + $c = new Matches(['x' => ['$$type' => 'string']]); $this->assertResult(true, $c, ['x' => 'foo'], 'string matches string type'); $this->assertResult(false, $c, ['x' => 1], 'integer does not match string type');