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.
composer.json
autoload
and autoload-dev
sections from composer.json
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: