Releases: sizuhiko/Fabricate
Release v2.0.3
Release v1.3.0
String class was renamed to CakeText from CakePHP 2.8
Please use the version if you use after CakePHP2.8.0.
Release v2.0.2
Fix bug:
- #24 Ensure that $record always exists
Release v2.0.1
Add config $text_size_limit
for using to generate fake data of text field.
Because text field size is biggest then generation became slow.
Release v1.2.2
Bux fix:
If you use type of char(1)
for generating automation, then throw Exception followings:
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'hoge' at row 1
From PR #19 , thanks.
Version 1.2.1.1
Include bug fix.
Version 2.0.0
New Feature v2.0.0
Fabricate 2.0.0 is not only CakePHP.
For all framework of PHP.
Usage
Adaptor
At first, Fabricate require to config for using. For example, to override these settings, put a bootstrap.php in your app folder and append the path to phpunit.xml
use Fabricate\Fabricate;
use CakeFabricate\Adaptor\CakeFabricateAdaptor;
Fabricate::config(function($config) {
$config->adaptor = new CakeFabricateAdaptor();
});
Fabricate doesn't provide adaptors. If you will make adaptor of any frameworks, send us your pull request. The pull request will include suggestion into composer.json and link of repository on README(Comunity Adaptors).
Version 1.2.1
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']),
];
});
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();