PhpStorm 2016.3 Help

Using PHPSpec

With PhpStorm, you can practice behaviour-driven development by running specifications using the PHPSpec toolset.

On this page:

Before you start

  1. Make sure the PHP and PHPSpec 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. Make sure the PHP interpreter is configured in PhpStorm on the PHP page, as described in Enabling PHP Support.
  3. Configure the PHP interpreter to use PHPSpec with, as described Configuring Remote PHP Interpreters.

Installing PHPSpec 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 phpspec/phpspec 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 https://getcomposer.org/doc/03-cli.md.
  4. Click Install.

Configuring PHPSpec 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 OS X. Expand the Languages&Frameworks node, and then click PHPSpec under PHP.
  2. On the PHPSpec that opens, specify the location of the PHPSpec executable file and the PHP interpreter to use PHPSpec 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 PHPSpec installations. The list contains at least one item (Local) which cannot be removed. To use PHPSpec with a local PHP interpreter:

    1. Choose Local in the central pane.
    2. In the PHPSpec Library area, specify the PHPSpec installation to use.
      • In the Path to PHPSpec executable text box, specify the location of phpspec. PHPSpec does not necessarily have to be installed under the current project root. You can type the path manually or click the /help/img/idea/2016.3/browseButton.png button and choose the relevant location in the dialog box that opens.

        If no path to PHPSpec is specified for a Local interpreter, PhpStorm does not provide full support of PHPSpec, for example, it does not show suggestion for code completion and does not resolve ??? references.

      • The Prefix ('spec_prefix'): read-only field shows the namespace prefix for specifications. PhpStorm detects spec_prefix from the configuration file specified in the Default Configuration File field. The default value is spec. See PHPSpec Configuration: PSR-4 and PHPSpec Configuration: Spec and Source Location for details.

    To use PHPSpec with a remote PHP interpreter, click the Add toolbar button /help/img/idea/2016.3/new.png in the central pane and do one of the following depending on your workflow:

    • To use PHPSpec in a Vagrant environment:
      1. In the PHPSpec by Remote Interpreter dialog box, choose the desired PHP interpreter configuration in a Vagrant environment. When you click OK, PhpStorm returns to the PHPSpec page.

        PhpStorm displays the appointed PHP interpreter configuration in the CLI Interpreter field. The field is read-only, to update the chosen interpreter configuration or create a new one, click the /help/img/idea/2016.3/browseButton.png whereupon PhpStorm brings you to the Interpreters dialog box.

      2. In the PHPSpec Library area, specify the PHPSpec installation to use.

        In the Path to PHPSpec executable text box, specify the location of phpspec. PHPSpec does not necessarily have to be installed under the current project root. You can type the path manually or click the /help/img/idea/2016.3/browseButton.png button and choose the relevant location in the dialog box that opens.

    • To use PHPSpec on a remote host with SSH access:
      1. In the PHPSpec by Remote Interpreter dialog box, choose the desired PHP interpreter configuration on a remote host. When you click OK, PhpStorm returns to the PHPSpec page.

        PhpStorm displays the appointed PHP interpreter configuration in the CLI Interpreter field. The field is read-only, to update the chosen interpreter configuration or create a new one, click the /help/img/idea/2016.3/browseButton.png whereupon PhpStorm brings you to the Interpreters dialog box.

      2. In the PHPSpec Library area, specify the PHPSpec installation to use.

        In the Path to PHPSpec executable text box, specify the location of phpspec. PHPSpec does not necessarily have to be installed under the current project root. You can type the path manually or click the /help/img/idea/2016.3/browseButton.png button and choose the relevant location in the dialog box that opens.

    • To use PHPSpec in a Docker container:
      1. In the PHPSpec by Remote Interpreter dialog box, choose the desired PHP interpreter configuration in a Docker container. When you click OK, PhpStorm returns to the PHPSpec page.

        PhpStorm displays the appointed PHP interpreter configuration in the CLI Interpreter field. The field is read-only, to update the chosen interpreter configuration or create a new one, click the /help/img/idea/2016.3/browseButton.png whereupon PhpStorm brings you to the Interpreters dialog box.

      2. In the PHPSpec Library area, specify the PHPSpec installation to use.

        In the Path to PHPSpec executable text box, specify the location of phpspec. PHPSpec does not necessarily have to be installed under the current project root. You can type the path manually or click the /help/img/idea/2016.3/browseButton.png button and choose the relevant location in the dialog box that opens.

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

    By default, PHPSpec looks for a phpspec.yml or a phpspec.yml.dist configuration file in the project root folder. You can appoint a custom configuration file.

    • Clear the Default configuration file check box to have PHPSpec use the phpspec.yml or phpspec.yml.distconfiguration 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 PHPSpec 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/2016.3/browseButton.png button and choose the file in the dialog box that opens.

Creating a run configuration of the type PHPSpec

  1. Choose Run | Edit Configuration on the main menu. Alternatively, click Shift+Alt+F10 and select Edit Configuration from the pop-up menu.
  2. In the Edit Configuration dialog box that opens, click the Add New Configuration toolbar button add.png, and choose PHPSpec on the context menu.
  3. In the Run/Debug Configuration: PHPSpec dialog box, specify the specifications 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 PHPSpec specifications, see http://www.phpspec.net/en/stable/manual/getting-started.html#specifying-behaviour. To run or debug your tests, do one of the following:

See Also

Last modified: 1 December 2016