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

PHPC-2478: Implement API for bulkWrite command #1763

Draft
wants to merge 4 commits into
base: v1.x
Choose a base branch
from

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Dec 10, 2024

src/MongoDB/BulkWriteCommand.stub.php Outdated Show resolved Hide resolved

final public function updateMany(string $namespace, array|object $filter, array|object $update, ?array $options = null): void {}

final public function execute(Manager|Server $managerOrServer): mixed {}
Copy link
Member

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);
}

Copy link
Member Author

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.

Copy link
Member Author

@jmikola jmikola Dec 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants