jcloutz/forger

该软件包已被废弃,不再维护。未建议替代软件包。

旨在允许快速创建用于数据库填充的已填充模型实例。

1.0.2 2014-03-18 23:11 UTC

This package is not auto-updated.

Last update: 2020-05-15 16:52:09 UTC


README

Build Status

该软件包旨在允许在 Laravel 中快速创建数据库对象。

安装

在您的 composer.json 文件的 require 键中添加以下内容。

"jcloutz/forger": "dev-master"

运行 composer update 命令

$ composer update

用法

Forger 为项目中的任何模型提供了快速检索填充模拟的能力。它使用 Faker 包 根据值数组生成模拟数据。

<?php // namespace Models;

use Jcloutz\Mocker\MockerTrait;

class Widget extends Eloquent
{
    use ForgerTrait;

    protected $table = 'widgets';

    protected $fillable = [];

    public static $mockable = array(
        'name'  => 'A Fancy Widget', // Static data
        'cost'  => 'randomFloat|2|0|100', // Faker method with arguments
        'price' => 'call|uppercase|word', // Call to user function with data from faker
    );

    public function uppercase($string)
    {
        return strtoupper($string);
    }
}

ForgerTrait 为模型提供了两个静态函数:::forge()::forgeCreate()

    // Returns an instance of Widget without saving it to the database.
    $widget = Widget::forge();

    // Returns an instance of Widget and saves it to the database.
    $widget = Widget::forgeCreate();

许可证

WTFPL