Running PHPUnit in Intellij with docker remote interpreter from docker-compose expects project in “/opt/project”

北慕城南 提交于 2020-06-28 04:20:13

问题


I have a PHP symfony project loaded in IntelliJ (2019.3.2, Build #IU-193.6015.39) with the following structure (left out irrelevant files like README, etc):

<project_root>
+- src/
+- tests/
+- vendor/
|  +- autoload.php    
+- .env
+- composer.json
+- composer.lock
+- docker-compose.yml
+- Dockerfile
+- phpunit.xml
+- phpunit-custom.xml

The project interpreter is set to use remote docker (Docker for Mac) by docker-compose and IntelliJ detects the interpreter and debugger correctly:

docker-compose.yml has the following structure:

version: "2"

services:
    app:
        build: .
        env_file:
            - ./.env
        ports:
            - 8888:80
        volumes:
            - ./:/var/www/
            - .docker/app-dev/nginx/fastcgi-timeouts.conf:/etc/nginx/fastcgi-timeouts.conf
            - .docker/app-dev/php/conf.d/00_opcache.ini:/etc/php/conf.d/00_opcache.ini
            - .docker/app-dev/php/conf.d/30_xdebug.ini:/etc/php/conf.d/30_xdebug.ini
            - .docker/app-dev/php/php-fpm-settings.conf:/etc/php/php-fpm-settings.conf

    db:
        image: mysql:5.6
        environment:
            MYSQL_DATABASE: project_database
            MYSQL_USER: user
            MYSQL_PASSWORD: password
            MYSQL_ROOT_PASSWORD: master_password
        ports:
            - 3306:3306
        volumes:
            - mysql-data:/var/lib/mysql:delegated
            - .docker/db/mysqld.cnf:/etc/mysql/conf.d/mysqld.cnf
            - .docker/db/000-structure.sql:/docker-entrypoint-initdb.d/000-structure.sql
            - .docker/db/001-data.sql:/docker-entrypoint-initdb.d/001-data.sql
            - .docker/db/002-test-data.sql:/docker-entrypoint-initdb.d/002-test-data.sql

volumes:
    mysql-data:

So the project is mounted into the container's /var/www. After spinning up the project with docker-compose up -d it is accessible on http://localhost:8888 as expected. But running the unit-tests through IntelliJ does not work as the resulting command expects the configuration in /opt/project folder of the container:

[docker-compose://[/Users/me/projects/symfony_with_db/docker-compose.yml]:app/]:php /opt/.phpstorm_helpers/phpunit.php --configuration /opt/project/phpunit-custom.xml
Could not read "/opt/project/phpunit-custom.xml".

Process finished with exit code 1

Whereas the path to the configuration-file has to be provided as an absolute path in the UI.

Entering the project-relative path does not work. So there seems to be no way to tell IntelliJ to look into the path, where the project is actually mounted.


回答1:


I have a similar issue and I could't find any option in Intellij settings, so I need to manually change paths in .idea directory. Try search for /opt/project inside .idea directory and replace it with /var/www.

In my case, this issue was caused by the Python plugin in my Intellij Ultimate 2019.3



来源:https://stackoverflow.com/questions/60337001/running-phpunit-in-intellij-with-docker-remote-interpreter-from-docker-compose-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!