PhpStorm 2017.1 Help

Testing with Codeception

PhpStorm provides support for running unit, functional, and aceptance tests with the Codeception test framework, versions 2.2.0 and higher.

On this page:

Before you start

  1. Make sure the PHP and Codeception plugins are installed and enabled. The plugins are bundled with PhpStorm and activated by default. If the plugins are not activated, enable them on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.
  2. Configure the PHP interpreter to use Codeception with, as described in Configuring Local PHP Interpreters and Configuring Remote PHP Interpreters.

Downloading and installing Codeception

You can acquire Codeception in the following ways:

  • Download the codeception.phar archive.
  • Use the Composer dependency manager.

Downloading the codeception.phar archive

  1. Download codeception.phar at the Codeception Installation page.
  2. Save codeception.phar under the root of the project where Codeception will be later used. You can also save codeception.phar anywhere else and configure it as an include path. In either case, PhpStorm will include codeception.phar in indexing, so PhpStorm will successfully resolve references to Codeception classes and thus provide you with full coding assistance.

Installing Codeception using the Composer dependency manager

Before you start, make sure Composer is installed on your machine and initialized in the current project, see Using Composer Dependency Manager.

  1. On the main menu, choose Tools | Composer | Add Dependency.
  2. In the Add Composer Dependency dialog that opens, select the codeception/codeception package from the Available Packages list, possibly using the search field. The list shows all the available packages, however, the packages that have been already installed are marked with a tick.
    Choose the relevant version from the Version to install drop-down list.
  3. If necessary, expand the Settings hidden area and specify the advanced installation options. In the Command line parameters text box, type the additional command line parameters to adjust the add dependency procedure. For example, to have the package added to the require-dev section instead of the default require section type -dev. For more information about Composer command line options during installation, see
  4. Click Install.

Configuring Codeception in PhpStorm

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for macOS. Expand the Languages & Frameworks node, and then click Codeception under PHP.
    The Codeception page opens.
  2. In the central pane, choose the PHP interpreter to use Codeception with. This PHP interpreter can be installed either locally, or in a Vagrant virtual environment, or on a remote host, or in a Docker container. For information on configuring PHP interpreters, see Configuring Local PHP Interpreters and Configuring Remote PHP Interpreters. The central pane of the page shows a list of configured PHP interpreters that are associated with Codeception installations. The list contains at least one item (Local) which cannot be removed. The contents of the right-hand pane depend on the type of the selected interpreter.
    • To use Codeception with a local PHP interpreter, choose Local in the central pane, and in the Codeception Library area, specify the location of the Codeception executable file or codeception.phar archive. For example, if you installed Codeception through the Composer dependency manager, the location is vendor/bin/codecept. Click /help/img/idea/2017.1/refresh.png next to the Path to Codeception directory or phar file text box. PhpStorm detects the version of Codeception and displays it below the text box.
    • To use Codeception with a remote PHP interpreter, click /help/img/idea/2017.1/new.png, and from the Codeception by Remote Interpreter dialog box choose the PHP interpreter configuration in a Vagrant environment, in a Docker container, or on a remote host with SSH access.
      1. In the Codeception Library area, specify the location of the Codeception executable file or codeception.phar archive in the target environment. Click /help/img/idea/2017.1/refresh.png next to the Path to Codeception directory or phar file text box. PhpStorm detects the version of Codeception and displays it below the text box.
      2. Specify the Path Mappings between your local sources and the sources inside the Vagrant instance, or the Docker container, or on the remote host.
      3. If the selected interpreter runs in a Docker container, specify the Docker container settings that will be used to start the container from an image. These settings may include the volume configuration, the exposed port, the network, etc.
        In most cases, PhpStorm detects the path mappings and the container settings and fills in all the fields automatically. Alternatively, click the /help/img/idea/2017.1/browseButton.png next to the field in question and specify the settings manually.
  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 check box 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 check box to specify your own .yml configuration file. This file will be later used as default in all Codeception run/debug configurations.

      In the text box, specify the location of the configuration file to use. Type the path manually or click the /help/img/idea/2017.1/browseButton.png button and choose the file in the dialog box that opens.

Initializing Codeception in project

To generate a codeception.yml configuration file, open the built-in PhpStorm Terminal (press Alt+F12 or choose View | Tool Windows | Terminal on the main menu) and at the command line 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 through Composer, type codecept bootstrap for all platforms.

Creating a run configuration of the type Codeception

  1. Choose Run | Edit Configuration on the main menu
  2. In the Edit Configuration dialog box that opens, click the Add New Configuration toolbar button add.png, and choose Codeception on the context menu.
  3. In the Run/Debug Configuration: Codeception dialog box, specify the tests 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.

Launching Tests

For information about writing Codeception tests, see Unit Tests, Acceptance Tests, and Functional Tests. To run or debug your tests, do one of the following:

See Also

Last modified: 19 July 2017