Autorun PHPUnit Tests in PhpStorm 2017.2

In recent versions of PhpStorm we’ve tried to make improving the testing experience a priority, and in 2017.2 we’ve done just that by introducing the ability to automatically run PHPUnit tests when you stop editing.

The ability to autorun tests has been a hot topic of discussion on Twitter and at conferences and user groups for a long time. There’s been a workaround using file-watchers for a while, but PhpStorm 2017.2 brings you the ability to autorun tests after you’ve stopped editing files integrated into the test runner.

To start your tests automatically running, run your tests, as usual, (using a run configuration – you can find more information in this video), and then turn on auto-testing by using the Toggle auto-test button.

phpunit-auto-toggle

This turns on autorunning of tests 3 seconds after you stop editing any file (excluding scratch files). You can change the time it takes for the autorun to fire using the Set AutoTest Delay menu you can find in the More options (cog) menu.

phpunit-test-delay

It’s also worth mentioning that we’ve unified the place you configure your test frameworks, be that PHPUnit, PhpSpec, Behat or Codeception. If you want to create a configuration for a test framework you’ll now find them all under Languages & Frameworks | PHP | Test Frameworks rather than in their own individual settings section. You still create each configuration in the same way as before, however.

We hope you enjoy this new feature, I’m already using this in some of my open source work and it’s really useful – give it a try and let me know what you think.

– Gary & The PhpStorm Team

About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature, Newsletter and tagged . Bookmark the permalink.
  • michabbb

    dear gary, is it possible to run these tests remotly ? (inside a docker container?)

    • GeeH

      Hi – Yes, it works regardless of which interpreter you are using (Local, Vagrant, Docker – other remote).

      • michabbb

        sorry, i want to be 100% sure: so for example, does this work?

        – phpstorm: windows (local)
        – linux system running inside vmware (windows, same pc)
        – run phpunit via ssh with a custom command (because of docker)

        thanks

        • Eugene Morozov

          What does this “custom command” look like?
          And how do you mount sources to the container?

          • michabbb

            in my case it is something like this:

            `docker run –rm -it –name php -w /home/myproject php-fpm vendor/phpunit/phpunit/phpunit tests/`

            and the question is, if this command is working with this new auto-phpunit feature via ssh…..

  • Andrea Sciamanna

    I probably don’t need to ask that, but will it be included in IntelliJ as well?

    • Anna Lebedeva

      yes, of course

  • Dragoș Ardeleanu

    Is there any way to configure PhpStorm to use the interpreter from a docker box inside a vagrant box?

  • Jiří

    Is it possible to rerun a Codeception (unit) tests that way? Its only missing the ‘Set AutoTest Delay’ item in the menu …

    • Eugene Morozov
      • Jiří

        I don’t think the linked feature request is the same thing.
        I have a set of unit tests in Codeception (PhpUnit envelope) and I want to run them automatically 3 seconds after I edit the file – the same behavior which is in the article with PhpUnit, while the linked issue is about reruning a failed tests. I can do that with ctrl + R (rerun the last tests), but I dont want to always press that, I want it to do it automatically.
        Menu options are the same, only the final “Set AutoDelay” is missing.
        From your answer I see it is not supported, should I open a new feature request?