IntelliJ IDEA 2019.2 Help

Testing with Codeception

IntelliJ IDEA provides support for running unit, functional, and acceptance tests with the Codeception test framework, versions 2.2.0 and later.

Before you start

  1. Make sure the PHP and Codeception plugins are installed and enabled. The plugins are not bundled with IntelliJ IDEA, but they can be installed from the JetBrains plugin repository as described in Managing plugins. Once enabled, the plugins are available at the IDE level, that is, you can use them in all your IntelliJ IDEA projects.

  2. Make sure the PHP interpreter is configured in IntelliJ IDEA on the PHP page, as described in Configuring Local PHP Interpreters and Configuring Remote PHP Interpreters.

Downloading and installing 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, IntelliJ IDEA 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

  1. From the context menu of composer.json, choose Composer | Manage Dependencies. Alternatively choose Tools | Composer | Manage Dependencies from the main menu.

  2. In the Manage Composer Dependencies Dialog that opens, select the codeception/codeception package from the Available Packages list, possibly using the search field.

    Choose the relevant version from the Version to install list.

  3. If necessary, expand the Settings hidden area and specify the advanced installation options. In the Command line parameters field, type the additional command line parameters.

  4. Click Install.

Learn more about installing Codeception from Codeception Official website.

Initializing Codeception in a IntelliJ IDEA 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

Open the built-in IntelliJ IDEA Terminal Alt+F12 and at the command prompt type one of the following commands depending on the installation mode and your current operating system:

  • If you installed codeception.phar in your project, type php codecept.phar bootstrap for Windows and macOS or codecept bootstrap for Linux.

  • If you installed Codeception globally through Composer, type codecept bootstrap for all platforms.

Integrating Codeception with IntelliJ IDEA in a project

If you use a local PHP interpreter, IntelliJ IDEA performs initial Codeception configuration automatically. In the case of remote PHP interpreters, manual Codeception configuration is required.

Configure Codeception automatically

  1. Store the codeception.yml or codeception.yml.dist configuration file under the project root.

  2. Install Codeception with Composer.

IntelliJ IDEA will create the local framework configuration on the Test Frameworks page and the Codeception run/debug configuration.

Configure Codeception manually

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), expand the Languages and Frameworks node and select Test Frameworks under PHP.

    On the Test Frameworks page that opens, click Add icon 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:

  2. 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 the Reload button next to the Path to Codeception directory or phar file field. IntelliJ IDEA detects the version of Codeception and displays it below the field.

  3. In the Test Runner area, appoint the configuration YML file to use for launching and executing scenarios.

    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.

    • Select the Default configuration file checkbox to specify your own YML configuration file. This file will be later used as default in all Codeception run/debug configurations.

      In the field, specify the location of the configuration file to use. Type the path manually or click the Browse button and choose the file in the dialog that opens.

Generating a Codeception test for a class

  1. Open the Create New PHP Test dialog by doing any of the following:

    • From the main menu, choose File | New. Then, choose either PHP Test | Codeception Unit Test or PHP Test | Codeception Functional Test from the context menu.

    • 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 inside the definition of the class. Then, choose Go To | Test from the context menu or press Ctrl+Shift+T 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 Generate test methods for area of the Create New PHP Test dialog.

  2. The Create New PHP Test dialog opens.

    the Create new codeception test dialog

    Provide the parameters of the generated test:

    • The test file template, that is, the template based on which IntelliJ IDEA will generate the test class. Make sure that either Codeception Unit or Codeception Functional is selected in the Test file template list.

    • The fully qualified name of the class to be tested, this name will be used to propose the Test Class Name. By default, the Name box displays the name of the class on which the test generation was invoked. To use completion, press Ctrl+Space.

    • The name of the test class. IntelliJ IDEA 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 test class name is displayed in the Name field of the Test Class area.

    • The folder for the test class. By default, it is the folder that is marked as a test sources root. If no such folder is specified, the folder containing the production class is proposed instead.

      To specify a different folder, click the Browse button next to the Directory field and choose the relevant folder.

    • The production class methods to generate test method stubs for. In the Generate test methods for area, select the checkboxes next to the required production class methods. To include inherited methods from parent classes, select the Show inherited methods checkbox.

      IntelliJ IDEA 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.

  3. Check, accept, or update the predefined settings and click OK to initiate the test generation.

When the test is ready, you can navigate back to the production class by choosing Navigate | Go to Test Subject. For details, see Navigating between test and test subject.

Running and debugging Codeception tests

For information about writing Codeception tests, see Unit Tests, Acceptance Tests, and Functional Tests.

Run or debug Codeception tests

In the Project tool window, select the file or folder to run your tests from and choose Run '<file or folder>' or Debug '<file or folder>' from the context menu of the selection:


IntelliJ IDEA generates a default run configuration and starts a run/debug test session with it.

Save an automatically generated default configuration

After a test session is over, choose Save <default_test_configuration_name> from the context menu of the file or folder.

Run or debug tests through a previously saved run/debug configuration

Choose the required Codeception configuration from the list on the toolbar and click the Run button or the Debug button.

Create a custom run/debug configuration

  1. 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 Run | Edit Configurations from the main menu, then click Add icon and choose Codeception from the list.

  2. In the Run/Debug Configuration: Codeception dialog that opens, specify the scenarios to run and customize the behavior of the current PHP interpreter by specifying the options and arguments to be passed to the PHP executable file.

Monitoring test results

IntelliJ IDEA shows the tests execution results in the Test Runner tab of the Run Tool Window.


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.

Last modified: 20 September 2019