aboutsummaryrefslogtreecommitdiffstats
path: root/lua/plugins/test.lua
blob: fd1f9bc8037a3891e41e16872ba79371f2ef5778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
return {
  "vim-test/vim-test",
  keys = { { "<leader>t", desc = "Open Test menu" } },
  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 behat_paths = {
      "tests/Functional/Context/**/*.php",
      "tests/Behat/Context/*.php",
      "tests/Behat/**/*.php",
      "src/Behat/**/*.php",
    }

    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"

        -- 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

    require "alpha.test_menu"
  end,
}