You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

66 lines
1.6 KiB

local M = require('module'):new()
function M:initialize()
self.keymap = nukevim.modules:get('keymap')
end
function M:register()
self.keymap:add({
filetype = 'php',
mode = 'n',
key = { '<leader>', 'l', 'p' },
group = true,
label = 'phpunit'
})
self.keymap:add({
filetype = 'php',
mode = 'n',
key = { '<leader>', 'l', 'p', 'a' },
map = ':lua nukevim.modules:get("phpunit"):all()<CR>',
label = 'run all'
})
self.keymap:add({
filetype = 'php',
mode = 'n',
key = { '<leader>', 'l', 'p', 'f' },
map = ':lua nukevim.modules:get("phpunit"):file()<CR>',
label = 'run file'
})
self.keymap:add({
filetype = 'php',
mode = 'n',
key = { '<leader>', 'l', 'p', 't' },
map = ':lua nukevim.modules:get("phpunit"):test()<CR>',
label = 'run single test'
})
end
function M:run()
vim.g.asyncrun_open = 8
end
function M:all()
vim.call('asyncrun#run', '', {}, './vendor/bin/phpunit --colors=never')
end
function M:file()
file = vim.fn.expand('%')
vim.call('asyncrun#run', '', {}, './vendor/bin/phpunit --colors=never '..file)
end
function M:test()
-- so... this tries to get the current tag in the which-key window which is
-- always blank. there's probably a smarter way to do this, but we just...
-- wait a half second then do it.
vim.defer_fn(function()
file = vim.fn.expand('%')
test = vim.fn['tagbar#currenttag']('%s', 'nil')
if (test == 'nil') then
print('cannot find test function')
return
end
vim.call('asyncrun#run', '', {}, './vendor/bin/phpunit --colors=never --filter '..test..' '..file)
end, 500)
end
return M