PhpStorm provides support for running unit, functional, and acceptance tests with the Codeception test framework, versions 2.2.0 and later.
Before you start
Download and install Codeception
Before you start, make sure Composer is installed on your machine and initialized in the current project as described in Composer dependency manager.
Download and install Codeception manually
Download codeception.phar at the Codeception Installation page and save it under the root of the project where Codeception will be later used.
You can also save codeception.phar in a different location and configure it as an include path. In either case, PhpStorm will include codeception.phar in indexing, so it will successfully resolve references to the Codeception classes and thus provide you with full coding assistance.
Download and install Codeception with Composer
Inside composer.json, add the codeception/codeception dependency record to the
require-devsection. Press Ctrl+Space to get code completion both for the package name and version.
Do one of the following:
Click the Install shortcut link on top of the editor panel.
If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.
Learn more about installing Codeception from Codeception Official website.
Initialize Codeception in a PhpStorm project
Having installed Codeception, you need to initialize it in your project by generating a codeception.yml configuration file.
Generate a codeception.yml configuration file
If you installed codeception.phar in your project, type
php codecept.phar bootstrapfor Windows and macOS or
codecept bootstrapfor Linux.
If you installed Codeception globally through Composer, type
codecept bootstrapfor all platforms.
Integrate Codeception with PhpStorm in a project
Configure Codeception automatically
Store the codeception.yml or codeception.yml.dist configuration file under the project root.
Configure Codeception manually
On the Test Frameworks page that opens, click in the central pane and choose the configuration type from the list:
In local configurations, the default project PHP interpreter is used, see Default project CLI interpreters for details.
To use Codeception with a remote PHP interpreter, choose one of the configurations in the dialog that opens:
In the Codeception Library area, specify the location of the Codeception executable file or codeception.phar archive in the target environment. For example, if you installed Codeception through Composer, the executable file is stored in vendor/bin/codecept. Click next to the Path to Codeception directory or phar file field. PhpStorm detects the version of Codeception and displays it below the field.
By default, Codeception looks for a codeception.yml configuration file in the project root folder. You can appoint a custom configuration file.
Clear the Default configuration file checkbox to have Codeception use the codeception.yml configuration file from the project root folder. If no such file is found, test execution fails, therefore it may be more reliable to specify the configuration file explicitly.
In the field, specify the location of the configuration file to use. Type the path manually or click and choose the file in the dialog that opens.
Generate a Codeception test for a class
Open the Create New PHP Test dialog by doing any of the following:
From the main menu, choose PHP Test | Codeception Unit Test or PHP Test | Codeception Functional Test from the context menu.. Then, choose either
In the Project tool window, press Alt+Insert or right-click the PHP class to be tested and choose either New | PHP Test | Codeception Unit Test or New| PHP Test | Codeception Functional Test.
In the editor of the PHP class to be tested, position the caret at the definition of the class. Then, press Alt+Enter and select Create New Test from the popup menu. This way, you can generate a test for a PHP class defined among several classes within a single PHP file.
To create a test for a certain method, position the caret within the method declaration. The chosen method will be automatically selected in the methods list of the Create New PHP Test dialog.
The Create New PHP Test dialog opens.
Provide the parameters of the generated test:
The test file template, that is, the template based on which PhpStorm will generate the test class. Make sure that either Codeception Unit or Codeception Functional is selected in the Test file template list.
The name of the test class. PhpStorm automatically composes the name from the production class name as <production class>Test.php (for Codeception Unit Test) or <production class>Cest.php (for Codeception Functional Test).
The folder for the test class file, which is automatically suggested based on the containing directory and namespace of the production class, the configured test sources root and its psr-4 package prefix, or the
testsvalue specified in the codeception.yml configuration file.
To specify a different folder, click next to the Directory field and choose the relevant folder.
The namespace the test class will belong to, which is automatically suggested based on the containing directory and namespace of the production class, the configured test sources root and its psr-4 package prefix, or the
namespacevalue specified in the codeception.yml configuration file.
The production class methods to generate test method stubs for. Select the checkboxes next to the required production class methods. To include inherited methods from parent classes, select the Show inherited methods checkbox.
PhpStorm will automatically compose the test methods' names as
test<production method>. You can customize the code templates used for generating test method stubs on the Code tab of the File and Code Templates settings page.
After the test is created, you can navigate back to the production class by choosing Navigate | Go to Test Subject. For details, see Navigate between test and test subject.
Run and debug Codeception tests
Run or debug Codeception tests
Save an automatically generated default configuration
Run or debug tests through a previously saved run/debug configuration
Create a custom run/debug configuration
In the Project tool window, select the file or folder with the tests to run and choose Create run configuration from the context menu. Alternatively, choose from the main menu, then click and choose Codeception from the list.
In the Run/Debug Configuration: Codeception dialog that opens, specify the scenarios to run, choose the PHP interpreter to use, and customize its behavior by specifying the options and arguments to be passed to the PHP executable.
Monitor test results
The tab is divided into 2 main areas:
The left-hand area lets you drill down through all unit tests to see the succeeded and failed ones. You can filter tests, export results, and use the context menu commands to run specific tests or navigate to the source code.
The right-hand area displays the raw Codeception output.