Search code examples
macosphpunitphpstormddev

DDEV/Laravel/PHPUnit: Problems with setup in PhpStorm


Using Laravel with DDEV/Docker on a Mac, I am stuck getting PhpStorm to run directly PHPUnit with coverage. I am following these instructions: https://ddev.readthedocs.io/en/stable/users/topics/phpstorm/

I started the setup with

curl -s "https://laravel.build/myproject?with=mysql,redis,memcached" | bash

Everything's is working fine, including debugging with Xdebug after I turned on Xdebug with

ddev xdebug on

PHPUnit works fine via console as well:

ddev exec phpunit 

Composer version is 2.1.4.

Following the instructions named above, I am stuck at point 6.

PhpStorm does not find PHPUnit

What am I missing out? PHPUnit is located within the directory and it is composer-installed as well:

composer.json for PHPUnit


Solution

  • Thanks to all of you guys, I really appreciate your help.

    Here is how I solved it:

    1. I installed ddev-edge to avoid composer 2.1.x. I could not change it to 2.2 in config.yaml without failing ddev to restart when using stable version of ddev. It only worked on an active docker instance.
    2. Then configurated ddev to use latest PHP-version 8.1 (for a new project from scratch, it makes sense anyway).
    3. Then the error with PHPUnit changed to an error telling me that the PHP version is too old for the PHPUnit version. That was because PHPStorm automatically picked PHP 7.4 as default when connecting to Docker and checking the CLI remote interpreter.
    4. So I changed the PHP executable from "php" to "php8.1"

    See screenshots. Now running PHPUnit from PHPStorm works fine, even with coverage.

    setup test framework in PHPStorm PHP remote executable in PHPStorm