Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

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

share|improve this answer
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.