Skip to content

Commit 09c78e3

Browse files
committed
PHPLIB-1533: Mark Collection::mapReduce as deprecated
1 parent fb6a9c8 commit 09c78e3

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/Collection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@
7777
use function array_key_exists;
7878
use function current;
7979
use function is_array;
80+
use function sprintf;
8081
use function strlen;
82+
use function trigger_error;
83+
84+
use const E_USER_DEPRECATED;
8185

8286
class Collection
8387
{
@@ -952,6 +956,8 @@ public function listSearchIndexes(array $options = []): Iterator
952956
*/
953957
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, string|array|object $out, array $options = [])
954958
{
959+
@trigger_error(sprintf('The %s method is deprecated and will be removed in a future release.', __METHOD__), E_USER_DEPRECATED);
960+
955961
$hasOutputCollection = ! is_mapreduce_output_inline($out);
956962

957963
// Check if the out option is inline because we will want to coerce a primary read preference if not

tests/Collection/CollectionFunctionalTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,9 @@ public function testMapReduce(): void
433433
$reduce = new Javascript('function(key, values) { return Array.sum(values); }');
434434
$out = ['inline' => 1];
435435

436-
$result = $this->collection->mapReduce($map, $reduce, $out);
436+
$result = $this->assertDeprecated(
437+
fn () => $this->collection->mapReduce($map, $reduce, $out),
438+
);
437439

438440
$this->assertInstanceOf(MapReduceResult::class, $result);
439441
$expected = [

tests/TestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ final public static function provideInvalidStringValues(): array
160160
return self::wrapValuesForDataProvider(self::getInvalidStringValues());
161161
}
162162

163-
protected function assertDeprecated(callable $execution): void
163+
protected function assertDeprecated(callable $execution)
164164
{
165165
$errors = [];
166166

@@ -169,12 +169,14 @@ protected function assertDeprecated(callable $execution): void
169169
}, E_USER_DEPRECATED);
170170

171171
try {
172-
call_user_func($execution);
172+
$result = call_user_func($execution);
173173
} finally {
174174
restore_error_handler();
175175
}
176176

177177
$this->assertCount(1, $errors);
178+
179+
return $result;
178180
}
179181

180182
protected static function createOptionDataProvider(array $options): array

0 commit comments

Comments
 (0)