Giter Site home page Giter Site logo

laravel-test-factory-helper's Introduction

Laravel Test Factory Generator

php artisan generate:model-factory

This package will generate factories from your existing models so you can get started with testing your Laravel application more quickly.

Example output

Migration and Model

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('username');
    $table->string('email')->unique();
    $table->string('password', 60);
    $table->integer('company_id');
    $table->rememberToken();
    $table->timestamps();
});

class User extends Model {
    public function company()
    {
        return $this->belongsTo(Company::class);
    }
}

Factory Result

$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'username' => $faker->userName,
        'email' => $faker->safeEmail,
        'password' => bcrypt($faker->password),
        'company_id' => factory(App\Company::class)->create()->id,
        'remember_token' => Str::random(10),
    ];
});

Install

Require this package with composer using the following command:

composer require --dev mpociot/laravel-test-factory-helper

Usage

To generate multiple factories at once, run the artisan command:

php artisan generate:model-factory

This command will find all models within your application and create test factories. By default, this will not overwrite any existing model factories. You can force overwriting existing model factories by using the --force option.

To generate a factory for specific model or models, run the artisan command:

php artisan generate:model-factory User Team

By default, this command will search under the app folder for models. If your models are within a different folder, for example app/Models, you can specify this using --dir option. In this case, run the artisan command:

php artisan generate:model-factory --dir app/Models -- User Team

License

The Laravel Test Factory Helper is free software licensed under the MIT license.

laravel-test-factory-helper's People

Contributors

dontfreakout avatar dweineratl avatar edmandiesamonte avatar ilvsx avatar jasonmccreary avatar jijoel avatar mpociot avatar oussama-tn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.