So when I develop extensions I usually do this outside of Magento and just pull in the packages I need. Once I have developed the extension I integrate it at the end.
...
Yeah I'm coupled to the Magento/Framework module. Do you know if it generates these for you when not plugged into magento?
Generation is handled by Magento/Framework
, yes. To utilize that in your tests, you can use the Magento unit test framework or mock the generated classes. Both methods are described here:
Generate factory or proxy in unit tests: "ReflectionException: Class ...Factory does not exist"
But you can go even further and develop as much as possible of your extensions without any dependency to Magento. You will have two packages in the end, one independent library and one "dumb" Magento module that integrates the library into Magento.
For the Magento module you will mostly write integration tests within Magento (as in your "integrate it at the end" step). The library can define interfaces for interaction with the Magento core and the module implements these (acting as an adapter).
If you follow this approach, you have different options regarding factories in the library package, which should be choosen case by case:
- write them yourselves. This makes sense for classes that are implemented and used within the library
- only write the interfaces, then implement these in the module (possibly proxying to generated factories). This makes sense for the adapter classes that are not implemented in the library.
- let them generate by Magento when integrating the module. This makes sense for classes that are implemented within the library but only used from the integration module
If you want to read more about the framework independent approach, I wrote a few blog articles on how and why to do this that you can find here:
http://integer-net.com/m1m2
Magento/Framework
module. Do you know if it generates these for you when not plugged into magento?