1

I'm trying to setup PHPUnit in PhpStorm, so I can run tests from inside my IDE.

I have Docker setup in PhpStorm, and I can see my containers in the 'Services'-tab and exec stuff in them, from inside PhpStorm.

And if I click Update button (the circular arrows) next to 'Path to script', then it throws the error:

Cannot parse PHPUnit version output: Could not open file: /var/www/docroot/vendor/phpunit/phpunit/phpunit

It can be seen here:

Docker test struggles - Cannot parse PHPUnit version

The overarching question

What is failing here? I'm guessing that PhpStorm is trying to access PHPUnit inside the Docker-container, but can't find that phpunit-file (from the error).

... Oh, yeah - and how do I fix it? :-)


Quick solution attempts and thoughts

  1. If I run this in my terminal: docker-compose exec php bin/phpunit --log-junit testresults.xml, then all the tests run. Great!

  2. If I, inside PhpStorm, right click the php-container and choose exec and paste in: php bin/phpunit --log-junit testresults.xml, then the tests all run in PhpStorm. Great!

  3. I could also try and find the phpunit.phar-file directly and point to that. But if I access the container (with docker-compose exec -i php /bin/bash) and then search for the file (with find . -name 'phpunit.phar') then nothing is found.

  4. Default configuration file is blank. I also tried setting that to: /Users/myusername/Code/myproject/phpunit.xml.dist. Same result.

  5. What if PHPUnit is installed in the php-image - and therefore not via Composer or something? Hmm... The only phpunit-line in the composer-file seem to be this: "symfony/phpunit-bridge": "^5.2", ...

Solution attempt 1: Check for the file

If I check for the file it's looking for in the vendor directory, then I can't seem to find the file it's looking for:

| vendor
  | ...
  | phpunit
    | php-timer
      | .github
      | src
      | tests
      | ... 
  | ...
  | ...

It looks like something is missing. But the tests can run inside the docker-container?! Hmm.!

And it's the same inside the container:

Docker test struggles - Cannot parse PHPUnit version

Links and resources

1 Answer 1

0

I figured it out!

It was because phpunit was located in a weird location inside my project. See here:

Solution to PHPUnit-location

Sign up to request clarification or add additional context in comments.

1 Comment

In my case I just needed to invalidate PhpStorm caches and restart: File > Invalidate Caches > Invalidate and Restart (PhpStorm version 2024.1.4)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.