Skip to content

Version 1.2.1

Compare
Choose a tag to compare
@sizuhiko sizuhiko released this 21 Jul 08:25
· 72 commits to master since this release

New Feature v1.2.1

Configuration

To override these settings, put a bootstrap.php in your app folder and append the path to phpunit.xml

Fabricate::config(function($config) {
    $config->sequence_start = 1;
    $config->auto_validate = false;
    $config->filter_key = false;
    $config->testing = true;
});

Added Options

testing

testing If false, uses create seed data to default database with using Fabricate. All model instance created by CalssRegistry::init('modelName', ['testing'=>false]). see: CakePHP's ClassRegistry::init()

Default: true

Associations

It's possible to set up associations(hasOne/hasMany/belongsTo) within Fabricate::create(). You can also specify a FabricateContext::association(). It will generate the attributes, and set(merge) it in the current array.

Usage

Fabricate::create('User', function($data, $world) {
    return [
        'user' => 'taro',
        'Post' => $world->association('Post', 3),
    ];
});
// or can overwritten by array or callback block.
Fabricate::create('User', function($data, $world) {
    return [
        'user' => 'taro',
        'Post' => $world->association('Post', 3, function($data, $world) {
            return ['title'=>$world->sequence('Post.title',function($i){ return "Title-${i}"; })];
        }),
    ];
});
// can use defined onbject.
Fabricate::define(['PublishedPost', 'class'=>'Post'], ['published'=>'1']);
Fabricate::create('User', function($data, $world) {
    return [
        'user' => 'taro',
        'Post' => $world->association(['PublishedPost', 'association'=>'Post'], 3),
    ];
});
// can use association alias (Post belongs to Author of User class)
Fabricate::define(['PublishedPost', 'class'=>'Post'], ['published'=>'1']);
Fabricate::create('PublishedPost', 3, function($data, $world) {
    return [
        'Author' => $world->association(['User', 'association'=>'Author'], ['id'=>1,'user'=>'taro']),
    ];
});