3

Is there an easy way to run phpunit on open php test file inside vim?

3 Answers 3

2

I don’t know PHPUnit’s call syntax by heart, but probably something like :!phpunit % may help.

2

I personally like to set up a key mapping for running different tools. My mapping for PHPUnit looks like this (added to ~/.vim/ftplugin/php.vim, accessible at https://github.com/archwisp/linux-home/blob/master/.vim/ftplugin/php.vim):

nnoremap ,u :!./bin/runtests %<CR>

Thus, when editing a unit test file, I just press, ",u" and the runtests script specific to the project is executed with the current file name as an argument. I create a runtests script for each project because each project is set up differently and this allows me to use the same key mapping for each project. The other added benefit is that this script can be run from the command-line or by a continuous integration package.

An example runtests script can be seen here: https://github.com/archwisp/MindFrame2/blob/master/bin/runtests

0

I don’t know PHPUnit either, however, I'd have set &makeprg to phpunit, and then called make on %:

:set makeprg=phpunit
:make %

and then navigate among the failed assertions with :copen, :cc, :cn, :cp (:h quickfix) -- assuming phpunit failed assertions are compatible with the usual error format: "file:line:error message", otherwise some tuning on &efm would be necessary.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .