fadllabanie / laravel_unittest_generator
Requires
- php: >=7.3
- illuminate/support: ^8.0|^9.0|^10.0
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.