Skip to content

Commit f584124

Browse files
Merge v1.x into v2.x (#1467)
2 parents 411f612 + 2186d4f commit f584124

File tree

11 files changed

+27
-57
lines changed

11 files changed

+27
-57
lines changed

.evergreen/config/functions.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,15 @@ functions:
8484
content_type: ${content_type|application/x-gzip}
8585
permissions: public-read
8686
local_file: ${build_id}.tar.gz
87-
remote_file: mongo-php-driver/${build_variant}/${revision}/${task_name}/${version}.tar.gz
88-
# TODO: Use separate folder for the library once it exists
89-
# remote_file: ${project}/${build_variant}/${revision}/${task_name}/${version}.tar.gz
87+
remote_file: mongo-php-driver/${build_variant}/${revision}/${task_name}/${version_id}.tar.gz
9088

9189
"fetch extension":
9290
- command: s3.get
9391
params:
9492
aws_key: ${aws_key}
9593
aws_secret: ${aws_secret}
9694
bucket: mciuploads
97-
# TODO: Use separate folder for the library once it exists
98-
remote_file: mongo-php-driver/${FETCH_BUILD_VARIANT}/${revision}/${FETCH_BUILD_TASK}/${version}.tar.gz
99-
# remote_file: ${project}/${FETCH_BUILD_VARIANT}/${revision}/${FETCH_BUILD_TASK}/${version}.tar.gz
95+
remote_file: mongo-php-driver/${FETCH_BUILD_VARIANT}/${revision}/${FETCH_BUILD_TASK}/${version_id}.tar.gz
10096
local_file: build.tar.gz
10197
- command: archive.targz_extract
10298
params:

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"require-dev": {
2222
"doctrine/coding-standard": "^12.0",
23-
"phpunit/phpunit": "^9.6",
23+
"phpunit/phpunit": "^9.6.11",
2424
"rector/rector": "^1.1",
2525
"squizlabs/php_codesniffer": "^3.7",
2626
"vimeo/psalm": "^5.13"

src/Collection.php

+6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@
7878
use function array_key_exists;
7979
use function current;
8080
use function is_array;
81+
use function sprintf;
8182
use function strlen;
83+
use function trigger_error;
84+
85+
use const E_USER_DEPRECATED;
8286

8387
class Collection
8488
{
@@ -921,6 +925,8 @@ public function listSearchIndexes(array $options = []): Iterator
921925
*/
922926
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, string|array|object $out, array $options = []): MapReduceResult
923927
{
928+
@trigger_error(sprintf('The %s method is deprecated and will be removed in a version 2.0.', __METHOD__), E_USER_DEPRECATED);
929+
924930
$hasOutputCollection = ! is_mapreduce_output_inline($out);
925931

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

src/Model/IndexInfo.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function getName(): string
8989
*/
9090
public function getNamespace(): string
9191
{
92-
@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);
92+
@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);
9393

9494
return (string) $this->info['ns'];
9595
}
@@ -117,7 +117,7 @@ public function is2dSphere(): bool
117117
*/
118118
public function isGeoHaystack(): bool
119119
{
120-
@trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED);
120+
@trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in version 2.0', E_USER_DEPRECATED);
121121

122122
return array_search('geoHaystack', $this->getKey(), true) !== false;
123123
}

src/Operation/CreateCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function __construct(private string $databaseName, private string $collec
228228
}
229229

