50

GitHub - Naoray/laravel-factory-prefill: Prefills factories with faker method su...

 5 years ago
source link: https://github.com/Naoray/laravel-factory-prefill
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

readme.md

laravel-factory-prefill

Software License Total Downloads Build Status

Factories are a great concept and I really love to use them for testing purposes, but it sucks to write every needed column name and associated faker methods by hand. This package aims to make the process less painful by providing a command to prefill your factories!

After creating a factory with the artisan cli you end up having something like this:

<?php

use Faker\Generator as Faker;

$factory->define(Model::class, function (Faker $faker) {
    return [
        //
    ];
});

With laravel-factory-prefill you can just skip the previous command call and instead execute php artisan factory:prefill Habit.

factory:prefill

Install

composer require naoray/laravel-factory-prefill --dev

Usage

After running php artisan migrate you are good to go. If you want the factory:prefill command to notice the model relations, you should implement the methods first!

php artisan factory:prefill model_name

Tip: If you also want the realtionships to be loaded automatically, you have to define the methods in the models.

To prefill factories from models outside of the App/ namespace just add the -O flag and provide the full path in the model name.

php artisan factory:prefill "Some\Other\Namespace\ModelName" -O

Testing

Run the tests with:

vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK