The PhpSpec Intelligence Extension introduces a next
command to PhpSpec, leveraging OpenAI's GPT models to suggest the
next specification to implement in your test-driven development workflow.
Test-driven development (TDD) encourages writing tests before implementing code. However, deciding what to test next can sometimes be challenging. This extension integrates with OpenAI's API to analyze your existing specs and provide intelligent suggestions for the next spec to write, streamlining your TDD process.
- Automated Spec Suggestions: Get suggestions for your next spec based on existing specifications.
- Seamless Integration: Adds a
next
command to PhpSpec without disrupting your workflow. - Configurable Parameters: Customize API settings like model, max tokens, and temperature.
Install the extension via Composer:
composer require --dev md/phpspec-intelligence-extension
To use the extension, you need to:
- Enable the Extension: Add it to your
phpspec.yml
configuration file. - Set the OpenAI API Key: Provide your OpenAI API key securely.
Update your phpspec.yml
file:
extensions:
Md\PhpSpecIntelligenceExtension\Extension:
openai_api_key: ~
openai_api_model: "gpt-3.5-turbo"
openai_api_temperature: 0.7
openai_api_max_tokens: 256
For security, it's recommended to use environment variables to store your API key.
Set the OPENAI_API_KEY
environment variable in your shell or server configuration.
export OPENAI_API_KEY='your-openai-api-key'
You can also set the API key in the phpspec.yml
file (not recommended for shared repositories):
extensions:
Md\PhpSpecIntelligenceExtension\Extension:
openai_api_key: 'your-openai-api-key'
Warning: Avoid committing API keys to version control.
After installation and configuration, you can use the next
command:
vendor/bin/phpspec next
The command will analyze your existing specs and suggest the next one to implement.
--config
: Specify a custom configuration file.--verbose
: Increase the verbosity of messages.
Example:
vendor/bin/phpspec next --config=phpspec.yml --verbose
vendor/bin/phpspec next
Output:
Suggested example for: spec/Acme/MarkdownSpec.php:
function it_registers_the_next_command(ServiceContainer $container)
{
$container->define('console.commands.next',
Argument::type('Closure'),
Argument::type('array')
)->shouldBeCalled();
$this->load($container, []);
}
Would you like me to generate this spec? [Y/n]
vendor/bin/phpspec next --config=custom-phpspec.yml
If you encounter rate limits or quota issues, the command will display an appropriate error message. Ensure your OpenAI account has sufficient quota and consider implementing retry logic if needed.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Write specs for your changes.
- Submit a pull request with a detailed description.
vendor/bin/phpspec run
This project is licensed under the MIT License. See the LICENSE file for details.
Note: This extension uses the OpenAI API, which may incur costs. Monitor your usage to avoid unexpected charges. Always handle API keys securely and follow best practices to protect sensitive information.