webfactory / doctrine-orm-test-infrastructure

Provides utils to create a test infrastructure for Doctrine ORM entities.
MIT License
20 stars 5 forks source link

Ability to (auto)load entity configuration via XML/YML files #14

Open MalteWunsch opened 8 years ago

MalteWunsch commented 8 years ago

E.g. in the FOSUserBundle, one inherits from a Doctrine User entity that is configured via an XML file instead of annotations like we expect in the doctrine-orm-test-infrastructure. For now, these configuration files are ignored, which leads to errors like "unrecognized field: username".

Duplicating the configuration in annotation form is no workaround, as this leads to other errors (field is already defined).

It would be great to allow passing configuration files to ORMInfrastructure::create*. Even better, but not urgent, would be an auto-discover of these configuration files.

mpdude commented 7 years ago

That was one question that came up during the Symfony User Group the other day...

Currently, the ORMInfrastructure works without further ado because it can find the classes in code and so it can discover annotations as well. But if configuration is kept in XML files, it has no way of knowing where to look for those, right?

apapsch commented 6 years ago

Looking in OrmInfrastructure::createEntityManager, it creates the EntityManager configuration via ConfigurationFactory::createFor, which has the AnnotationDriver hardcoded. It also discovers directory paths via the PHP reflection API. To support XML (or any) mappings, ConnectionConfiguration should, just like Doctrine's EntityManager::create, accept a second parameter \Doctrine\ORM\Configuration $config.

But looking closer in ConfigurationFactory::createFor it does two things which would not be enforced if the connection would be opened for injection:

Therefore, instead of a \Doctrine\ORM\Configuration, the second parameter to ConnectionConfiguration should be an (optional) mapping driver. I'll be looking into it at the weekend.

While we're at it, maybe ConnectionConfiguration should be renamed to Configuration, because it would no longer be exclusive to connection configuration.

mpdude commented 8 months ago

Please check if #48 solves this.