Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/olimorris/neotest-phpunit
๐งช Neotest adapter for PHPUnit
https://github.com/olimorris/neotest-phpunit
neotest neovim neovim-plugin nvim php phpunit
Last synced: about 1 month ago
JSON representation
๐งช Neotest adapter for PHPUnit
- Host: GitHub
- URL: https://github.com/olimorris/neotest-phpunit
- Owner: olimorris
- License: mit
- Created: 2022-07-04T23:44:47.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-05T09:31:40.000Z (8 months ago)
- Last Synced: 2024-12-02T08:15:52.723Z (about 1 month ago)
- Topics: neotest, neovim, neovim-plugin, nvim, php, phpunit
- Language: Lua
- Homepage:
- Size: 63.5 KB
- Stars: 35
- Watchers: 2
- Forks: 25
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# neotest-phpunit
[![Tests](https://github.com/olimorris/neotest-phpunit/actions/workflows/ci.yml/badge.svg)](https://github.com/olimorris/neotest-phpunit/actions/workflows/ci.yml)
This plugin provides a [PHPUnit](https://phpunit.de) adapter for the [Neotest](https://github.com/nvim-neotest/neotest) framework.
## :package: Installation
Install with the package manager of your choice:
**Lazy**
```lua
{
"nvim-neotest/neotest",
lazy = true,
dependencies = {
...,
"olimorris/neotest-phpunit",
},
config = function()
require("neotest").setup({
...,
adapters = {
require("neotest-phpunit")
},
}
end
}
```**Packer**
```lua
use({
"nvim-neotest/neotest",
requires = {
...,
"olimorris/neotest-phpunit",
},
config = function()
require("neotest").setup({
...,
adapters = {
require("neotest-phpunit"),
}
})
end
})
```## :wrench: Configuration
### Default configuration
> [!NOTE]
> You only need to the call the `setup` function if you wish to change any of the defaults.Click to see the default configuration
```lua
adapters = {
require("neotest-phpunit")({
phpunit_cmd = function()
return "vendor/bin/phpunit" -- for `dap` strategy then it must return string (table values will cause validation error)
end,
root_files = { "composer.json", "phpunit.xml", ".gitignore" },
filter_dirs = { ".git", "node_modules" },
env = {}, -- for example {XDEBUG_CONFIG = 'idekey=neotest'}
dap = nil, -- to configure `dap` strategy put single element from `dap.configurations.php`
}),
}
```### The test command
The command used to run tests can be changed via the `phpunit_cmd` option:
```lua
require("neotest-phpunit")({
phpunit_cmd = function()
return "vendor/bin/phpunit"
end
})
```### Setting the root directory
For Neotest adapters to work, they need to define a project root whereby the process of discovering tests can take place. By default, the adapter looks for a `composer.json`, `phpunit.xml` or `.gitignore` file. These can be changed with:
```lua
require("neotest-phpunit")({
root_files = { "README.md" }
})
```You can even set `root_files` with a function which returns a table:
```lua
require("neotest-phpunit")({
root_files = function() return { "README.md" } end
})
```If there are projects you don't want discovered, you can instead set `root_ignore_files` to ignore any matching projects.
For example, if your project uses Pest and the appropriate [neotest adapter](https://github.com/V13Axel/neotest-pest), you'll need to set:
```lua
require("neotest-phpunit")({
root_ignore_files = { "tests/Pest.php" }
})
```### Filtering directories
By default, the adapter will search test files in all dirs in the root with the exception of `node_modules` and `.git`. You can change this with:
```lua
require("neotest-phpunit")({
filter_dirs = { "vendor" }
})
```You can even set `filter_dirs` with a function which returns a table:
```lua
require("neotest-phpunit")({
filter_dirs = function() return { "vendor" } end
})
```### Debugging
The plugin can also be used for debugging via a dap strategy.
Firstly, install and configure [nvim-dap](https://github.com/mfussenegger/nvim-dap) with [vscode-php-debug](https://github.com/xdebug/vscode-php-debug). Then set the following dap configuration:
```lua
dap.configurations.php = {
{
log = true,
type = "php",
request = "launch",
name = "Listen for XDebug",
port = 9003,
stopOnEntry = false,
xdebugSettings = {
max_children = 512,
max_data = 1024,
max_depth = 4,
},
breakpoints = {
exception = {
Notice = false,
Warning = false,
Error = false,
Exception = false,
["*"] = false,
},
},
}
}
```Then in the plugin's config, add:
```lua
require("neotest-phpunit")({
env = {
XDEBUG_CONFIG = "idekey=neotest",
},
dap = dap.configurations.php[1],
})
```> [!NOTE]
> If you run a test with the `dap` strategy from the summary window (by default by `d`) and see that the window content has been replaced by debugger content then consider setting `dap.defaults.fallback.switchbuf = "useopen"` or Neovim level [`switchbuf`](https://neovim.io/doc/user/options.html#'switchbuf')## :rocket: Usage
#### Test single method
To test a single test, hover over the test and run `lua require("neotest").run.run()`
#### Test file
To test a file run `lua require("neotest").run.run(vim.fn.expand("%"))`
#### Test directory
To test a directory run `lua require("neotest").run.run("path/to/directory")`
#### Test suite
To test the full test suite run `lua require("neotest").run.run({ suite = true })`
## :gift: Contributing
This project is maintained by the Neovim PHP community. Please raise a PR if you are interested in adding new functionality or fixing any bugs. When submitting a bug, please include an example test that we can test against.
To trigger the tests for the adapter, run:
```sh
./scripts/test
```