0

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

iquellis
  • 979
  • 1
  • 8
  • 26
  • 1
    Cannot say for 100% that it's the issue (not using DDEV so do not know how accurate their instructions are) but on your first screenshot you have selected **phpunit.PHAR** option but pointing to PHPUnit **executable**... Do you know that `.../bin/phpunit` executable may not be a **PHAR** file at all? You better try "composer" option instead as that's what `phpunit/phpunit` in your composer.json stands for. If you are selecting the PHAR option then the file has to be PHAR file. – LazyOne Dec 29 '21 at 01:05
  • 1
    It seems that composer 2.2.* changed how phpunit gets installed, see https://twitter.com/StefanFroemken/status/1474215132544839683 - You may want to `ddev config --composer-version=2.1.14` until the new composer 2.2.x breakage settles out. – rfay Dec 29 '21 at 01:10
  • I have no idea about DDEV, but instead of using `/var/www/html/vendor/bin/phpunit` do `/var/www/html/vendor/autoload.php` and select the other option: `Use Composer autoloader`. That works all the time when using Docker + Composer (PHPUnit) – matiaslauriti Dec 29 '21 at 06:10
  • Thanks, @LazyOne actually I became a bit blind at 3am in the morning. – iquellis Dec 29 '21 at 14:41
  • @rfay: I am on composer-version 2.1.14. That's the current ddev default. – iquellis Dec 29 '21 at 14:41
  • @matiaslauriti When I set CLI interpreter to web and use composer autoloader, PHPStorm says Cannot parse PHPUnit version output and that it cannot open the file its location. However, the file is there and works when I peak in with ddev ssh. – iquellis Dec 29 '21 at 14:45

2 Answers2

1

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
Derick
  • 35,169
  • 5
  • 76
  • 99
froemken
  • 412
  • 2
  • 7
  • Thanks, but ddev uses composer 2.1.4 on its current version. When I try to change composer version to 2.2 oder 2.2-dev in .ddev/config.yaml and restart ddev, it fails. Using autoload as matiaslauriti suggested does not work either. Pointing to the phpunit executable does not work because PHPStorm expects the .phar-file. – iquellis Dec 29 '21 at 15:02
  • Composer 2.2.2 was released today. Use `ddev config --composer-version=2.2.2` and see how you do. – rfay Dec 29 '21 at 15:18
  • Composer 2.2.3 was released today with specific attention to this, https://github.com/composer/composer/releases/tag/2.2.3 – rfay Dec 31 '21 at 18:47
1

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

iquellis
  • 979
  • 1
  • 8
  • 26
  • Just for future reference, you can change ddev's composer version by editing composer_version in .ddev/config.yaml or with `ddev config --composer-version=2.2.2` for example. – rfay Dec 29 '21 at 23:55
  • @rfay I did. Did not work. ddev start didn't work then. But I cannot promise that I've overseen sth. – iquellis Jan 06 '22 at 14:46
  • The composer version would have nothing to do with `ddev start`. It's not in any way related to being able to start the project. Current composer is 2.2.3 also. – rfay Jan 07 '22 at 00:15