Skip to content

Releases: sizuhiko/Fabricate

Release v2.0.3

26 Jun 00:58
Compare
Choose a tag to compare

Build with PHP 7.1

Thanks contribute @tenkoma .

Release v1.3.0

30 Oct 10:42
Compare
Choose a tag to compare

String class was renamed to CakeText from CakePHP 2.8

cakephp/cakephp@63093e1

Please use the version if you use after CakePHP2.8.0.

Thanks, PR from @katsukii / Peraichi

Release v2.0.2

21 Jun 09:03
Compare
Choose a tag to compare

Fix bug:

  • #24 Ensure that $record always exists

Release v2.0.1

16 Apr 02:06
Compare
Choose a tag to compare

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

13 Feb 07:33
Compare
Choose a tag to compare

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

05 Jun 00:18
Compare
Choose a tag to compare

Include bug fix.

Version 2.0.0

18 Apr 06:01
Compare
Choose a tag to compare

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

21 Jul 08:25
Compare
Choose a tag to compare

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

08 Jun 11:33
Compare
Choose a tag to compare

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();

Fix bugs

11 Feb 08:53
Compare
Choose a tag to compare
Merge pull request #3 from sizuhiko/develop

bug fixes