无法在PhpStorm中运行单个PHP测试(在Docker容器内),错误:无法打开文件“/item/child”,返回上一页

wa7juj8i  于 2022-11-22  发布在  Docker
关注(0)|答案(1)|浏览(66)

运行所有测试(工作)

当我在PhpStorm中运行 all tests 时,我会进入“Run”〉〉“MyProject PhpUnit Test”。
[docker-compose://[/path/to/my/project/docker-compose.yml]:php/]:/usr/local/bin/php /var/www/docroot/bin/phpunit --configuration /var/www/docroot/phpunit.xml.dist --teamcity
在PhpStorm中运行所有测试,到目前为止一切顺利!

运行单一测试(不工作)

如果转到单个测试,请右键单击测试名称,然后单击:
“执行测试将捷径附加至答案...”
快捷键:CTRLShiftR
然后输出并运行如下命令:
[docker-compose://[/path/to/my/project/docker-compose.yml]:php/]:/usr/local/bin/php /var/www/docroot/bin/phpunit --configuration /var/www/docroot/phpunit.xml.dist --filter "/(App\\Tests\\Entity\\CardTest::testAppendShortToAnswers)( .*)?$/" --test-suffix CardTest.php /path/to/my/project/tests/Entity --teamcity
并立即抛出错误:

Cannot open file "/path/to/my/project/tests/Entity.php".

Process finished with exit code 1

我假设这是因为它试图访问该文件,而不是从我的Docker-container内部,而是从我的主机。
我如何解决这个问题,这样我就可以在PhpStorm中运行一个测试了?

有关设置的信息

我在设置PhpStorm来运行测试时遇到了一些困难,但您可以看到the big problem I had (and the solution) alongside links and whatnot here
我用的是Mac,这是一个Symfony项目,其中PhpUnit位于项目根目录(/bin/phpunit)的一个文件夹中,所以它不是通过Composer安装的。
我不知道为什么要这样设置。

解决方案尝试1:从终端运行单个测试

如果我转到终端并运行以下命令:

docker-compose exec php /usr/local/bin/php /var/www/docroot/bin/phpunit --filter testAppendShortToAnswers

但是我最好直接从PhpStorm运行它,这样我就可以使用CTRLShiftR快捷键了。

cngwdvgl

cngwdvgl1#

@LazyOne给我指出了正确的方向。
这是因为我有一个路径Map设置不正确。
因此,通过改变它,它现在起作用了:

"我有过这样的经历“

/Users/MYUSERNAME/Code/MYPROJECTNAME/some-wrong-project   ->  /var/www/docroot

并将其修改为:

/Users/MYUSERNAME/Code/MYPROJECTNAME/the-project-I-am-working-on  ->  /var/www/docroot

相关问题