Generate PHP tests

Last modified: 14 July 2022

You can have the test class stubs generated automatically based on the PHP classes that are subject for testing. PhpStorm provides this ability for the PHPUnit, Codeception, and PHPSpec test frameworks. If you are using Behat framework, you have to create tests manually.

A Test class is a PHP class with its name derived from the production class name. For example, if the class to test is MyClass.php, PhpStorm will automatically compose the name for the corresponding PHPUnit test class as <MyClass>Test.php.

PhpStorm can generate tests for the classes that are defined in separate files as well as for the classes that are defined within a single PHP file. In the latter case, for each generated test class PhpStorm will create a separate file.

After creating the test, you can quickly navigate between the test and its subject.