tdd.nvim
is a Neovim plugin designed to streamline test-driven development for PHP projects. It allows you to quickly jump between a PHP class and its corresponding PHPUnit test, and will create the test file if it doesn't exist.
NOTE: This plugin is still under active development. In future versions, it is expected to handle namespaces and file paths more robustly.
- Detects matching test files based on PSR-4 mappings in
composer.json
- Prompts to open an existing test in a vertical split
- Creates a new PHPUnit test class with the correct namespace and path
- Parses both
autoload
andautoload-dev
sections fromcomposer.json
- Automatically finds the project root
Using Lazy.nvim:
{
"zkucekovic/tdd.nvim",
config = function()
require("tdd").setup()
end,
}
Open any PHP class file and run the following command:
:GetTest
If a matching test file exists, the plugin will prompt you to open it in a vertical split. If it doesn't exist, it will offer to create one using a PHPUnit skeleton. The plugin uses the PSR-4 autoload mappings in your composer.json
file to determine the correct file path and namespace.
Given a source file:
src/Article/src/Repository/Article.php
And the following composer.json
mapping:
"autoload": {
"psr-4": {
"Content\\Article\\": "src/Article/src"
}
},
"autoload-dev": {
"psr-4": {
"Test\\Content\\Article\\": "src/Article/tests/src"
}
}
tdd.nvim
will create or open:
src/Article/tests/src/Repository/ArticleTest.php
With the following namespace:
namespace Test\Content\Article\Repository;
Contributions are welcome. Please keep the code simple, modular, and testable. The plugin is in early development, so unit tests are not mandatory yet, but writing clean and reusable modules is encouraged.
To contribute:
- Fork or clone the repository
- Work in a feature branch
- Test locally with your Neovim setup
- Submit a pull request