Giter Club home page Giter Club logo

vim-phpunitqf's Introduction

PHPUnit runner for Vim

PHPUnitQf is a plugin for Vim that allows you to run PHPUnit tests easily from the Vim window. It then reads the output and puts the errors into the quickfix list, so you can easily jump to them. It's configurable too, so if you use a PHPUnit wrapper command or have a special set of arguments, then that's no problem.

How to use

In a Vim window, run:

:Test <args>

Where <args> are passed directly to the PHPUnit command. To set up a custom PHPUnit command see the configuration section below. You can also set default arguments which will always be passed.

Installation

Installation is easy-peasy if you're using Vundle. Just add this to your .vimrc file:

Bundle 'joonty/vim-phpunitqf.git'

and run vim +BundleInstall +qall from a terminal.

If you aren't using vundle, you will have to extract the files in each folder to the correct folder in .vim/.

Note: your vim installation must be compiled with python for this plugin to work.

Configuration

By default, the command used to run PHPUnit is phpunit, but you can change it in your vimrc file with:

let g:phpunit_cmd = "/usr/bin/mytest"

To pass arguments to the command, use:

let g:phpunit_args = "--configuration /path/to/config"

You can also specify arguments to be placed after the "dynamic" argument (the argument passed when running from within Vim):

let g:phpunit_args_append = "--repeat"

The output is written to a temporary file. You can change the location of this (default value is /tmp/vim_phpunit.out) with:

let g:phpunit_tmpfile = "/my/new/tmp/file"

Callback for modifying arguments

You can do some more in-depth argument handling when running tests, with callback functions. You can define a callback function and tell PHPUnitQf to use that function to parse and potentially modify the arguments passed to PHPUnit when running :Test. The callback function takes the arguments as it's parameter, and returns the modified arguments. Think of it as a filter for your test arguments. You can tell PHPUnitQf to use the callback with:

let g:phpunit_callback = "MyCallbackFunction"

A callback function looks like this:

function! MyCallbackFunction(args)
    let l:args = a:args
    " Do something with the arguments
    return l:args
endfunction

For example, let's say I want :Test on it's own (no arguments) to try and find and run a test case for the current file. I would write a callback that accepts the arguments to PHPUnit, and tries to work out a test case from the current filename if the arguments are empty. Here's one that I use that works for CakePHP (I won't explain it, see if you can understand it :D):

" Let PHPUnitQf use the callback function
let g:phpunit_callback = "CakePHPTestCallback"

function! CakePHPTestCallback(args)
    " Trim white space
    let l:args = substitute(a:args, '^\s*\(.\{-}\)\s*$', '\1', '')

    " If no arguments are passed to :Test
    if len(l:args) is 0
        let l:file = expand('%')
        if l:file =~ "^app/Test/Case.*"
            " If the current file is a unit test
            let l:args = substitute(l:file,'^app/Test/Case/\(.\{-}\)Test\.php$','\1','')
        else
            " Otherwise try and run the test for this file
            let l:args = substitute(l:file,'^app/\(.\{-}\)\.php$','\1','')
        endif
    endif
    return l:args
endfunction

License

This plugin is released under the MIT License.

vim-phpunitqf's People

Contributors

joonty avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.