2017 © Pedro Peláez
 

library laravel-test-factory-helper

Generate Laravel test factories from your existing models

image

mpociot/laravel-test-factory-helper

Generate Laravel test factories from your existing models

  • Monday, October 9, 2017
  • by mpociot
  • Repository
  • 12 Watchers
  • 364 Stars
  • 83,942 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 30 Forks
  • 7 Open issues
  • 10 Versions
  • 16 % Grown

The README.md

Laravel Test Factory Generator

php artisan generate:model-factory, (*1)

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

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),
        'remember_token' => Str::random(10),
    ];
});

Install

Require this package with composer using the following command:, (*3)

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

Usage

To generate multiple factories at once, run the artisan command:, (*4)

php artisan generate:model-factory, (*5)

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., (*6)

To generate a factory for specific model or models, run the artisan command:, (*7)

php artisan generate:model-factory User Team, (*8)

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:, (*9)

php artisan generate:model-factory --dir app/Models -- User Team, (*10)

License

The Laravel Test Factory Helper is free software licensed under the MIT license., (*11)

The Versions

09/10 2017

dev-master

9999999-dev

Generate Laravel test factories from your existing models

  Sources   Download

MIT

The Requires

 

laravel tests factory

09/10 2017

0.5.0

0.5.0.0

Generate Laravel test factories from your existing models

  Sources   Download

MIT

The Requires

 

laravel tests factory

02/02 2017

0.4.0

0.4.0.0

Generate Laravel test factories from your existing models

  Sources   Download

MIT

The Requires

 

laravel tests factory

26/08 2016
25/08 2016
25/05 2016

0.2.1

0.2.1.0

Generate Laravel test factories from your existing models

  Sources   Download

MIT

The Requires

 

laravel tests factory

02/04 2016

0.2.0

0.2.0.0

Generate Laravel test factories from your existing models

  Sources   Download

MIT

The Requires

 

laravel tests factory

02/04 2016

0.1.2

0.1.2.0

Generate Laravel test factories from your existing models

  Sources   Download

MIT

The Requires

 

laravel tests factory

02/04 2016

0.1.1

0.1.1.0

Generate Laravel test factories from your existing models

  Sources   Download

MIT

The Requires

 

laravel tests factory

27/03 2016

0.1

0.1.0.0

Generate Laravel test factories from your existing models

  Sources   Download

MIT

The Requires

 

laravel tests factory