simplemachineorg / generate-laravel-test
使用人工智能动态创建应用程序中PHP类的测试。
0.1.2
2024-08-16 14:31 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0|^11.0
- laravel/prompts: ^0.1.15|dev-support-older-php
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
ALPHA
此包正在开发中,可能会有破坏性更改。
概述
它使您能够通过GPT快速创建Laravel测试。该包将您的代码文件发送到GPT,并附带一些提示指令,然后在_draft文件夹中保存草稿测试。
每个生成的测试都需要调整,因为GPT不了解应用程序的所有内容,但它是一个有用的起点。在实际操作中,当脚手架工作自动完成时,编写更多的测试会更加容易。
安装
运行此命令...
composer require simplemachineorg/generate-laravel-test`
然后,在env中设置您的API密钥...
GENERATE_TEST_OPENAI_API_KEY=
可选地,您可以使用以下命令发布配置文件...
php artisan vendor:publish --tag="generate_laravel_test-config"
使用此包
运行此命令以使用人工智能生成测试...
php artisan generate:test
它将要求您在代码库中搜索PHP文件,并使用该文件生成测试。
添加有关应用程序的定制说明
您可以创建一个文件,该文件在每次请求中渲染有关应用程序的定制说明,从而使测试生成器对您的特定配置更加智能。默认情况下,在resources/views/utility/generate-test-custom-notes.blade.php
中创建一个视图,并编写您的说明。您可以选择更改配置中的文件位置。
发布配置(可选)
php artisan vendor:publish --tag=":generate_laravel_test-config"
这是默认配置文件...
return [ /* |-------------------------------------------------------------------------- | API Key |-------------------------------------------------------------------------- | | An OpenAI API key is required to use this package. | */ 'open_ai_api_key' => env('GENERATE_TEST_OPENAI_API_KEY'), /* |-------------------------------------------------------------------------- | Custom notes Path (optional) |-------------------------------------------------------------------------- | | You can create a blade file with extra notes which will get placed | inside each request so the AI knows more about your specific app. | */ 'custom_notes' => env('GENERATE_TEST_EXTRA_NOTES_PATH', 'utility.generate-test-custom-notes'), /* |-------------------------------------------------------------------------- | Comment Out code before adding to the project |-------------------------------------------------------------------------- | | If PHP detects code inside the project with a syntax error, it will | throw an exception until you fix it. So you can comment out all code | to avoid runtime errors. | */ 'comment_out' => env('GENERATE_TEST_COMMENT_OUT', true), /* |-------------------------------------------------------------------------- | Default Model |-------------------------------------------------------------------------- | | The default OpenAI model used for creating tests. | */ 'default_model' => env('GENERATE_TEST_DEFAULT_MODEL', 'gpt-4o'), /* |-------------------------------------------------------------------------- | TEST RUNNER |-------------------------------------------------------------------------- | | Either 'pest' or 'phpunit' | */ 'runner' => env('GENERATE_TEST_RUNNER', 'pest'), /* |-------------------------------------------------------------------------- | PATH TO STORE DRAFT FILES |-------------------------------------------------------------------------- | | Where should we put the files once they are processed? | Note: the files will not be runnable PHP immediately. | | */ 'draft_test_file_path' => env('GENERATE_TEST_FILE_PATH', 'tests/Feature/_draft'), ];