Files
LazyVim-mirror/lua/lazyvim/plugins/extras/lang/php.lua
Jarryd Tilbrook 9b077c7a8e feat(lang): add neotest config for PHP tests (#5958)
## Description

Similar to some other languages (this closely follows the Go lang
extra), this adds neotest runners for the major PHP test runners:
PHPUnit and Pest.

Both work together, trying to use Pest if available and falling back to
PHPUnit which is a decent approach for the PHP ecosystem.

I read CONTRIBUTING.md which differs from the way the Go lang extra has
implemented a neotest adapters and opted to follow that instead. Ie.
adapters
have been added as dependencies instead of a separate spec with
`lazy=true`. Let me know if you want that changed.

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
2025-10-20 11:40:56 +02:00

104 lines
2.0 KiB
Lua

if lazyvim_docs then
-- LSP Server to use for PHP.
-- Set to "intelephense" to use intelephense instead of phpactor.
vim.g.lazyvim_php_lsp = "intelephense"
end
local lsp = vim.g.lazyvim_php_lsp or "phpactor"
return {
recommended = {
ft = "php",
root = { "composer.json", ".phpactor.json", ".phpactor.yml" },
},
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "php" } },
},
{
"neovim/nvim-lspconfig",
opts = {
servers = {
phpactor = {
enabled = lsp == "phpactor",
},
intelephense = {
enabled = lsp == "intelephense",
},
[lsp] = {
enabled = true,
},
},
},
},
{
"mason-org/mason.nvim",
opts = {
ensure_installed = {
"phpcs",
"php-cs-fixer",
},
},
},
{
"mfussenegger/nvim-dap",
optional = true,
opts = function()
local dap = require("dap")
dap.adapters.php = {
type = "executable",
command = "php-debug-adapter",
args = {},
}
end,
},
{
"nvimtools/none-ls.nvim",
optional = true,
opts = function(_, opts)
local nls = require("null-ls")
opts.sources = opts.sources or {}
table.insert(opts.sources, nls.builtins.formatting.phpcsfixer)
table.insert(opts.sources, nls.builtins.diagnostics.phpcs)
end,
},
{
"mfussenegger/nvim-lint",
optional = true,
opts = {
linters_by_ft = {
php = { "phpcs" },
},
},
},
{
"stevearc/conform.nvim",
optional = true,
opts = {
formatters_by_ft = {
php = { "php_cs_fixer" },
},
},
},
{
"nvim-neotest/neotest",
optional = true,
dependencies = {
"V13Axel/neotest-pest",
"olimorris/neotest-phpunit",
},
opts = {
adapters = {
"neotest-pest",
["neotest-phpunit"] = {
root_ignore_files = { "tests/Pest.php" },
},
},
},
},
}