fadllabanie/laravel_unittest_generator

v2.5.2 2023-12-31 15:16 UTC

This package is auto-updated.

Last update: 2024-10-30 02:21:43 UTC


README

Supercharge your Laravel application's testing workflow with the laravel-generator package. This dynamic toolkit is your steadfast ally in creating robust unit tests with a touch of magic!

๐Ÿš€ Installation

Time to bring the laravel-generator into your project. Cast these spells with Composer:

composer require fadllabanie/laravel-generator

Invoke the artisan to publish your configs:

php artisan vendor:publish

Finally, migrate to shape your database's destiny:

php artisan migrate

๐Ÿ”ง Configuration

For the enchantment to work, your models must be imbued with these arcane properties:

public function getFillable()
{
    return [
        'title',
        'description',
    ];
}

public function getFillableType()
{
    return [
        'title' => 'string',
        'description' => 'text',
    ];
}

public function getRelationData()
    {
        return [
            'relationName1' => RelatedModel1::class,
            'relationName2' => RelatedModel2::class,
            // Add other relationships as needed
        ];
    }

Supported data types include: string, text, integer, float, date, image, datetime, boolean, password, email, token, belongsTo

๐Ÿ“– Usage

With the package now part of your repository, conjure unit tests for your models with a simple artisan command:

php artisan generator:run {Model} {ModelPath} {options}
php artisan generator:run Post App/Models -f -r -c

๐Ÿ“– NOTE:

  • if use belongsTo you should create relation model first and add getRelationData i model

๐ŸŽ›๏ธ Options

Fine-tune your unit test generation with these options:

  • -f or --factory: Summon a factory alongside your test for authentic data alchemy.
  • -c or --controller: Invoke a controller test for double the sorcery.
  • -r or --request: Enforce request validation tests for an impenetrable defense.

โœจ Features

  • Generate Factories: Automatically create factories based on your model's $fillable and $fillableType.
  • CRUD Unit Tests: Conjure tests for Create, Read, Update, Delete, and relationships in one incantation.
  • Action Pattern Controller: Organize your controller logic with discrete Action classes for clarity and reusability.

๐Ÿงช Generate Factories

The command transmutes your model properties into a factory class, paving the way for effortlessly creating test data:

php artisan generator:run {Model} {ModelPath} -f

๐Ÿ”’ Generate Request Validation Tests

Strengthen your application's defenses by automating Request Validation tests:

php artisan generator:run {Model} {ModelPath} -r

๐Ÿ› ๏ธ Generate Controller with Action Pattern

Embrace clean architecture by splitting controller logic into dedicated Action classes:

php artisan generator:run {Model} {ModelPath} -c

๐Ÿ’ก The Magic Behind the Trait

Our Error Logging Trait is your silent guardian, logging every misstep in the shadows so your app never falters.

Benefits

  • Automated Error Tracking: Capture errors without lifting a wand.
  • Easy Error Retrieval: Consult the database as your crystal ball for error insights.
  • Streamlined Debugging: Navigate the maze of bugs with an enchanted map.

How to Generate

To arm your controllers with our trait, simply integrate it with:

php artisan generator:run {Model} {ModelPath} -f -r -c

๐Ÿ“œ Known Issues

Ensure your models are correctly named and that your composer.json pathways are prophesied correctly. The $fillable and $fillableType must be declared to conjure tests properly.

๐Ÿ“š Contributing

Join our coven of contributors! Whether it's fixes, enhancements, or new features, your pull requests shall be greeted with a feast.

This README not only guides users through the mystical arts of unit test generation but also conveys the magical essence of the package. It aims to engage developers by blending technical instructions with thematic charm.