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

Aggregation class is final and can't be mocked to mock Aggregation\Builder #2699

Open
GromNaN opened this issue Nov 16, 2024 · 0 comments · May be fixed by #2702
Open

Aggregation class is final and can't be mocked to mock Aggregation\Builder #2699

GromNaN opened this issue Nov 16, 2024 · 0 comments · May be fixed by #2702

Comments

@GromNaN
Copy link
Member

GromNaN commented Nov 16, 2024

Bug Report

Q A
BC Break no
Version 2.9.0

Summary

The method Doctrine\ODM\MongoDB\Aggregation\Builder::execute() is deprecated and should be replaced by $builder->getAggregation()->getIterator() (Note that it's more verbose for the common use case).

But getAggregation() must return an instance of Doctrine\ODM\MongoDB\Aggregation\Aggregation. This class is hard to instantiate in tests as it requires a lot of dependencies that would have to be mocked with the ODM internal behavior. Since the class is final, it cannot be mocked.

I created a draft PR to remove usage of Aggregation\Builder::execute() in API Platform, but the tests cannot be fixed. GromNaN/api-platform-core#2

The solutions would be to remove the final keyword on Doctrine\ODM\MongoDB\Aggregation\Aggregation.

@GromNaN GromNaN changed the title Aggregation classes are final and can't be mocked to mock Aggregation\Builder Aggregation class is final and can't be mocked to mock Aggregation\Builder Nov 17, 2024
@alcaeus alcaeus linked a pull request Nov 28, 2024 that will close this issue
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 a pull request may close this issue.

1 participant