Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge v1.x into v2.x #1466

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Model/IndexInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/CreateCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */)) {
Expand Down
11 changes: 0 additions & 11 deletions src/Operation/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
4 changes: 0 additions & 4 deletions tests/GridFS/BucketFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
18 changes: 0 additions & 18 deletions tests/Operation/FindTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
19 changes: 8 additions & 11 deletions tests/Operation/WatchFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1225,7 +1223,6 @@ public function testSessionFreed(): void

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

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

Expand Down Expand Up @@ -1282,19 +1279,19 @@ 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'),
),
),
);

$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'),
),
);

Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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
Expand Down