Open alekitto opened 2 weeks ago
Obviously not a bug. Please elaborate your use-case.
As explained also in the ODM issue:
It is mostly used for testing actually: I'm using a DocumentManager with a mocked connection and a custom metadata factory in order to precisely control what is returned from the factory itself
I used this feature in 2.x without any problem, but defining the concrete type into the EntityManager does not allow to use any other class implementing the common interface/extending the abstract class.
You did not answer the question.
You did not answer the question.
Yes, I did. My use-case is to create a fake/mock version of the class metadata factory implementing Doctrine\Persistence\Mapping\ClassMetadataFactory
interface, and using it in testing to control what is returned from the factory itself and when the factory methods are called.
In the current state calling setClassMetadataFactoryName
on configuration with such a class results in a fatal error on entity manager construction. But the same thing was possible in 2.x because the property type was not defined, so it was possible to implement the interface/extend the abstract class to have your custom implementation of the class metadata factory.
What else do you need to know precisely?
As far as I know, our factory is not final, so you may still mock it.
The class itself is not final, but some of the public methods are final in ClassMetadataFactory
and in AbstractClassMetadataFactory
and cannot be overridden (also what's the purpose of the abstract class if cannot be used in the entity manager?) .
I'm currently replacing the class completely, just implementing the interface.
I see. Well, we could introduce a new interface for our factory that you can mock. Please send a PR.
:+1: Ok, thanks. I'll send it tomorrow.
Bug Report
Summary
Since version 3.0.0, the class metadata factory cannot be overridden.
Previous behavior
The entity manager has been instantiated taking the class name from the configuration on entity manager construction
Current behavior
Since https://github.com/doctrine/orm/commit/ea97ea4c470f81f7944e4c8931f04c17eb86bee7 the override is broken as the entity manager is wired to the class
Doctrine\ORM\Mapping\ClassMetadataFactory
. To allow overriding via configuration, it should be wired againstDoctrine\Persistence\Mapping\ClassMetadataFactory
interface.How to reproduce
This is the same exact bug reported on mongodb-odm at https://github.com/doctrine/mongodb-odm/issues/2551 The only difference is that on mongodb-odm this was considered a BC break, as the bug was introduced in a minor version.