skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. With composer version 2.2 the phpunit executable in vendor/bin is not a symlink anymore. It‘s a PHP file which includes the original executable with help of stream-wrapper, but including phpunit is not allowed: https://github.com/sebastianbergmann/phpunit/issues/4096#issuecomment-585900398

    The bug is solved in composer:
    https://github.com/composer/composer/issues/10387#issuecomment-1000246631

    Use the following to get the latest dev version until this fix was official released:

    composer self-update --snapshot
    

    Further you can configure PhpStorm to use the original file instead:

    vendor/phpunit/phpunit/phpunit
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search