Phpstorm Magento 2



Plugin

Table of Contents

Introduction

The easy answer is 'not', out of the box magento2 just have some defined factories like CatalogPriceFactory (which have sense since are auto-generated) however you can add var/generation as source folder. Personally I don't like to use it that way because you'll find some class definitions twice. Magento PhpStorm - Official Magento PhpStorm plugin for Magento 2 MaGinto - Plugin, created to improve life-work balance while working with Magento 2 PHPAnnotation - Extends PhpStorm to support annotations in DocBlocks Symfony Support - Support for Symfony framework / components. After configuring the interpreter, the next step is to set up the PHPStorm preferences for how to execute PHPUnit. Click the Use Composer autoloader option. Select the vendor/autoload.php file in your Magento 2 installation. Optionally select the dev/tests/unit/phpunit.xml.dist file as the Default configuration file.

In this second part of the series, I’m going to guide you how to start a debugging session, place a breakpoint and track the debugging progress. But before we begin, make sure that you have installed and set up Xdebug with PhpStorm.

Configure phpstorm for magento 2

Phpstorm Magento 2018

If you don’t know how to do it, please visit our instructions on Part 1 here.

Working on Xdebug

You can start a debugging session with PhpStorm either by clicking on the debug button (with a bug icon), or turn on debugging connection listening and let PhpStorm catch debugging requests from the browser. I personally prefer the second way, as it is convenient and easier to manage.

On the taskbar, go to Run -> Edit Configurations to enter the configuration window for your debug:

Click on the green plus button on the top left corner and choose PHP Web Application and fill in the necessary parameters. The Start URL is quite important, as it defines the start page when you start a new debug session with PhpStorm.

When it is done, click OK to save.

Now you can either:

Magento 2 Phpstorm Templates

  • Click on the green bug on the top right corner to get started.
  • Or you can switch on browser debugging and enable debug listening on PhpStorm, as follows:

For Chrome:

For Firefox:

In PhpStorm:

Now you will want to place a breakpoint where your code would stop. It looks like this:

When you runs the code, it would stop at the breakpoint and a debug window shows up.

As in the photo above, there is a white line that shows where your debug is, and the code in the white-line is not executed. On the bottom, the debug window show you all of the debugging flow, variables’ values, object’s properties, etc…

Phpstorm Magento 2 Code Style

While working on debug window, if you want to:

  • Execute the current code and go to the next line, press
  • Go into the current method, press
  • Step out, press
  • Stop debugging, continue the code flow, press
  • Stop the code flow and then terminate the debug, press

Magento 2 Phpstorm Xsd

Congrats! You just mastered an very important tool for developers. If you have any questions or problems about Xdebug, don’t mind leaving them in the comment section below.