Using PHPUnit and Xdebug with Local Beach and PhpStorm

Configure the Local Beach PHP interpreter for PhpStorm


  1. Go to Settings/Preferences (⌘,), then go to Languages & Frameworks | PHP
  2. On the PHP page click […] next to the CLI Interpreter list
  3. In the CLI Interpreters dialog, click  [+] in the left-hand pane, then choose From Docker... from the popup menu
  4. In the Configure Remote PHP Interpreter dialog choose Docker
  5. Provide the PHP interpreter connection parameters
    • As Server choose "Docker" 
    • As Image name use flownative/beach-php:7.4 (or the respective PHP version you use in your project)
    • Check that the PHP executable / PHP version is detected correctly (might take a while, if PhpStorm needs to download the Docker image first). There's a small [i] icon above the "Debugger: Xdebug" label which allows you to display some phpinfo() output. If the [i] icon is disabled, click on the reload icon (next to it) first
  6. open the Docker container mapping dialog and adjust the container path to  /application. You may also want to raise the PHP memory limit by adding the environment variable PHP_MEMORY_LIMIT with the desired value

  7. choose the PHP Runtime tab and click on Sync Extensions with Interpreter
    

Configure PHPUnit

  1. Go to Languages & Frameworks > PHP > Test Frameworks
  2. Add PHPUnit by Remote Interpreter and choose the Docker-based interpreter you configured previously
    
  3. Configure the PHPUnit remote interpreter like in the following screenshots. Especially make sure to point to the correct default configuration file and default bootstrap file
    

  4. If you like, adjust the color scheme for line coverage annotations:
    

  5. Test your setup by running a unit test case. In order to do that, right-click on a test case file and select "Run 'YourTestCaseName' (PHPUnit)"

  6. See the test results: