-
Notifications
You must be signed in to change notification settings - Fork 206
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
PHPC-2478: Implement API for bulkWrite command #1763
base: v1.x
Are you sure you want to change the base?
Conversation
|
||
final public function updateMany(string $namespace, array|object $filter, array|object $update, ?array $options = null): void {} | ||
|
||
final public function execute(Manager|Server $managerOrServer): mixed {} |
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.
By placing the execute method on this side, it becomes essential to be able to mock this class. But this class is final
.
How do you test a function that creates a BulkWriteCommand and executes it?
function saveDocuments(Manager $manager, array $documents) {
$command = new BulkWriteCommand();
foreach ($documents as $document) {
$command->replaceOne(/** do something very domain specific */);
}
// I have no idea how to track the call to $manager
$command->execute($manager);
// This implementation would be easier to mock
$manager->execute($command);
}
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.
Thanks for the feedback here. I clearly don't deal with mocking objects anymore, so I overlooked how this would hinder that. I suppose that takes us back to Manager::executeBulkWriteCommand()
, and a corresponding Server method.
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.
Revisiting this since we discussed it earlier in the week with @alcaeus. In terms of mocking, having execute()
here isn't much different than the Manager and Server classes, which are also both final
.
We also discussed having execute()
methods oh other objects, and I believe only Command would be problematic since that currently relies on several variations (read, read/write, write) and to replace that with a singular execute()
method would require PHPC to inspect command documents.
Anyway, I'm going to proceed with BulkWriteCommand::execute()
for now and we can revisit later if needed.
985a161
to
7c6d456
Compare
https://jira.mongodb.org/browse/PHPC-2478