Comments (14)
And then @FrenkyNet was all like...
@scottrobertson this is actually what I wanted to mention too. Having the definition in the model is smelly. I'd be more in favour a separation. It could be class based, where (like phpspec does) a namespace is prepended or a suffix appended so a classname can be mapped to it's factory config counterpart. Optionally an interface can be exposed which would allow for a per-class handling of the location/config/definition. Another option would be to create config files (returning arrays) in another directory where the files (like autoloading) can be mapped to configs.
from factory-muffin.
And @scottrobertson was saying
@FrenkyNet I like the idea of having it class based yeah. Do you have an idea of how you would want to do it? Using the namespace prepending/appending sounds good to me.
Having config files would be ok I guess, but it could get quite messy.
from factory-muffin.
To which @FrenkyNet replied:
In order to check whether a FQCN implements an interface you can check it like this:
if (in_array('MuffinStuffin\\DefinitionProviderInterface', class_implements($class, true))) {
var_dump('fuck yeah');
}
In which case the interface could look something like:
interface DefinitionProviderInterface
{
public static function getFactoryMuffinDefinition();
}
Which would return a Definition (either string FQCN or instance). A definition object would be created which in turn would supply the bootstrapper the needed information.
When this interface is not implemented a convention could be created. In this case I'm more leaning towards prefixing than suffixing to allow for nicer separation. Seperating the definition files in the FS as well as in code. These definitions, because it's used for testing, could then be made autoloadable by adding a autoload-dev clause (which only adds these classes to the auto-loaded when installing as --dev) eliminating clutter in production. So a class like League\Awesome\Sause
Would then be converted to Muffin\League\Awesome\SauseDefinition
.
The prefixed namespace and class based nature of the definitions enable definitions to be auto generated by a cli tool (future feature maybe?).
So, in short. Check FQCN for interface, if so, get it from the static method provided by the model. Otherwise autoload by convention. Wrapped by WhatEver\[FQCN]\Definition
.
from factory-muffin.
@GrahamCampbell What are your thoughts on this?
from factory-muffin.
I definitely like the idea of separating the testing code from the model and I like the idea of having that interface.
from factory-muffin.
Any news on this?
from factory-muffin.
Not at all sorry, I have been really busy :(
from factory-muffin.
No problem. Should we shift the rc1 milestone one week in the future from it's current date then?
from factory-muffin.
I am not sure I am going to have time this week either. Stuff has come up that I need to do :( You could have a go at it? Or someone else could?
from factory-muffin.
Maybe you could just tag the rc today, and postpone this for 3.0?
from factory-muffin.
Yeah i think so. It's quite a big change and I think we have done a lot to justify v2 already
from factory-muffin.
Would it be sufficient to expose the FactoryMuffin instance method define
through a top level static function in the facade?
from factory-muffin.
@ianterrell Maybe yeah. I am trying to think of any consequences of storing $this->factories as a static variable instead.
from factory-muffin.
@scottrobertson Thanks for thinking about this idea. If you find it useful, here's a merge request to expose it: #90
It looks from the unit tests that the define method is already used extensively.
from factory-muffin.
Related Issues (20)
- PHPUnit 6.0 support HOT 2
- Question: "The model class is undefined." error. HOT 3
- what is '$fm' ? HOT 1
- Question: Is there any way to create a doctrine entity without a need for setters?
- Update documentation on the league website to match the README on the ~3.0 branch HOT 8
- What is `$fm` in the factory definitions? HOT 2
- Make the error message in DeletingFailedException more descriptive HOT 2
- OneToMany Doctrine relation.
- Factory Muffin converts false values to empty strings HOT 1
- Allow write to private properties and/or create instance without constructor calling HOT 1
- No explicit support by FactoryGenerator HOT 2
- still maintained? HOT 2
- How to place an Auto-increment id in v3.1 HOT 1
- FM tries to call string as a function if its the same name as a built-in HOT 2
- Custom Maker is gone in v3 HOT 5
- Add warning to docs that you can't use your own Faker instance HOT 3
- Add warning to docs that you can't use your own Faker instance HOT 9
- Callbacks don't stack
- Does Factory Muffin supports multiple entity managers?
- Unresolved composer.json requirements when action according contribution guideline HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from factory-muffin.