<-- home

# A smart way of testing inside Vim

Most of my developing time I pass on the test suite. More than that, I spend the majority of time in a specific test file or even a single test function. Given that, any effort made to simplify this process is a good one. In this mood I’ll present my method of testing while developing inside Vim.

The following function wraps PHPunit’s and allows me to run tests from inside vim and other goodies that I’ll describe below.

function! RunPHPUnitTest(filter)
cd %:p:h
if a:filter

normal! T yw
if @" =~ "^test*"
normal! mT
endif

normal! T

normal! T yw
"
let myCommand="phpunit -c ". $PWD ."/Backend/phpunit.xml.dist \ --filter " . @" . " " . expand("%:p") let result = system(myCommand) else let @n = expand('%:t') if @n =~ "Test" normal! mA endif normal! A let myCommand = "phpunit -c ".$PWD . "/Backend/phpunit.xml.dist \
" . expand("%:p")
let result = system(myCommand)
endif
split __PHPUnit_Result__
normal! ggdG
setlocal buftype=nofile
call append(0, myCommand)
call append(0, split(result, '\v\n'))
cd -
endfunction

With the following maps: