thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
531 stars 72 forks source link

Add detection for non public setter methods #413

Closed LostKobrakai closed 8 years ago

LostKobrakai commented 8 years ago

FactoryMuffin::generate does currently try to access protected or private setter methods independent of the visibility of the method.

GrahamCampbell commented 8 years ago

What use case do you have for this?

LostKobrakai commented 8 years ago

I want to use it with ProcessWire, which does use a pattern like in the test quite often. The magic method is the catch-all portion and in some cases longer work is delegated to a explicit setter function, which may or may not be public.

LostKobrakai commented 8 years ago

I just noticed is_callable(array($model, $setter)) would work as well and might be more readable. Should I change it to that?

GrahamCampbell commented 8 years ago

The test doesn't really test this is correct?

LostKobrakai commented 8 years ago

Trying to use the setName() method would result in an error, which it doesn't with my addition. I think the assert might not be needed and I'm not really into phpunit, so I don't know how to correctly test for such errors.

GrahamCampbell commented 8 years ago

Maybe just make that method throw an exception so we can be 1000% sure?

GrahamCampbell commented 8 years ago

Thanks. I've merged your tests, but fixed it a different way.