return { "nvim-neotest/neotest", event = "VeryLazy", dependencies = { "nvim-lua/plenary.nvim", "nvim-treesitter/nvim-treesitter", "antoinemadec/FixCursorHold.nvim", "nvim-neotest/nvim-nio", -- Adapters "tovijaeschke/neotest-phpunit", "nvim-neotest/neotest-go", }, config = function() local neotest = require("neotest") local keymap = vim.keymap -- Docker service management for PHP tests local current_service = "app-fpm" local phpunit_adapter = nil local function get_phpunit_cmd(service) service = service or current_service return { "docker", "compose", "exec", service, "./vendor/bin/phpunit" } end local function switch_service() local services = { "app-fpm", "fpm", "subscription-fpm" } vim.ui.select(services, { prompt = "Select Docker service for PHPUnit:", format_item = function(item) return item .. (item == current_service and " (current)" or "") end, }, function(choice) if choice then current_service = choice vim.notify("PHPUnit service switched to: " .. choice, vim.log.levels.INFO) -- Recreate the adapter with new service phpunit_adapter = require("neotest-phpunit")({ root_files = { "phpunit.xml", "composer.json" }, phpunit_cmd = get_phpunit_cmd(choice), filter_dirs = { "vendor" }, mapped_docker_dir = "/var/www", append_to_cwd = "/api", }) -- Reinitialize neotest with the new adapter vim.notify("Restart Neovim for service change to take full effect", vim.log.levels.WARN) end end) end -- Environment setup vim.env.PROJECT_ROOT = vim.fn.getcwd() .. "/backend/" vim.env.ENV_PATH = vim.fn.getcwd() .. "/backend/.env" -- Test running keymaps keymap.set("n", "tr", function() neotest.run.run() end, { desc = "Run nearest test" }) keymap.set("n", "tf", function() neotest.run.run(vim.fn.expand("%")) end, { desc = "Run all tests in file" }) keymap.set("n", "tR", function() neotest.run.run_last() end, { desc = "Run last test" }) keymap.set("n", "tS", function() neotest.run.stop() end, { desc = "Stop running tests" }) keymap.set("n", "ta", function() neotest.run.attach() end, { desc = "Attach to running test" }) -- Watch mode keymap.set("n", "tw", function() neotest.watch.toggle(vim.fn.expand("%")) end, { desc = "Toggle watch mode for file" }) -- Output keymaps keymap.set("n", "to", function() neotest.output.open({ enter = true, short = false }) end, { desc = "Open test output" }) keymap.set("n", "tO", function() neotest.output_panel.toggle() end, { desc = "Toggle output panel" }) -- UI keymaps keymap.set("n", "ts", function() neotest.summary.toggle() end, { desc = "Toggle summary pane" }) -- Navigation keymaps keymap.set("n", "[t", function() neotest.jump.prev({ status = "failed" }) end, { desc = "Jump to previous failed test" }) keymap.set("n", "]t", function() neotest.jump.next({ status = "failed" }) end, { desc = "Jump to next failed test" }) -- Service switching keymap keymap.set("n", "tc", switch_service, { desc = "Change PHPUnit docker service" }) -- Setup neotest neotest.setup({ adapters = { require("neotest-phpunit")({ root_files = { "phpunit.xml", "composer.json" }, phpunit_cmd = get_phpunit_cmd(), filter_dirs = { "vendor" }, mapped_docker_dir = "/var/www", append_to_cwd = "/api", }), require("neotest-go")({ root = function() return './backend' end, experimental = { test_table = true, }, args = { "-count=1", "-timeout=60s" }, }), }, output = { enabled = true, open_on_run = false, }, output_panel = { enabled = true, open = "botright split | resize 15", }, quickfix = { enabled = true, open = false, }, status = { enabled = true, virtual_text = true, signs = true, }, icons = { passed = "", running = "", failed = "", unknown = "", skipped = "", }, floating = { border = "rounded", max_height = 0.8, max_width = 0.9, }, }) end, }