thephpleague / factory-muffin

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

RFC: Method to retrieve attributes as array #342

Closed jeremyworboys closed 9 years ago

jeremyworboys commented 9 years ago

I'm thinking something like:

$fm->define('User', array(
    'username' => Faker::firstNameMale()
));

$fm->attributes('User');
// returns: array('username' => 'Jack')

I'm happy to write a pull request for this, I just want to get some feedback before I put any time into it.

GrahamCampbell commented 9 years ago

This will never happen because of the fact that attribute generation could be dependent on the state of the User model, for example, the generation of relationships.

scottrobertson commented 9 years ago

@GrahamCampbell I think he means before we even call ->create

GrahamCampbell commented 9 years ago

Yeh, I know, but that will cause many issues.

GrahamCampbell commented 9 years ago

In 3.0, you do have access to the generator factory though: https://github.com/thephpleague/factory-muffin/blob/30e9b3b821e29bec30315079ab717e49eedad748/src/FactoryMuffin.php#L548.

scottrobertson commented 9 years ago

Yeah i guess, and if he really needs it, a simple work around is:

$fm->define('User', array(
    'username' => Faker::firstNameMale()
));

$user = $fm->instance('User');
// $user->toArray(): array('username' => 'Jack')
GrahamCampbell commented 9 years ago

Yeh.