PHPackages                             sizuhiko/cake\_fabricate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. sizuhiko/cake\_fabricate

ActiveCakephp-plugin[Framework](/categories/framework)

sizuhiko/cake\_fabricate
========================

CakeFabricate plugin for CakePHP

v0.3.0(6y ago)19169.9k↓10.6%8PHPPHP &gt;=5.6CI failing

Since Mar 7Pushed 6y ago2 watchersCompare

[ Source](https://github.com/sizuhiko/cakephp-fabricate-adaptor)[ Packagist](https://packagist.org/packages/sizuhiko/cake_fabricate)[ RSS](/packages/sizuhiko-cake-fabricate/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (9)Used By (0)

[![Build Status](https://camo.githubusercontent.com/feea9a1e4b2dc097e0a3b1a54cd8dacdfa469ab650df16407be44b65e802c59c/68747470733a2f2f7472617669732d63692e6f72672f73697a7568696b6f2f63616b657068702d6661627269636174652d61646170746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sizuhiko/Fabricate) [![Coverage Status](https://camo.githubusercontent.com/001746691da2b2c81636f623ffd90c04ddb7ff1d52c7e7d2c459d6a3213bf19a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f73697a7568696b6f2f63616b657068702d6661627269636174652d61646170746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/sizuhiko/cakephp-fabricate-adaptor?branch=master) [![Total Downloads](https://camo.githubusercontent.com/3575c450ed794265e256a6909d9b898bd923e6181d81fee94ad096a03ae0f2f9/68747470733a2f2f706f7365722e707567782e6f72672f73697a7568696b6f2f63616b655f6661627269636174652f646f776e6c6f6164732e737667)](https://packagist.org/packages/sizuhiko/cake_fabricate) [![Latest Stable Version](https://camo.githubusercontent.com/440f4cb9b5ba50a3462fe5c9d2a482b20d2bda4a84e86f9fcb305caa4a0e9167/68747470733a2f2f706f7365722e707567782e6f72672f73697a7568696b6f2f63616b655f6661627269636174652f762f737461626c652e737667)](https://packagist.org/packages/sizuhiko/cake_fabricate)

CakeFabricate plugin for CakePHP
================================

[](#cakefabricate-plugin-for-cakephp)

CakeFabricate is adaptor for [Fabricate](https://github.com/sizuhiko/Fabricate/tree/v2), and integrate Fabricate(version 2) to CakePHP3.

If you want use CakePHP4, please check [cakephp4 branch](https://github.com/sizuhiko/cakephp-fabricate-adaptor/tree/cakephp4).

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require sizuhiko/cake_fabricate

```

Usage
-----

[](#usage)

At first, Fabricate require to config for using. In app/tests/bootstrap.php, add followings :

```
use Fabricate\Fabricate;
use CakeFabricate\Adaptor\CakeFabricateAdaptor;

Fabricate::config(function($config) {
    $config->adaptor = new CakeFabricateAdaptor();
});
```

APIs
----

[](#apis)

CakeFabricateAdaptor has options. The options set with constructor.

### Configuration

[](#configuration)

```
Fabricate::config(function($config) {
    $config->adaptor = new CakeFabricateAdaptor([
        CakeFabricateAdaptor::OPTION_FILTER_KEY => true
        CakeFabricateAdaptor::OPTION_VALIDATE   => true
    ]);
});

```

#### Supported Options

[](#supported-options)

##### CakeFabricateAdaptor::OPTION\_FILTER\_KEY

[](#cakefabricateadaptoroption_filter_key)

OPTION\_FILTER\_KEY If true, not generate any primary key for auto incrementation id.

`Default: false`

##### OPTION\_VALIDATE

[](#option_validate)

Indicates whether or not to validate when create new entity. see: CakePHP's Entity::newEntity()

`Default: false`

### Generate model attributes as array (not saved)

[](#generate-model-attributes-as-array-not-saved)

`Fabricate::attributes_for(:name, :number_of_generation, :array_or_callback)` generate only attributes.

- name: Table class alias. For get table instance of CakePHP3, called `TableRegistry::get(:name);`.
- number\_of\_generation: Generated number of records
- array\_or\_callback: it can override each generated attributes

#### Example App

[](#example-app)

Entities:

- Model\\Entity\\Post
- Model\\Entity\\User

Tables:

- Model\\Entity\\PostsTable
- Model\\Entity\\UsersTable

Associations:

PostsTable has many UsersTable as Author

#### Example

[](#example)

```
$results = Fabricate::attributes_for('Posts', 10, function($data){
    return ["created" => "2013-10-09 12:40:28", "updated" => "2013-10-09 12:40:28"];
});

// $results is array followings :
array (
  0 =>
  array (
    'title' => 'Lorem ipsum dolor sit amet',
    'body' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.',
    'created' => '2013-10-09 12:40:28',
    'updated' => '2013-10-09 12:40:28',
  ),
  1 =>
  array (
  ....
```

### Generate a entity instance (not saved)

[](#generate-a-entity-instance-not-saved)

`Fabricate::build(:name, :array_or_callback)` generate a entity instance (using Table::newInstance).

- name: Table class alias. For get table instance of CakePHP3, called `TableRegistry::get(:name);`.
- array\_or\_callback: it can override each generated attributes

#### Example

[](#example-1)

```
$result = Fabricate::build('Posts', function($data){
    return ["created" => "2013-10-09 12:40:28", "updated" => "2013-10-09 12:40:28"];
});

// $result a Model\Entity\Post object.
 ......
```

### Generate records to database

[](#generate-records-to-database)

`Fabricate::create(:name, :number_of_generation, :array_or_callback)` generate and save records to database.

- name: Table class alias. For get table instance of CakePHP3, called `TableRegistry::get(:name);`.
- number\_of\_generation: Generated number of records
- array\_or\_callback: it can override each generated attributes

#### Example

[](#example-2)

```
Fabricate::create('Posts', 10, function($data){
    return ["created" => "2013-10-09 12:40:28", "updated" => "2013-10-09 12:40:28"];
});
```

Associations
------------

[](#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

[](#usage-1)

```
Fabricate::create('Users', function($data, $world) {
    return [
        'user' => 'taro',
        'posts' => $world->association('Posts', 3, ['author_id'=>false]),
    ];
});
// can use defined onbject.
Fabricate::define(['PublishedPost', 'class'=>'Posts'], ['published'=>'1']);
Fabricate::create('Users', function($data, $world) {
    return [
        'user' => 'taro',
        'posts' => $world->association(['PublishedPost', 'association'=>'Posts'], 3, ['author_id'=>false]),
    ];
});
// can use association alias (Post belongs to Author of User class)
Fabricate::define(['PublishedPost', 'class'=>'Posts'], ['published'=>'1']);
Fabricate::create('PublishedPost', 3, function($data, $world) {
    return [
        'author' => $world->association(['Users', 'association'=>'Author'], ['id'=>1,'user'=>'taro']),
    ];
});
```

Any more features
-----------------

[](#any-more-features)

Please see documentation of [Fabricate](https://github.com/sizuhiko/Fabricate/tree/v2).

Contributing to this Library
----------------------------

[](#contributing-to-this-library)

Please feel free to contribute to the library with new issues, requests, unit tests and code fixes or new features. If you want to contribute some code, create a feature branch from develop, and send us your pull request.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~364 days

Recently: every ~451 days

Total

6

Last Release

2269d ago

PHP version history (2 changes)v0.1PHP &gt;=5.4

v0.3.0PHP &gt;=5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/132000?v=4)[Kenichiro Kishida](/maintainers/sizuhiko)[@sizuhiko](https://github.com/sizuhiko)

---

Top Contributors

[![sizuhiko](https://avatars.githubusercontent.com/u/132000?v=4)](https://github.com/sizuhiko "sizuhiko (41 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (5 commits)")[![tenkoma](https://avatars.githubusercontent.com/u/16202?v=4)](https://github.com/tenkoma "tenkoma (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sizuhiko-cake-fabricate/health.svg)

```
[![Health](https://phpackages.com/badges/sizuhiko-cake-fabricate/health.svg)](https://phpackages.com/packages/sizuhiko-cake-fabricate)
```

###  Alternatives

[cakephp/debug_kit

CakePHP Debug Kit

86514.0M138](/packages/cakephp-debug-kit)[cakephp/bake

Bake plugin for CakePHP

11211.2M158](/packages/cakephp-bake)[friendsofcake/bootstrap-ui

Bootstrap front-end framework support for CakePHP

3492.1M32](/packages/friendsofcake-bootstrap-ui)[cakephp/app

CakePHP skeleton app

3831.7M1](/packages/cakephp-app)[cakephp/localized

CakePHP Localized Plugin

218595.6k5](/packages/cakephp-localized)[cakephp/acl

Acl Plugin for CakePHP framework

109553.9k15](/packages/cakephp-acl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
