Download the PHP package genericmilk/sakura without Composer
On this page you can find all versions of the php package genericmilk/sakura. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download genericmilk/sakura
More information about genericmilk/sakura
Files in genericmilk/sakura
Package sakura
Short Description Automated test generation for Laravel applications using OpenAI, Claude, Gemini, or Ollama
License MIT
Informations about the package sakura
Table of Contents
- Features
- Installation
- Usage
- Basic Usage
- Advanced Usage
- AI Providers
- OpenAI
- Claude
- Gemini
- Ollama
- Setting up Gemini
- Setting up Claude
- Setting up Ollama
- How It Works
- 1. Code Analysis
- 2. Change Detection
- 3. Test Generation
- 4. Test Organization
- Configuration
- AI Provider Settings
- OpenAI Settings
- Claude Settings
- Gemini Settings
- Ollama Settings
- Analysis Directories
- Testing Configuration
- File Structure
- Example Output
- Generated Test Examples
- Pest Feature Test (Controller)
- PHPUnit Unit Test (Service)
- Provider Comparison
- Troubleshooting
- OpenAI Issues
- Claude Issues
- Gemini Issues
- Ollama Issues
- General Issues
- Requirements
- Contributing
- License
- Support
Features
- Smart Code Analysis: Automatically detects and tracks changes in your PHP classes and functions
- Intelligent Test Generation: Uses OpenAI, Claude, Gemini, or Ollama to generate comprehensive Feature and Unit tests
- Framework Detection: Automatically detects whether your project uses Pest or PHPUnit
- Change Tracking: Only generates tests for code that has changed or is new
- Flexible Configuration: Highly configurable to match your project structure
- Progress Tracking: Beautiful CLI interface with progress bars and detailed feedback
- Multiple AI Providers: Support for OpenAI API, Claude API, Gemini API, and local Ollama models
Installation
-
Install the package via Composer:
-
Publish the configuration file:
- Configure your AI provider:
For OpenAI:
For Claude:
For Gemini:
For Ollama:
- Optional: Configure additional settings in your
.envfile:
Usage
Basic Usage
Generate tests for all changed/new code:
Advanced Usage
Force regeneration of all tests:
Generate tests for a specific class:
Generate tests for a specific function:
Dry run (see what would be generated without creating files):
Override AI provider for this run:
AI Providers
OpenAI
- Pros: High-quality test generation, reliable API, fast response times
- Cons: Requires API key, costs per request
- Best for: Production environments, high-quality test generation
- Models: GPT-4o-mini, GPT-4o, GPT-4-turbo
Claude
- Pros: Excellent code understanding, high-quality output, strong reasoning
- Cons: Requires API key, costs per request, slightly slower than OpenAI
- Best for: Complex codebases, high-quality test generation, reasoning-heavy tasks
- Models: Claude 3.5 Sonnet, Claude 3.5 Haiku, Claude 3 Opus
Gemini
- Pros: Fast response times, good code understanding, competitive pricing
- Cons: Requires API key, costs per request, newer API
- Best for: Fast development cycles, cost-effective test generation
- Models: Gemini 1.5 Pro, Gemini 1.5 Flash, Gemini 1.0 Pro
Ollama
- Pros: Free, runs locally, no API costs, privacy-focused
- Cons: Requires local setup, model quality varies, slower inference
- Best for: Development environments, privacy-conscious teams
- Models: CodeLlama, Llama2, Mistral, DeepSeek Coder
Setting up Gemini
-
Get a Google AI API key:
- Visit https://makersuite.google.com/app/apikey
- Create an account and generate an API key
-
Configure sakura:
- Test the configuration:
Setting up Claude
-
Get an Anthropic API key:
- Visit https://console.anthropic.com/
- Create an account and generate an API key
-
Configure sakura:
- Test the configuration:
Setting up Ollama
-
Install Ollama:
-
Start Ollama:
-
Pull a code model:
- Configure sakura:
How It Works
1. Code Analysis
sakura analyzes your codebase and creates a tree of all PHP classes and functions in the configured directories:
- Controllers
- Services
- Actions
- Enums
- Commands
- Models
- Repositories
- Jobs
- Listeners
- Notifications
2. Change Detection
sakura tracks changes by:
- Computing hashes of class content and individual methods
- Comparing current code with previously saved state
- Detecting new classes and functions
- Identifying modified methods
3. Test Generation
For each changed/new item, sakura:
- Determines the appropriate test type (Feature vs Unit)
- Detects your testing framework (Pest or PHPUnit)
- Generates comprehensive tests using your chosen AI provider
- Saves tests to the appropriate directory structure
4. Test Organization
Tests are organized following Laravel conventions:
- Feature tests:
tests/Feature/for controllers and HTTP-related code - Unit tests:
tests/Unit/for services, actions, and business logic - Directory structure: Mirrors your app directory structure
Configuration
AI Provider Settings
OpenAI Settings
Claude Settings
Gemini Settings
Ollama Settings
Analysis Directories
Note: Sakura will only analyze directories that exist in your project. If you see "No changes detected" on a fresh installation, you may need to:
- Adjust the
directoriesarray to match your project structure - Create some PHP classes in the configured directories
- Run
php artisan sakura:generate-tests --forceto analyze all existing code
Testing Configuration
File Structure
After installation, sakura creates a .sakura directory in your project root:
Example Output
When you run php artisan sakura:generate-tests, you'll see output like:
Generated Test Examples
Pest Feature Test (Controller)
PHPUnit Unit Test (Service)
Provider Comparison
| Feature | OpenAI | Claude | Gemini | Ollama |
|---|---|---|---|---|
| Cost | Per request | Per request | Per request | Free |
| Speed | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Quality | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| Privacy | ⭐⭐ | ⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐⭐ |
| Setup | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Customization | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
Troubleshooting
OpenAI Issues
- API Key Error: Ensure
OPENAI_API_KEYis set in your.envfile - Rate Limiting: Check your OpenAI usage limits
- Model Not Found: Verify the model name in your configuration
Claude Issues
- API Key Error: Ensure
ANTHROPIC_API_KEYis set in your.envfile - Rate Limiting: Check your Anthropic usage limits
- Model Not Found: Verify the model name in your configuration
- Timeout: Claude responses can be slower, increase timeout if needed
Gemini Issues
- API Key Error: Ensure
GOOGLE_AI_API_KEYis set in your.envfile - Rate Limiting: Check your Google AI usage limits
- Model Not Found: Verify the model name in your configuration
- Timeout: Increase
sakura_GEMINI_TIMEOUTif needed
Ollama Issues
- Connection Error: Ensure Ollama is running with
ollama serve - Model Not Found: Pull the model with
ollama pull <model-name> - Timeout: Increase
sakura_OLLAMA_TIMEOUTfor slower models
General Issues
- No Changes Detected on Fresh Installation: On first run, Sakura should automatically detect all existing code. If you see "No changes detected" on a fresh installation, it means no PHP classes were found in the configured directories. Check that the directories in
config/sakura.phpmatch your project structure. - No Changes Detected (Subsequent Runs): Use
--forceto regenerate all tests - Test Quality: Adjust temperature settings for more/less creative tests
- Framework Detection: Manually set
sakura_TEST_FRAMEWORKif auto-detection fails - Empty Project: If your project has no classes yet, create some in
app/Modelsorapp/Http/Controllersfirst
Requirements
- PHP 8.1+
- Laravel 10.0+ or 11.0+
- OpenAI API key (for OpenAI provider)
- Anthropic API key (for Claude provider)
- Google AI API key (for Gemini provider)
- Ollama (for Ollama provider)
- Composer
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see License File for more information.
Support
If you encounter any issues or have questions, please open an issue on GitHub.
Made with ❤️ by Genericmilk
All versions of sakura with dependencies
laravel/framework Version ^10.0|^11.0
guzzlehttp/guzzle Version ^7.0
openai-php/client Version ^0.8.0
wpai-inc/anthropic-sdk-php Version ^0.2.0
google-gemini-php/client Version ^2.3.0