Version 1.2
New Feature v1.2
filter_key
filter_key If true(default is false), overwrites any primary key input with an empty value.
see: CakePHP's Model::create()
Fabricate::config(function($config) {
$config->filter_key = true;
});
define
The first argument to the define is the name you will use when fabricating objects.
Fabricate::define(['PublishedPost', 'class'=>'Post'], ['published'=>'1']);
// or
Fabricate::define(['PublishedPost', 'class'=>'Post'], function($data, $world) {
return ['published'=>'1']
});
association
It's possible to set up associations(hasOne/hasMany) within Fabricate::create().
You can also specify a Fabricate::association() :
Fabricate::create('User', function($data, $world) {
return [
'user' => 'taro',
'Post' => Fabricate::association('Post', 3, ['id'=>false,'author_id'=>false]),
];
});
trait
Traits allow you to group attributes together and then apply them to any fabricating objects.
Fabricate::define(['trait'=>'published'], ['published'=>'1']);
$results = Fabricate::attributes_for('Post', function($data, $world) {
$world->traits('published');
return ['id'=>false];
});
Reloading
If you need to reset fabricate back to its original state after it has been loaded.
Fabricate::clear();