Skip to content

Commit 8c6988e

Browse files
committed
PHPLIB-1533: Mark Collection::mapReduce as deprecated
1 parent 84a94de commit 8c6988e

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
@@ -71,7 +71,11 @@
7171
use function array_key_exists;
7272
use function current;
7373
use function is_array;
74+
use function sprintf;
7475
use function strlen;
76+
use function trigger_error;
77+
78+
use const E_USER_DEPRECATED;
7579

7680
class Collection
7781
{
@@ -927,6 +931,8 @@ public function listSearchIndexes(array $options = []): Iterator
927931
*/
928932
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])
929933
{
934+
@trigger_error(sprintf('The %s method is deprecated and will be removed in a future release.', __METHOD__), E_USER_DEPRECATED);
935+
930936
$hasOutputCollection = ! is_mapreduce_output_inline($out);
931937

932938
// 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
@@ -429,7 +429,9 @@ public function testMapReduce(): void
429429
$reduce = new Javascript('function(key, values) { return Array.sum(values); }');
430430
$out = ['inline' => 1];
431431

432-
$result = $this->collection->mapReduce($map, $reduce, $out);
432+
$result = $this->assertDeprecated(
433+
fn () => $this->collection->mapReduce($map, $reduce, $out),
434+
);
433435

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

tests/TestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function provideInvalidStringValues(): array
165165
return $this->wrapValuesForDataProvider($this->getInvalidStringValues());
166166
}
167167

168-
protected function assertDeprecated(callable $execution): void
168+
protected function assertDeprecated(callable $execution)
169169
{
170170
$errors = [];
171171

@@ -174,12 +174,14 @@ protected function assertDeprecated(callable $execution): void
174174
}, E_USER_DEPRECATED);
175175

176176
try {
177-
call_user_func($execution);
177+
$result = call_user_func($execution);
178178
} finally {
179179
restore_error_handler();
180180
}
181181

182182
$this->assertCount(1, $errors);
183+
184+
return $result;
183185
}
184186

185187
protected function createOptionDataProvider(array $options): array

0 commit comments

Comments
 (0)