From 1837a7559c705c556cd7a85f953ea1d57fa500a7 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 25 Sep 2024 16:01:46 +0200 Subject: [PATCH 1/4] Deprecate functionality to be removed (#1441) * Remove duplicate deprecation notices for query options * PHPLIB-1533: Mark Collection::mapReduce as deprecated * Update deprecation notice language --- src/Collection.php | 6 ++++++ src/Model/IndexInfo.php | 4 ++-- src/Operation/CreateCollection.php | 2 +- src/Operation/Find.php | 11 ----------- tests/Collection/CollectionFunctionalTest.php | 4 +++- tests/Operation/FindTest.php | 18 ------------------ tests/TestCase.php | 6 ++++-- 7 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index ab82cca5d..937f22f5b 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -77,7 +77,11 @@ use function array_key_exists; use function current; use function is_array; +use function sprintf; use function strlen; +use function trigger_error; + +use const E_USER_DEPRECATED; class Collection { @@ -952,6 +956,8 @@ public function listSearchIndexes(array $options = []): Iterator */ public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, string|array|object $out, array $options = []) { + @trigger_error(sprintf('The %s method is deprecated and will be removed in a version 2.0.', __METHOD__), E_USER_DEPRECATED); + $hasOutputCollection = ! is_mapreduce_output_inline($out); // Check if the out option is inline because we will want to coerce a primary read preference if not diff --git a/src/Model/IndexInfo.php b/src/Model/IndexInfo.php index 53b7b63f0..062c40856 100644 --- a/src/Model/IndexInfo.php +++ b/src/Model/IndexInfo.php @@ -99,7 +99,7 @@ public function getName() */ public function getNamespace() { - @trigger_error('MongoDB 4.4 drops support for the namespace in indexes, the method "IndexInfo::getNamespace()" will be removed in a future release', E_USER_DEPRECATED); + @trigger_error('MongoDB 4.4 drops support for the namespace in indexes, the method "IndexInfo::getNamespace()" will be removed in version 2.0', E_USER_DEPRECATED); return (string) $this->info['ns']; } @@ -132,7 +132,7 @@ public function is2dSphere() */ public function isGeoHaystack() { - @trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED); + @trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in version 2.0', E_USER_DEPRECATED); return array_search('geoHaystack', $this->getKey(), true) !== false; } diff --git a/src/Operation/CreateCollection.php b/src/Operation/CreateCollection.php index 3f4cc881a..a633dd682 100644 --- a/src/Operation/CreateCollection.php +++ b/src/Operation/CreateCollection.php @@ -230,7 +230,7 @@ public function __construct(private string $databaseName, private string $collec } if (isset($this->options['autoIndexId'])) { - trigger_error('The "autoIndexId" option is deprecated and will be removed in a future release', E_USER_DEPRECATED); + trigger_error('The "autoIndexId" option is deprecated and will be removed in version 2.0', E_USER_DEPRECATED); } if (isset($this->options['pipeline']) && ! is_pipeline($this->options['pipeline'], true /* allowEmpty */)) { diff --git a/src/Operation/Find.php b/src/Operation/Find.php index 1d2dfb388..52c43c525 100644 --- a/src/Operation/Find.php +++ b/src/Operation/Find.php @@ -37,9 +37,6 @@ use function is_string; use function MongoDB\document_to_array; use function MongoDB\is_document; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Operation for the find command. @@ -285,14 +282,6 @@ public function __construct(private string $databaseName, private string $collec unset($this->options['readConcern']); } - if (isset($this->options['snapshot'])) { - trigger_error('The "snapshot" option is deprecated and will be removed in a future release', E_USER_DEPRECATED); - } - - if (isset($this->options['maxScan'])) { - trigger_error('The "maxScan" option is deprecated and will be removed in a future release', E_USER_DEPRECATED); - } - if (isset($this->options['codec']) && isset($this->options['typeMap'])) { throw InvalidArgumentException::cannotCombineCodecAndTypeMap(); } diff --git a/tests/Collection/CollectionFunctionalTest.php b/tests/Collection/CollectionFunctionalTest.php index d00ebd84e..d63140ca4 100644 --- a/tests/Collection/CollectionFunctionalTest.php +++ b/tests/Collection/CollectionFunctionalTest.php @@ -433,7 +433,9 @@ public function testMapReduce(): void $reduce = new Javascript('function(key, values) { return Array.sum(values); }'); $out = ['inline' => 1]; - $result = $this->collection->mapReduce($map, $reduce, $out); + $result = $this->assertDeprecated( + fn () => $this->collection->mapReduce($map, $reduce, $out), + ); $this->assertInstanceOf(MapReduceResult::class, $result); $expected = [ diff --git a/tests/Operation/FindTest.php b/tests/Operation/FindTest.php index 9e398650d..1a88cd6a2 100644 --- a/tests/Operation/FindTest.php +++ b/tests/Operation/FindTest.php @@ -55,24 +55,6 @@ public static function provideInvalidConstructorOptions() ]); } - public function testSnapshotOptionIsDeprecated(): void - { - $this->assertDeprecated(function (): void { - new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['snapshot' => true]); - }); - - $this->assertDeprecated(function (): void { - new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['snapshot' => false]); - }); - } - - public function testMaxScanOptionIsDeprecated(): void - { - $this->assertDeprecated(function (): void { - new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['maxScan' => 1]); - }); - } - /** @dataProvider provideInvalidConstructorCursorTypeOptions */ public function testConstructorCursorTypeOption($cursorType): void { diff --git a/tests/TestCase.php b/tests/TestCase.php index 4bff57e0d..07f8219ed 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -161,7 +161,7 @@ final public static function provideInvalidStringValues(): array return self::wrapValuesForDataProvider(self::getInvalidStringValues()); } - protected function assertDeprecated(callable $execution): void + protected function assertDeprecated(callable $execution) { $errors = []; @@ -170,12 +170,14 @@ protected function assertDeprecated(callable $execution): void }, E_USER_DEPRECATED | E_DEPRECATED); try { - call_user_func($execution); + $result = call_user_func($execution); } finally { restore_error_handler(); } $this->assertCount(1, $errors); + + return $result; } protected static function createOptionDataProvider(array $options): array From 62dd5ff087fcffe9d5f8c5dff6e6c6f6c6e58028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 25 Sep 2024 16:23:06 +0200 Subject: [PATCH 2/4] Fix deprecations in tests (#1458) * Reflection method setAccessible is useless As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default. https://www.php.net/manual/en/reflectionproperty.setaccessible.php * Replace deprecated ObjectHasAttribute with ObjectHasProperty --- tests/GridFS/BucketFunctionalTest.php | 4 ---- tests/Operation/WatchFunctionalTest.php | 19 ++++++++----------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/GridFS/BucketFunctionalTest.php b/tests/GridFS/BucketFunctionalTest.php index ccbe6bf02..163c458c2 100644 --- a/tests/GridFS/BucketFunctionalTest.php +++ b/tests/GridFS/BucketFunctionalTest.php @@ -951,8 +951,6 @@ public function testResolveStreamContextForRead(): void fclose($stream); $method = new ReflectionMethod($this->bucket, 'resolveStreamContext'); - $method->setAccessible(true); - $context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'rb', []]); $this->assertIsArray($context); @@ -967,8 +965,6 @@ public function testResolveStreamContextForRead(): void public function testResolveStreamContextForWrite(): void { $method = new ReflectionMethod($this->bucket, 'resolveStreamContext'); - $method->setAccessible(true); - $context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'wb', []]); $this->assertIsArray($context); diff --git a/tests/Operation/WatchFunctionalTest.php b/tests/Operation/WatchFunctionalTest.php index cc6690b0f..df4c98fdc 100644 --- a/tests/Operation/WatchFunctionalTest.php +++ b/tests/Operation/WatchFunctionalTest.php @@ -25,6 +25,7 @@ use MongoDB\Operation\InsertOne; use MongoDB\Operation\Watch; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Constraint\ObjectHasProperty; use PHPUnit\Framework\ExpectationFailedException; use ReflectionClass; use stdClass; @@ -724,10 +725,7 @@ public function testInitialCursorIsNotClosed(): void $this->assertNotEquals('0', (string) $changeStream->getCursorId(true)); $rc = new ReflectionClass(ChangeStream::class); - $rp = $rc->getProperty('iterator'); - $rp->setAccessible(true); - - $iterator = $rp->getValue($changeStream); + $iterator = $rc->getProperty('iterator')->getValue($changeStream); $this->assertInstanceOf('IteratorIterator', $iterator); @@ -1225,7 +1223,6 @@ public function testSessionFreed(): void $rc = new ReflectionClass($changeStream); $rp = $rc->getProperty('resumeCallable'); - $rp->setAccessible(true); $this->assertIsCallable($rp->getValue($changeStream)); @@ -1282,9 +1279,9 @@ function (array $event) use (&$aggregateCommands): void { $aggregateCommands[0]['pipeline'][0]->{'$changeStream'}, $this->logicalNot( $this->logicalOr( - $this->objectHasAttribute('resumeAfter'), - $this->objectHasAttribute('startAfter'), - $this->objectHasAttribute('startAtOperationTime'), + new ObjectHasProperty('resumeAfter'), + new ObjectHasProperty('startAfter'), + new ObjectHasProperty('startAtOperationTime'), ), ), ); @@ -1292,9 +1289,9 @@ function (array $event) use (&$aggregateCommands): void { $this->assertThat( $aggregateCommands[1]['pipeline'][0]->{'$changeStream'}, $this->logicalOr( - $this->objectHasAttribute('resumeAfter'), - $this->objectHasAttribute('startAfter'), - $this->objectHasAttribute('startAtOperationTime'), + new ObjectHasProperty('resumeAfter'), + new ObjectHasProperty('startAfter'), + new ObjectHasProperty('startAtOperationTime'), ), ); From 0f9049dae31cd4a99daedb4bb4dd0335af60edbb Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 26 Sep 2024 11:21:07 +0200 Subject: [PATCH 3/4] Fix wrong evergreen variable for version (#1464) --- .evergreen/config/functions.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.evergreen/config/functions.yml b/.evergreen/config/functions.yml index 0c8c85635..f53dba0e1 100644 --- a/.evergreen/config/functions.yml +++ b/.evergreen/config/functions.yml @@ -84,9 +84,7 @@ functions: content_type: ${content_type|application/x-gzip} permissions: public-read local_file: ${build_id}.tar.gz - remote_file: mongo-php-driver/${build_variant}/${revision}/${task_name}/${version}.tar.gz - # TODO: Use separate folder for the library once it exists -# remote_file: ${project}/${build_variant}/${revision}/${task_name}/${version}.tar.gz + remote_file: mongo-php-driver/${build_variant}/${revision}/${task_name}/${version_id}.tar.gz "fetch extension": - command: s3.get @@ -94,9 +92,7 @@ functions: aws_key: ${aws_key} aws_secret: ${aws_secret} bucket: mciuploads - # TODO: Use separate folder for the library once it exists - remote_file: mongo-php-driver/${FETCH_BUILD_VARIANT}/${revision}/${FETCH_BUILD_TASK}/${version}.tar.gz -# remote_file: ${project}/${FETCH_BUILD_VARIANT}/${revision}/${FETCH_BUILD_TASK}/${version}.tar.gz + remote_file: mongo-php-driver/${FETCH_BUILD_VARIANT}/${revision}/${FETCH_BUILD_TASK}/${version_id}.tar.gz local_file: build.tar.gz - command: archive.targz_extract params: From 4af38e630552a518855ad5aa7e7da9da118c0150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 26 Sep 2024 11:25:00 +0200 Subject: [PATCH 4/4] Higher phpunit version required (#1463) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3ac90068c..e7d51e61e 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "doctrine/coding-standard": "^12.0", - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^9.6.11", "rector/rector": "^1.1", "squizlabs/php_codesniffer": "^3.7", "vimeo/psalm": "^5.13"