简体   繁体   English

在IntelliJ / PhpStorm中更改测试根路径/模式

[英]Change the test root path/pattern in IntelliJ/PhpStorm

In my PhpStorm/IntelliJ I have a src folder and a test folder (marked correctly as this in project settings). 在我的PhpStorm / IntelliJ中,我有一个src文件夹和一个test文件夹(在项目设置中正确标记)。

My src files look like this for example: 我的src文件看起来像这样:

path: src/Project/Module/Business/Customer/Model.php
namespace: Project\Module\Business\Customer

Already given by the application there is the following structure for tests: 已经由应用程序给出了以下测试结构:

path: tests/ProjectTest/Module/Business/Customer/ModelTest.php
namespace: ProjectTest\Module\Business\Customer

As you can see, instead of the same namespace structure under tests, the Namespace unfortunately begins with "ProjectTest". 正如您所看到的,命名空间不仅仅是在测试中使用相同的命名空间结构,而是以“ProjectTest”开头。

The problem: Whenever I want to automatically create a test out of the source class it uses the wrong path like this: 问题:每当我想从源类中自动创建测试时,它使用错误的路径,如下所示:

path: tests/Project/Module/Business/Customer/ModelTest.php
namespace: Project\Module\Business\Customer

and I have to correct that manually. 我必须手动纠正。 This extra effort makes the "automatically create a test file" useless for me. 这种额外的努力使“自动创建测试文件”对我来说毫无用处。

Is it possible to say IntelliJ/PhpStorm that it should use "ProjectTest" instead of "Project" for tests? 是否可以说IntelliJ / PhpStorm应该使用“ProjectTest”代替“Project”进行测试?

How to solve this? 怎么解决这个?

I found this article https://blog.jetbrains.com/phpstorm/2014/04/psr-0-psr-4-and-sourcetest-root-support-in-phpstorm-8-eap/ but I can't figure out if this applicable for my use case. 我发现这篇文章https://blog.jetbrains.com/phpstorm/2014/04/psr-0-psr-4-and-sourcetest-root-support-in-phpstorm-8-eap/但我无法想象如果这适用于我的用例。 I didn't have success with this, but maybe someone can give me a hint. 我没有成功,但也许有人可以给我一个提示。

As far as I'm aware it's not yet possible (at least for PHPUnit and PHPSpec): 据我所知,它还不可能(至少对于PHPUnit和PHPSpec):

Watch these tickets (star/vote/comment) to get notified on any progress: 观看这些门票(星级/投票/评论)以获得任何进展的通知:

Also check related tickets as well. 还要检查相关的门票。

How to solve it? 怎么解决? Well first of all, but this might be subjective, you could use the same namespace. 首先,但这可能是主观的,您可以使用相同的命名空间。 In my understanding the tests belong therein but I also know that others do this differently. 在我的理解中,测试属于其中,但我也知道其他人做的不同。 I don't think so because this would probably fix your problem but by design - the tests are part of the project. 我不这么认为,因为这可能会解决你的问题但是通过设计 - 测试是项目的一部分。

Regardless of the question of how to name the root name in a namespace for tests, I can also suggest to support that namespace in the composer.json file for autoload-dev . 无论如何在命名空间中为测试命名根名称的问题,我还建议在autoload-devcomposer.json文件中支持该命名空间。

Phpstorm has composer support and can read out the namespaces root and map it to the concrete directories which it otherwise could not. Phpstorm具有作曲家支持,可以读出命名空间根目录并将其映射到具体目录,否则它就不能。 I can not tell you if this actually solves your problem, however it's not wrong to have it defined in your projects Composer file and otherwise check the PSR root paths of your IDE so that namespace mapping to directories is set up properly. 我不能告诉你这是否真的解决了你的问题,但是在你的项目Composer文件中定义它并没有错,否则检查你的IDE的PSR根路径,以便正确设置命名空间映射到目录。


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM