diff --git a/src/Collection.php b/src/Collection.php index ab82cca5d..f872f4aa2 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 future release.', __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/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/TestCase.php b/tests/TestCase.php index 1d965606d..abc330ad8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -160,7 +160,7 @@ final public static function provideInvalidStringValues(): array return self::wrapValuesForDataProvider(self::getInvalidStringValues()); } - protected function assertDeprecated(callable $execution): void + protected function assertDeprecated(callable $execution) { $errors = []; @@ -169,12 +169,14 @@ protected function assertDeprecated(callable $execution): void }, E_USER_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