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!
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
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
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
- if use
belongsTo
you should create relation model first and add getRelationData i model
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.
- 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.
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
Strengthen your application's defenses by automating Request Validation tests:
php artisan generator:run {Model} {ModelPath} -r
Embrace clean architecture by splitting controller logic into dedicated Action classes:
php artisan generator:run {Model} {ModelPath} -c
Our Error Logging Trait is your silent guardian, logging every misstep in the shadows so your app never falters.
- 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.
To arm your controllers with our trait, simply integrate it with:
php artisan generator:run {Model} {ModelPath} -f -r -c
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.
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.