Testing with Codeception
IntelliJ IDEA 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
- Downloading and installing Codeception
- Configuring Codeception in IntelliJ IDEA
- Initializing Codeception in project
- Creating a run configuration of the type Codeception
- Launching Tests
Before you start
- 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 Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins. Once enabled, the plugins are available at the IDE level, that is, you can use them in all your IntelliJ IDEA projects.
- Configure the PHP interpreter to use Codeception with, as described in Configuring Local PHP Interpreters and Configuring Remote PHP Interpreters.
Downloading and installing Codeception
Downloading the codeception.phar archive
codeception.pharat the Codeception Installation page.
codeception.pharunder the root of the project where Codeception will be later used. You can also save
codeception.pharanywhere else and configure it as an include path. In either case, IntelliJ IDEA will include
codeception.pharin indexing, so IntelliJ IDEA 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.
- On the main menu, choose .
In the Add Composer Dependency dialog that opens, select the
codeception/codeceptionpackage 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.
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-devsection instead of the default
-dev. For more information about Composer command line options during installation, see https://getcomposer.org/doc/03-cli.md.
- Click Install.
Configuring Codeception in IntelliJ IDEA
Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or
Expand the Languages & Frameworks node, and then
click Codeception under PHP.
The Codeception page opens.
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, click ,
choose Local, and in the Codeception Library area, specify the location of the Codeception executable file or
codeception.phararchive. For example, if you installed Codeception through the Composer dependency manager, the location is
vendor/bin/codecept. Click next to the Path to Codeception directory or phar file text box. IntelliJ IDEA detects the version of Codeception and displays it below the text box.
To use Codeception with a remote PHP interpreter, click ,
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.
In the Codeception Library area, specify the location of the Codeception executable file or
codeception.phararchive in the target environment. Click next to the Path to Codeception directory or phar file text box. IntelliJ IDEA detects the version of Codeception and displays it below the text box.
- Specify the Path Mappings between your local sources and the sources inside the Vagrant instance, or the Docker container, or on the remote host.
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, IntelliJ IDEA detects the path mappings and the container settings and fills in all the fields automatically. Alternatively, click the next to the field in question and specify the settings manually.
- In the Codeception Library area, specify the location of the Codeception executable file or
- To use Codeception with a local PHP interpreter, click , choose Local, and in the Codeception Library area, specify the location of the Codeception executable file or
In the Test Runner area,
appoint the configuration
.ymlfile to use for launching and executing scenarios.
Clear the Default configuration file check box
to have Codeception use the
codeception.ymlconfiguration 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
.ymlconfiguration 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 button and choose the file in the dialog box that opens.
- Clear the Default configuration file check box to have Codeception use the
Initializing Codeception in project
To generate a
codeception.yml configuration file,
open the built-in IntelliJ IDEA Terminal (press Alt+F12 or choose 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.pharin your project, type
php codecept.phar bootstrapfor Windows and macOS or
codecept bootstrapfor Linux.
If you installed Codeception through Composer, type
codecept bootstrapfor all platforms.
Creating a run configuration of the type Codeception
- Choose on the main menu
- In the Edit Configuration dialog box that opens, click the Add New Configuration toolbar button , and choose Codeception on the context menu.
- 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.
- On the main menu, choose and monitor test results in the Run tool window as described in Viewing and Exploring Test Results.
- On the main menu, choose and debug the tests in the Debug tool window.