danon910 / blitzy
Laravel test generator package
Requires
- php: ^8.1
- illuminate/support: ^10.0
This package is auto-updated.
Last update: 2025-05-25 15:41:48 UTC
README
Blitzy is a lightweight package for Laravel that automates test generation. It is designed to speed up the testing process and make developers' lives easier.
Installation
1. Install package using composer
composer require danon910/blitzy --dev
2. Add the ServiceProvider in config/app.php
\Danon910\blitzy\Providers\BlitzyProvider::class,
3. Publish config
php artisan vendor:publish --provider="Danon910\blitzy\Providers\BlitzyProvider" --tag=config
Configuration
Before use Blitzy you should customize its behavior for your requirements, you can edit the configuration file located at config/blitzy.php
.
What does the package do?
This package generates Test
and Trait
files in the tests
folder with the correct namespace and a simple structure, ready for writing real working tests.
Commands
Generate simple test
php artisan blitzy:generate "{path}" --type=smoke --force
Generate test with more precision
php artisan blitzy:generate "{path}" --type=smoke --feature=Post --methods=index,show --force
Required params
{path}
Path of tested class
--type
smoke / integration / unit
Optional params
--feature
Name of feature which will be saved in docblock
--methods
Provide methods which should be parsed (e.g. index,show)
--force
If you want to overwrite already generated existing test files
Usage
Generate smoke test
php artisan blitzy:generate "App\Http\Controllers\PostController" --type=smoke --force
Generate integration test
php artisan blitzy:generate "App\Services\PostService" --type=integration --force
Generate unit test
php artisan blitzy:generate "App\Services\PostService" --type=unit --force
Examples
Smoke test
<?php /** This test file was automatically generated by Blitzy. */ declare(strict_types=1); namespace Tests\Smoke\App\Http\Controllers\PostController\Index; use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseTransactions; class PostControllerTest extends TestCase { use PostControllerTrait; use DatabaseTransactions; /** * @feature Post * @scenario Index * @case Happy path * * @expectation Return valid json structure * * @test */ public function index_happyPath_returnValidJsonStructure(): void { $this->markTestSkipped("Test generated automatically!"); // TODO: Check this test! // GIVEN // WHEN $response = $this->getJson(route("posts.index")); // THEN $response->assertOk(); $response->assertJsonStructure($this->getExpectedJsonStructure()); } }
Integration test
<?php /** This test file was automatically generated by Blitzy. */ declare(strict_types=1); namespace Tests\Integration\App\Services\PostService\FindById; use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseTransactions; class PostServiceTest extends TestCase { use PostServiceTrait; use DatabaseTransactions; /** * @feature Post * @scenario Find by id * @case Happy path * * @expectation TODO * * @test */ public function findById_happyPath_todo(): void { // GIVEN $properties = []; $id = 1; // WHEN $result = $this->getTestedClass($properties)->findById($id); // THEN // TODO } }
Unit test
<?php /** This test file was automatically generated by Blitzy. */ declare(strict_types=1); namespace Tests\Unit\App\Services\PostService\FindById; use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseTransactions; class PostServiceTest extends TestCase { use PostServiceTrait; use DatabaseTransactions; /** * @feature Post * @scenario Find by id * @case Happy path * * @expectation TODO * * @test */ public function findById_happyPath_todo(): void { // GIVEN $properties = []; $id = 1; // WHEN $result = $this->getTestedClass($properties)->findById($id); // THEN // TODO } }
Changelog
See CHANGELOG for more information what has changed recently.