-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-722: Ignore writeConcern option for read-only aggregations #1100
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
Changes from all commits
9bb6ae1
52340de
28cc1f5
edfe5e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
use function call_user_func; | ||
use function is_scalar; | ||
use function json_encode; | ||
use function strchr; | ||
use function str_contains; | ||
use function usort; | ||
use function version_compare; | ||
|
||
|
@@ -434,16 +434,30 @@ public function testMapReduce(): void | |
public function collectionMethodClosures() | ||
{ | ||
return [ | ||
[ | ||
'read-only aggregate' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->aggregate( | ||
[['$match' => ['_id' => ['$lt' => 3]]]], | ||
['session' => $session] + $options | ||
); | ||
}, 'r', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pipeline is actually read-only. I added a write pipeline as @jmikola recommended. |
||
], | ||
|
||
/* Disabled, as write aggregations are not supported in transactions | ||
'read-write aggregate' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->aggregate( | ||
[ | ||
['$match' => ['_id' => ['$lt' => 3]]], | ||
['$merge' => $collection . '_out'], | ||
], | ||
['session' => $session] + $options | ||
); | ||
}, 'rw', | ||
], | ||
*/ | ||
|
||
[ | ||
'bulkWrite insertOne' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->bulkWrite( | ||
[['insertOne' => [['test' => 'foo']]]], | ||
|
@@ -453,7 +467,7 @@ function ($collection, $session, $options = []): void { | |
], | ||
|
||
/* Disabled, as count command can't be used in transactions | ||
[ | ||
'count' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->count( | ||
[], | ||
|
@@ -463,7 +477,7 @@ function($collection, $session, $options = []) { | |
], | ||
*/ | ||
|
||
[ | ||
'countDocuments' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->countDocuments( | ||
[], | ||
|
@@ -473,7 +487,7 @@ function ($collection, $session, $options = []): void { | |
], | ||
|
||
/* Disabled, as it's illegal to use createIndex command in transactions | ||
[ | ||
'createIndex' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->createIndex( | ||
['test' => 1], | ||
|
@@ -483,7 +497,7 @@ function($collection, $session, $options = []) { | |
], | ||
*/ | ||
|
||
[ | ||
'deleteMany' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->deleteMany( | ||
['test' => 'foo'], | ||
|
@@ -492,7 +506,7 @@ function ($collection, $session, $options = []): void { | |
}, 'w', | ||
], | ||
|
||
[ | ||
'deleteOne' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->deleteOne( | ||
['test' => 'foo'], | ||
|
@@ -501,7 +515,7 @@ function ($collection, $session, $options = []): void { | |
}, 'w', | ||
], | ||
|
||
[ | ||
'distinct' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->distinct( | ||
'_id', | ||
|
@@ -512,7 +526,7 @@ function ($collection, $session, $options = []): void { | |
], | ||
|
||
/* Disabled, as it's illegal to use drop command in transactions | ||
[ | ||
'drop' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->drop( | ||
['session' => $session] + $options | ||
|
@@ -522,7 +536,7 @@ function($collection, $session, $options = []) { | |
*/ | ||
|
||
/* Disabled, as it's illegal to use dropIndexes command in transactions | ||
[ | ||
'dropIndex' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->dropIndex( | ||
'_id_1', | ||
|
@@ -532,7 +546,7 @@ function($collection, $session, $options = []) { | |
], */ | ||
|
||
/* Disabled, as it's illegal to use dropIndexes command in transactions | ||
[ | ||
'dropIndexes' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->dropIndexes( | ||
['session' => $session] + $options | ||
|
@@ -542,7 +556,7 @@ function($collection, $session, $options = []) { | |
*/ | ||
|
||
/* Disabled, as count command can't be used in transactions | ||
[ | ||
'estimatedDocumentCount' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->estimatedDocumentCount( | ||
['session' => $session] + $options | ||
|
@@ -551,7 +565,7 @@ function($collection, $session, $options = []) { | |
], | ||
*/ | ||
|
||
[ | ||
'find' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->find( | ||
['test' => 'foo'], | ||
|
@@ -560,7 +574,7 @@ function ($collection, $session, $options = []): void { | |
}, 'r', | ||
], | ||
|
||
[ | ||
'findOne' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->findOne( | ||
['test' => 'foo'], | ||
|
@@ -569,7 +583,7 @@ function ($collection, $session, $options = []): void { | |
}, 'r', | ||
], | ||
|
||
[ | ||
'findOneAndDelete' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->findOneAndDelete( | ||
['test' => 'foo'], | ||
|
@@ -578,7 +592,7 @@ function ($collection, $session, $options = []): void { | |
}, 'w', | ||
], | ||
|
||
[ | ||
'findOneAndReplace' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->findOneAndReplace( | ||
['test' => 'foo'], | ||
|
@@ -588,7 +602,7 @@ function ($collection, $session, $options = []): void { | |
}, 'w', | ||
], | ||
|
||
[ | ||
'findOneAndUpdate' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->findOneAndUpdate( | ||
['test' => 'foo'], | ||
|
@@ -598,7 +612,7 @@ function ($collection, $session, $options = []): void { | |
}, 'w', | ||
], | ||
|
||
[ | ||
'insertMany' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->insertMany( | ||
[ | ||
|
@@ -610,7 +624,7 @@ function ($collection, $session, $options = []): void { | |
}, 'w', | ||
], | ||
|
||
[ | ||
'insertOne' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->insertOne( | ||
['test' => 'foo'], | ||
|
@@ -620,7 +634,7 @@ function ($collection, $session, $options = []): void { | |
], | ||
|
||
/* Disabled, as it's illegal to use listIndexes command in transactions | ||
[ | ||
'listIndexes' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->listIndexes( | ||
['session' => $session] + $options | ||
|
@@ -630,7 +644,7 @@ function($collection, $session, $options = []) { | |
*/ | ||
|
||
/* Disabled, as it's illegal to use mapReduce command in transactions | ||
[ | ||
'mapReduce' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->mapReduce( | ||
new \MongoDB\BSON\Javascript('function() { emit(this.state, this.pop); }'), | ||
|
@@ -642,7 +656,7 @@ function($collection, $session, $options = []) { | |
], | ||
*/ | ||
|
||
[ | ||
'replaceOne' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->replaceOne( | ||
['test' => 'foo'], | ||
|
@@ -652,7 +666,7 @@ function ($collection, $session, $options = []): void { | |
}, 'w', | ||
], | ||
|
||
[ | ||
'updateMany' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->updateMany( | ||
['test' => 'foo'], | ||
|
@@ -662,7 +676,7 @@ function ($collection, $session, $options = []): void { | |
}, 'w', | ||
], | ||
|
||
[ | ||
'updateOne' => [ | ||
function ($collection, $session, $options = []): void { | ||
$collection->updateOne( | ||
['test' => 'foo'], | ||
|
@@ -673,7 +687,7 @@ function ($collection, $session, $options = []): void { | |
], | ||
|
||
/* Disabled, as it's illegal to use change streams in transactions | ||
[ | ||
'watch' => [ | ||
function($collection, $session, $options = []) { | ||
$collection->watch( | ||
[], | ||
|
@@ -685,32 +699,28 @@ function($collection, $session, $options = []) { | |
]; | ||
} | ||
|
||
public function collectionReadMethodClosures() | ||
public function collectionReadMethodClosures(): array | ||
{ | ||
return array_filter( | ||
$this->collectionMethodClosures(), | ||
function ($rw) { | ||
if (strchr($rw[1], 'r') !== false) { | ||
return true; | ||
} | ||
return str_contains($rw[1], 'r'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small refactoring to use the PHP 8 function, provided by the polyfill for older versions. |
||
} | ||
); | ||
} | ||
|
||
public function collectionWriteMethodClosures() | ||
public function collectionWriteMethodClosures(): array | ||
{ | ||
return array_filter( | ||
$this->collectionMethodClosures(), | ||
function ($rw) { | ||
if (strchr($rw[1], 'w') !== false) { | ||
return true; | ||
} | ||
return str_contains($rw[1], 'w'); | ||
} | ||
); | ||
} | ||
|
||
/** @dataProvider collectionMethodClosures */ | ||
public function testMethodDoesNotInheritReadWriteConcernInTranasaction(Closure $method): void | ||
public function testMethodDoesNotInheritReadWriteConcernInTransaction(Closure $method): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed a typo |
||
{ | ||
$this->skipIfTransactionsAreNotSupported(); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debugging is simplified when the data provider uses names. Even more so because of the filter applied in
collectionReadMethodClosures
andcollectionWriteMethodClosures
.