Hoppa till huvudinnehåll
Menu

Den här sidan använder cookies. Om du fortsätter använda sidan så accepterar du användandet av cookies. Läs mer om cookies

Jag förstår

Setup PHPStorm to run your Behat tests with a vagrant box

In order to run Behat test from PHPStorm we need to setup our IDE in a certain way because our IDE is on the host and the Behat tool is running inside our vagrant VM, so we will need to use a remote interpreter, let's see how we can do it:

Configure the PHP remote interpreter:

Go to settings/preferences and browse to Language and frameworks > PHP

Remote php interpreter

  • At CLI interpreter we may have <no interpreter> by default, so we can open the CLI interpreters dialog window from the ... icon.
  • In that dialog we can add a new interpreter clicking in the + icon.
  • In our case we can add a 'From Docker, Vagrant, VM, Remote' and we will get different options to setup the connection to the remote interpreter. Change the name of the remote interpreter and check the box 'Visible only for this project'.
  • We can use Vagrant and PHPStorm will fill all the information by default. 
  • Check the php version and all the checks that PHPStorm will do in that dialog window and click Ok.
  • We will be back in the previous window and now we will be able to select the remote interpreter that we have just created.

 

Add a new Behat configuration:

Again in settings/preferences now we can go to Language and frameworks > PHP > Behat

Remote Behat interpreter

  • Create a new Behat configuration with the + icon
  • Select the remote interpreter that we have just created
  • now we need to tell PHPStorm where the behat executable is inside the box. In our case we allocate this in /srv/www/project_name/vendor/bin/behat
  • Check that the Behat version is the right one and accept it.

Create a run configuration:

Go to the menu Run > Edit configurations

  • Add a new Behat configuration from the + icon
  • Check the settings of this test that we need to setup and we are ready to run the test.
  • Another way to create a Behat configuration is to right click on a current written test.

 

With this setup we will be able to run the Behat test from the IDE, we can use Ctrl+Click/Command+Click in the Behat steps to navigate to the functions, we can use autocomplete with the already existing steps and create new ones if it's a new step. But the most powerful of this setup is that we can use breakpoints in the php code and we can use the XDebug inside our IDE. 

Vi hjälper dig nå resultat. Kontakta oss Ring direkt på 08-20 90 04.