GitHub - Danon910/blitzy
Extracto
Contribute to Danon910/blitzy development by creating an account on GitHub.
Contenido
Blitzy ⚡
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=configConfiguration
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 --forceGenerate test with more precision
php artisan blitzy:generate "{path}" --type=smoke --feature=Post --methods=index,show --forceRequired 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 --forceGenerate integration test
php artisan blitzy:generate "App\Services\PostService" --type=integration --forceGenerate unit test
php artisan blitzy:generate "App\Services\PostService" --type=unit --forceExamples
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.
Fuente: GitHub