aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriel D'Alessandro <dalessandro.ariel@gmail.com>2023-09-01 11:33:10 +0200
committerAriel D'Alessandro <dalessandro.ariel@gmail.com>2023-09-01 11:33:10 +0200
commitf4fe416201cc9d1cba5dfa3fec0879601fb85ae7 (patch)
treed5660de66768722b327999fd894f1e1ba2a8649b
parent72c8f0deb1e8b3f069076a317d1f2d8abd97fae4 (diff)
downloadnvim-conf-f4fe416201cc9d1cba5dfa3fec0879601fb85ae7.tar.gz
nvim-conf-f4fe416201cc9d1cba5dfa3fec0879601fb85ae7.zip
refactor my tests to be more automatic and do not depend on project config
-rw-r--r--lazy-lock.json6
-rw-r--r--lua/alpha/test_menu.lua48
-rw-r--r--lua/plugins/project-config.lua1
-rw-r--r--lua/plugins/test.lua90
4 files changed, 92 insertions, 53 deletions
diff --git a/lazy-lock.json b/lazy-lock.json
index 0d552dc..94729af 100644
--- a/lazy-lock.json
+++ b/lazy-lock.json
@@ -14,6 +14,7 @@
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
"color-picker.nvim": { "branch": "master", "commit": "06cb5f853535dea529a523e9a0e8884cdf9eba4d" },
+ "composer.nvim": { "branch": "main", "commit": "ec9537969adc7fc128cfe9c3a9925850455896c8" },
"copilot-cmp": { "branch": "master", "commit": "11eb015fbf9f07ad1c72dbdc9d830ebac610b5cd" },
"copilot.lua": { "branch": "master", "commit": "0fa30d6846aae1af1c94a9ead93fa7dcf8affbe6" },
"dressing.nvim": { "branch": "master", "commit": "c7b035de7f91bb6b62b4308f105c56d1a968b8c5" },
@@ -26,6 +27,7 @@
"icon-picker.nvim": { "branch": "master", "commit": "e6dca182518eeb7a51470c13605a5bce08a816e4" },
"image.nvim": { "branch": "main", "commit": "dcabdf47b0b974b61d08eeafa2c519927e37cf27" },
"indent-blankline.nvim": { "branch": "master", "commit": "9637670896b68805430e2f72cf5d16be5b97a22a" },
+ "laravel.nvim": { "branch": "main", "commit": "8f8a0eab84191b1867b2f188cf475e6a05203908" },
"lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" },
"lspkind-nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" },
"lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" },
@@ -53,9 +55,11 @@
"nvim-projectconfig": { "branch": "master", "commit": "05fd34831e170db269d1b84597615bcdcdde930e" },
"nvim-spectre": { "branch": "master", "commit": "411cee67fe3f8242023eb8d9edafefbbfb2d06f1" },
"nvim-transparent": { "branch": "main", "commit": "4cf97fc0b1c4a88cf246b2f6facb735a536a558e" },
- "nvim-treesitter": { "branch": "master", "commit": "920b37260ebc720b0399bd12954fd2bf8bd18242" },
+ "nvim-treesitter": { "branch": "master", "commit": "4a9adef71061a883c81f79862ee1f4bf100a2ddd" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "bd103502252027434ec42f628d2dbf54821d4ce6" },
"nvim-web-devicons": { "branch": "master", "commit": "cfc8824cc1db316a276b36517f093baccb8e799a" },
+ "php-code-actions.nvim": { "branch": "main", "commit": "31831cb7c3227ac00ddc7590b31f11148ff4a81c" },
+ "phpactor.nvim": { "branch": "main", "commit": "0aa4ad09c2024e24d630c0ec616d65396caa39e0" },
"playground": { "branch": "master", "commit": "429f3e76cbb1c59fe000b690f7a5bea617b890c0" },
"plenary.nvim": { "branch": "master", "commit": "0dbe561ae023f02c2fb772b879e905055b939ce3" },
"popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" },
diff --git a/lua/alpha/test_menu.lua b/lua/alpha/test_menu.lua
new file mode 100644
index 0000000..5b3e5a5
--- /dev/null
+++ b/lua/alpha/test_menu.lua
@@ -0,0 +1,48 @@
+local hydra = require "hydra"
+
+local hint = [[
+ Vim Tests
+ _n_: Near test _f_: Current file _s_: Test Suit ^
+ _l_: Test Last _g_: Visit
+ _w_: Watch last Test _p_: stop watch
+ ^ ^ _<Esc>_ ^
+]]
+local auto_cmd_id = nil
+local stopAutoCommand = function()
+ if auto_cmd_id ~= nil then
+ vim.api.nvim_del_autocmd(auto_cmd_id)
+ auto_cmd_id = nil
+ end
+end
+local startAutoCommand = function()
+ stopAutoCommand()
+ auto_cmd_id = vim.api.nvim_create_autocmd({ "BufWritePost" }, {
+ pattern = { "*.php", "*.feature", "*.yaml" },
+ command = "TestLast",
+ })
+end
+
+hydra {
+ name = "vimtest",
+ hint = hint,
+ mode = "n",
+ config = {
+ color = "teal",
+ invoke_on_body = true,
+ hint = {
+ border = "rounded",
+ position = "bottom",
+ },
+ },
+ body = "<leader>t",
+ heads = {
+ { "n", ":TestNearest<CR>" },
+ { "f", ":TestFile<CR>" },
+ { "s", ":TestSuit<CR>" },
+ { "l", ":TestLast<CR>" },
+ { "g", ":TestVisit<CR>" },
+ { "w", startAutoCommand },
+ { "p", stopAutoCommand },
+ { "<Esc>", nil, { exit = true } },
+ },
+}
diff --git a/lua/plugins/project-config.lua b/lua/plugins/project-config.lua
index 3af9a68..393b849 100644
--- a/lua/plugins/project-config.lua
+++ b/lua/plugins/project-config.lua
@@ -1,4 +1,5 @@
return {
"windwp/nvim-projectconfig",
+ disable = true,
config = true,
}
diff --git a/lua/plugins/test.lua b/lua/plugins/test.lua
index a9d7baa..fd1f9bc 100644
--- a/lua/plugins/test.lua
+++ b/lua/plugins/test.lua
@@ -4,63 +4,49 @@ return {
dependencies = {
"anuvyklack/hydra.nvim",
},
+ init = function()
+ vim.g["test#strategy"] = "harpoon"
+ vim.g["test#neovim#term_position"] = "vert"
+ vim.g["test#harpoon_term"] = 1
+ vim.g["test#preserve_screen"] = 0
+ vim.g["test#harpoon#gototerminal"] = 0
+ vim.g["test#php#pest#executable"] = "./vendor/bin/sail test"
+
+ local function dockerComposeTransform(cmd)
+ local uid = vim.fn.system("id -u"):gsub("%s*$", "")
+ local gid = vim.fn.system("id -g"):gsub("%s*$", "")
+ return string.format("docker compose exec -u %s:%s php-fpm %s", uid, gid, cmd)
+ end
+
+ vim.g["test#php#behat#executable"] = "bin/behat --colors"
+ vim.g["test#custom_transformations"] = { docker = dockerComposeTransform }
+ end,
config = function()
- local hydra = require "hydra"
+ local behat_paths = {
+ "tests/Functional/Context/**/*.php",
+ "tests/Behat/Context/*.php",
+ "tests/Behat/**/*.php",
+ "src/Behat/**/*.php",
+ }
- vim.cmd [[
- let test#php#pest#executable = './vendor/bin/sail test'
- let test#strategy = 'harpoon'
- let test#neovim#term_position = 'vert'
- let g:test#preserve_screen = 0
- let g:test#harpoon_term = 1
- let g:test#harpoon#gototerminal= 0
-]]
+ for _, path in ipairs(behat_paths) do
+ if vim.fn.glob(path) ~= "" then
+ vim.g["test#php#behat#bootstrap_directory"] = path
+ vim.g["test#transformation"] = "docker"
- local hint = [[
- Vim Tests
- _n_: Near test _f_: Current file _s_: Test Suit ^
- _l_: Test Last _g_: Visit
- _w_: Watch last Test _p_: stop watch
- ^ ^ _<Esc>_ ^
-]]
- local auto_cmd_id = nil
- local stopAutoCommand = function()
- if auto_cmd_id ~= nil then
- vim.api.nvim_del_autocmd(auto_cmd_id)
- auto_cmd_id = nil
+ -- many of my projects have variables necessaries so this is required
+ local env_vars = vim.fn.system "make vars"
+ for _, env_var in ipairs(vim.split(env_vars, "\n")) do
+ if env_var ~= "" then
+ env_var = env_var:gsub("^export ", "")
+ local key, value = unpack(vim.split(env_var, "="))
+ vim.fn.setenv(key, value)
+ end
+ end
+ break
end
end
- local startAutoCommand = function()
- stopAutoCommand()
- auto_cmd_id = vim.api.nvim_create_autocmd({"BufWritePost"}, {
- pattern = {"*.php", "*.feature", "*.yaml"},
- command = "TestLast",
- })
- end
- hydra {
- name = "vimtest",
- hint = hint,
- mode = "n",
- config = {
- color = "teal",
- invoke_on_body = true,
- hint = {
- border = "rounded",
- position = "bottom",
- },
- },
- body = "<leader>t",
- heads = {
- { "n", ":TestNearest<CR>" },
- { "f", ":TestFile<CR>" },
- { "s", ":TestSuit<CR>" },
- { "l", ":TestLast<CR>" },
- { "g", ":TestVisit<CR>" },
- { "w", startAutoCommand },
- { "p", stopAutoCommand },
- { "<Esc>", nil, { exit = true } },
- },
- }
+ require "alpha.test_menu"
end,
}