GithubHelp home page GithubHelp logo

naoray / laravel-factory-prefill Goto Github PK

View Code? Open in Web Editor NEW
103.0 4.0 6.0 212 KB

Prefills factories with faker method suggestions to increase productivity

License: MIT License

PHP 99.55% Blade 0.45%
laravel factory package prefill

laravel-factory-prefill's Introduction

laravel-factory-prefill

Software License Total Downloads Build Status

This repository has been archived! Use Shift's Factory Generator to utilize the new class factories of Laravel 8.

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!

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

Fill all Factories

To generate factories for all models run

php artisan factory:all

Models in different directories

To prefill factories from models outside of the app/ directory just add the -P flag and provide the path.

php artisan factory:all --path=Some/Other/Path

you can also append the --realpath option to indicate that the given path is a pre-resolved absolut path.

Fill single Factory

To fill a single factory you can either run php artisan factory:prefill model_name or php artisan factory:all model_name.

Models with different namespace

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

Nullable columns

By default nullable columns are ignored. If you want to also add nullable columns to your factory includ the flag -N or --allow-nullable.

php artisan factory:prefill ModelName -N or php artisan factory:all -N

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.

laravel-factory-prefill's People

Contributors

braunson avatar dependabot[bot] avatar jasonmccreary avatar jaybizzle avatar naoray avatar stancl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-factory-prefill's Issues

Required 5.8 and above?

I understand the support for 5.8+ but some of us right now are not able to update due to dependencies stuck on 5.7, any way to support 5.7 for the time being?

Consider lazy() method for relationship

Hello.

First of all, great package!

I've noticed that relationships are generated using and old method. Have you considered using factory(App\REPLACE_THIS::class)->lazy(); instead?

It should not be a problem since the package is targeting illuminate 5.7 and lazy() is present since 5.5

Laravel 6.1 support

The current setting for Laravel 6 is too restrictive. Since Laravel now follows semver, you can use ^6.0 instead of ~6.0.0.

Column name 'password' generates false factory row

Running the package command php artisan factory:prefill User on a laravel default installation results in

//...
'password' => $faker->bcrypt($faker->word(255)),

but should result in

//...
'password' => bcrypt($faker->word(255)),
  • add test for failing scenario
  • fix implementation

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.