The test file template, that is, the template based on which PhpStorm will generate the test class. Provide the parameters of the generated test: The chosen method will be automatically selected in the methods list of the Create New PHP Test dialog. To create a test for a certain method, position the caret within the method declaration. This way, you can generate a test for a PHP class defined among several classes within a single PHP file. Then, press Alt+Enter and select Create New Test from the popup menu. In the editor of the PHP class to be tested, position the caret at the definition of the class. In the Project tool window, press Alt+Insert or right-click the PHP class to be tested and choose New | PHP Test | PHPUnit Test. Then, choose PHP Test | PHPUnit Test from the context menu. Open the Create New PHP Test dialog by doing any of the following:įrom the main menu, choose File | New. Note that you can also provide an alternative configuration and bootstrap file when editing a PHPUnit run/debug configuration. Type the path manually or click and select the desired folder in the dialog that opens. In the field, specify the location of the script. You can also type the path to a bootstrap file to have a PHP script always executed before launching tests. You can appoint a custom configuration file. In the Test Runner area, appoint the configuration XML file to use for launching and executing scenarios.īy default, PHPUnit looks for a behat.yml configuration file in the project root folder or in the config folder. When you click, PhpStorm detects and displays the PHPUnit version. To use it in the current project, make sure a default PHP interpreter is defined.
For local configurations, you can download the archive by clicking the Download link. To run PHPUnit from phpunit.phar, download phpunit.phar, save the archive in the project root folder, and specify the path to it. To use Composer autoloader, specify the path to the autoload.php file in the vendor folder. In the right-hand pane, choose the PHPUnit library installation type: To use PHPUnit with a remote PHP interpreter, choose one of the configurations in the dialog that opens: In local configurations, the default project PHP interpreter is used, see Default project CLI interpreters for details. On the Test Frameworks page that opens, click in the central pane and choose the configuration type from the list: In the Settings/Preferences dialog ( Ctrl+Alt+S), go to PHP | Test Frameworks. PhpStorm will create the local framework configuration on the Test Frameworks page and the PHPUnit run/debug configuration. Store the phpunit.xml or configuration file under the project root.
In the case of remote PHP interpreters, manual PHPUnit configuration is required. If you use a local PHP interpreter, PhpStorm performs initial PHPUnit configuration automatically. Integrate PHPUnit with a PhpStorm project
Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.Ĭlick next to the package record in the composer.json editor gutter to jump to the corresponding Settings/Preferences page and configure PHPUnit manually. If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed.
Press Ctrl+Space to get code completion for the package name and version.Ĭlick the Install shortcut link on top of the editor panel.
Inside composer.json, add the phpunit/phpunit dependency record to the require or require-dev section. If you only need to run PHPUnit tests and you do not need any coding assistance, you can save phpunit.phar outside the project.ĭownload and install phpunit.phar with Composer
If you need full coding assistance in addition to the ability of running PHPUnit tests, store phpunit.phar under the root of the project where PHPUnit will be later used. Download and install phpunit.phar manuallyĭownload phpunit.phar from the PHPUnit Official website and save it on your computer: Download and install PHPUnitīefore you start, make sure Composer is installed on your machine and initialized in the current project as described in Composer dependency manager. Make sure the PHP interpreter is configured in PhpStorm on the PHP page, as described in Configure local PHP interpreters and Configure remote PHP interpreters. PhpStorm supports unit testing of PHP applications through integration with the PHPUnit testing framework.