diff --git a/.config/nvim/lua/plugins/neotest.lua b/.config/nvim/lua/plugins/neotest.lua index 32610d0..15c910f 100644 --- a/.config/nvim/lua/plugins/neotest.lua +++ b/.config/nvim/lua/plugins/neotest.lua @@ -7,53 +7,21 @@ return { "antoinemadec/FixCursorHold.nvim", "nvim-neotest/nvim-nio", -- Adapters - "tovijaeschke/neotest-phpunit", + "olimorris/neotest-phpunit", + "praem90/neotest-docker-phpunit.nvim", "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" + -- Container toggle state + local current_container = "app-fpm" + -- Test running keymaps keymap.set("n", "tr", function() neotest.run.run() @@ -103,58 +71,78 @@ return { 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, + -- Setup neotest function + local cwd = vim.fn.getcwd() + local app_path = cwd .. "/app/api" + local subscription_path = cwd .. "/subscription/api" + + -- Config table that we can modify + local docker_config = { + default = { + container = current_container, + volume = (current_container == "subscription-fpm" and subscription_path or app_path) .. ":/var/www", + standalone = 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, - }, - }) + } + + local function setup_neotest() + neotest.setup({ + adapters = { + require("neotest-docker-phpunit").setup({ + phpunit_cmd = "neotest-docker-phpunit", + docker_phpunit = docker_config, + }), + 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, + }, + floating = { + border = "rounded", + max_height = 0.8, + max_width = 0.9, + }, + }) + end + + -- Initial setup + setup_neotest() + + -- Container toggle keybind + keymap.set("n", "tc", function() + if current_container == "app-fpm" then + current_container = "subscription-fpm" + else + current_container = "app-fpm" + end + + -- Update the config table directly + docker_config.default.container = current_container + docker_config.default.volume = (current_container == "subscription-fpm" and subscription_path or app_path) .. ":/var/www" + + vim.notify("Switched to container: " .. current_container, vim.log.levels.INFO) + end, { desc = "Toggle container (app/subscription)" }) end, }