230230
if (isset($this->options['autoIndexId'])) {
231-
trigger_error('The "autoIndexId" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
231+
trigger_error('The "autoIndexId" option is deprecated and will be removed in version 2.0', E_USER_DEPRECATED);
232232
}
233233

234234
if (isset($this->options['pipeline']) && ! is_pipeline($this->options['pipeline'], true /* allowEmpty */)) {

src/Operation/Find.php

-11
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
use function is_string;
3737
use function MongoDB\document_to_array;
3838
use function MongoDB\is_document;
39-
use function trigger_error;
40-
41-
use const E_USER_DEPRECATED;
4239

4340
/**
4441
* Operation for the find command.
@@ -282,14 +279,6 @@ public function __construct(private string $databaseName, private string $collec
282279
unset($this->options['readConcern']);
283280
}
284281

285-
if (isset($this->options['snapshot'])) {
286-
trigger_error('The "snapshot" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
287-
}
288-
289-
if (isset($this->options['maxScan'])) {
290-
trigger_error('The "maxScan" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
291-
}
292-
293282
if (isset($this->options['codec']) && isset($this->options['typeMap'])) {
294283
throw InvalidArgumentException::cannotCombineCodecAndTypeMap();
295284
}

tests/Collection/CollectionFunctionalTest.php

+3-1
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/GridFS/BucketFunctionalTest.php

-4
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,6 @@ public function testResolveStreamContextForRead(): void
919919
fclose($stream);
920920

921921
$method = new ReflectionMethod($this->bucket, 'resolveStreamContext');
922-
$method->setAccessible(true);
923-
924922
$context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'rb', []]);
925923

926924
$this->assertIsArray($context);
@@ -935,8 +933,6 @@ public function testResolveStreamContextForRead(): void
935933
public function testResolveStreamContextForWrite(): void
936934
{
937935
$method = new ReflectionMethod($this->bucket, 'resolveStreamContext');
938-
$method->setAccessible(true);
939-
940936
$context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'wb', []]);
941937

942938
$this->assertIsArray($context);

tests/Operation/FindTest.php

-18
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,6 @@ public static function provideInvalidConstructorOptions()
5555
]);
5656
}
5757

58-
public function testSnapshotOptionIsDeprecated(): void
59-
{
60-
$this->assertDeprecated(function (): void {
61-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['snapshot' => true]);
62-
});
63-
64-
$this->assertDeprecated(function (): void {
65-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['snapshot' => false]);
66-
});
67-
}
68-
69-
public function testMaxScanOptionIsDeprecated(): void
70-
{
71-
$this->assertDeprecated(function (): void {
72-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['maxScan' => 1]);
73-
});
74-
}
75-
7658
/** @dataProvider provideInvalidConstructorCursorTypeOptions */
7759
public function testConstructorCursorTypeOption($cursorType): void
7860
{

tests/Operation/WatchFunctionalTest.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use MongoDB\Operation\InsertOne;
2626
use MongoDB\Operation\Watch;
2727
use MongoDB\Tests\CommandObserver;
28+
use PHPUnit\Framework\Constraint\ObjectHasProperty;
2829
use PHPUnit\Framework\ExpectationFailedException;
2930
use ReflectionClass;
3031
use stdClass;
@@ -724,10 +725,7 @@ public function testInitialCursorIsNotClosed(): void
724725
$this->assertNotEquals(0, $changeStream->getCursorId());
725726

726727
$rc = new ReflectionClass(ChangeStream::class);
727-
$rp = $rc->getProperty('iterator');
728-
$rp->setAccessible(true);
729-
730-
$iterator = $rp->getValue($changeStream);
728+
$iterator = $rc->getProperty('iterator')->getValue($changeStream);
731729

732730
$this->assertInstanceOf('IteratorIterator', $iterator);
733731

@@ -1225,7 +1223,6 @@ public function testSessionFreed(): void
12251223

12261224
$rc = new ReflectionClass($changeStream);
12271225
$rp = $rc->getProperty('resumeCallable');
1228-
$rp->setAccessible(true);
12291226

12301227
$this->assertIsCallable($rp->getValue($changeStream));
12311228

@@ -1282,19 +1279,19 @@ function (array $event) use (&$aggregateCommands): void {
12821279
$aggregateCommands[0]['pipeline'][0]->{'$changeStream'},
12831280
$this->logicalNot(
12841281
$this->logicalOr(
1285-
$this->objectHasAttribute('resumeAfter'),
1286-
$this->objectHasAttribute('startAfter'),
1287-
$this->objectHasAttribute('startAtOperationTime'),
1282+
new ObjectHasProperty('resumeAfter'),
1283+
new ObjectHasProperty('startAfter'),
1284+
new ObjectHasProperty('startAtOperationTime'),
12881285
),
12891286
),
12901287
);
12911288

12921289
$this->assertThat(
12931290
$aggregateCommands[1]['pipeline'][0]->{'$changeStream'},
12941291
$this->logicalOr(
1295-
$this->objectHasAttribute('resumeAfter'),
1296-
$this->objectHasAttribute('startAfter'),
1297-
$this->objectHasAttribute('startAtOperationTime'),
1292+
new ObjectHasProperty('resumeAfter'),
1293+
new ObjectHasProperty('startAfter'),
1294+
new ObjectHasProperty('startAtOperationTime'),
12981295
),
12991296
);
13001297

tests/TestCase.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ final public static function provideInvalidStringValues(): array
161161
return self::wrapValuesForDataProvider(self::getInvalidStringValues());
162162
}
163163

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

@@ -170,12 +170,14 @@ protected function assertDeprecated(callable $execution): void
170170
}, E_USER_DEPRECATED | E_DEPRECATED);
171171

172172
try {
173-
call_user_func($execution);
173+
$result = call_user_func($execution);
174174
} finally {
175175
restore_error_handler();
176176
}
177177

178178
$this->assertCount(1, $errors);
179+
180+
return $result;
179181
}
180182

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

0 commit comments

Comments
 (0)