Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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

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

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:

share|improve this answer

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

You must log in to answer this question.

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