PHPStorm, current class testing unit

I'm trying to migrate from NetBeans to PHPStorm and I can't figure out how to do it: How to run a test suite for the current class (which ever was) without creating a run configuration for each class separately?

In NetBeans, you can run the entire package with Alt + F6, or run the current class with just F6. This allows you to run only the tests you need rather than your entire package all the time, which is obviously a time saver.

I can't figure out how to do this in PHPStorm without creating a new launch config for each class of the project, which I obviously don't want to do.

+3


source to share


2 answers


First you need to tell PHPStorm where you store your tests:

  • Settings-> Directories mark your tests folder as tests
  • Configure Options-> PHP-> PHPUnit
  • Right-click on any test in the test directory and select Run to create a test configuration for that particular test file on the fly.


You can even right click on one test method and select Run (or Debug) Same for any test folder (if you have nested test directories).

+4


source


This thread helped me a lot and I was grateful for Jakub's answer , however I had to do some additional digging, so I thought I'd try to take it a little further:

  • File> Settings> Directories

    • select any directories containing tests (possibly yourprojectroot / tests) and click "Mark as: Tests"
    • note that you can repeat this step if you have multiple directories containing tests and the selection will include sub directories, so there is no concern.
  • File> Preferences> Languages ​​and Structures> PHP

    • Make sure your php language level and CLI interpreter are configured correctly.
  • File> Preferences> Languages ​​and Frameworks> PHP> PHPUnit

    • Assuming your use of composer chooses to use the Composer autoloader and sets the path to yourprojectroot/vendor/autoload.php

    • or you can select Path to phpunit.phar and navigate to vendor/bin/phpunit

      and then check the box next to the default boot file and make the path tovendor/autoload.php

  • Open any phpunit test file in an editor and click Ctrl Shift F10to run it

    • Not sure about keybind for mac, but if you click Run> Run ... that will work too and it will tell you keybind in the submenu


Additional tips . After posting and using this feature, I learned a few more useful things and thought I'd just add them here:

  • In the project file explorer, if you select any test directory or test file and make Ctrl Shift F10it run that file or all test files in the directory.

  • Shift F10- will restart all those tests that you ran the last one, so if you are doing TDD and have previously performed a test and you are working in the class under test, you can make changes and just click Shift F10after each change and this repeats the previous test, there is no need to select a test for re-launch it.

+1


source







All Articles