PhpStorm中的PHPUnit引导程序 [英] PHPUnit bootstrap in PhpStorm

查看:272
本文介绍了PhpStorm中的PHPUnit引导程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Zend Framework 2,我想在PhpStorm 5.0.4中运行我所有模块的测试。我已经设置了PhpStorm以检查 myproject / module 中的测试,并且它成功找到了我的测试。问题是它没有在每个模块中读取我的配置文件,这是必需的(它指向一个引导程序文件)。

I am working with Zend Framework 2 and I want to run tests for all of my modules in PhpStorm 5.0.4. I have PhpStorm set up to check for tests in myproject/module and it successfully finds my tests. The problem is that it doesn't read my configuration file within each module, which is needed (it points to a bootstrap file).

这是一个目录结构模块(来源):

Here is the directory structure for a module (source):

/module
    /User
        /tests
            /UserTest
                /Model
                    /UserTest.php
            Bootstrap.php
            phpunit.xml.dist
            TestConfig.php.dist

当我运行测试时,它给了我一个错误,因为 Bootstrap.php 在运行 UserTest之前没有运行.PHP 。所有文件都是正确的,因为如果我 cd / myproject / module / User / tests / 并运行<在终端内code> phpunit ,它运行正常。

When I run the test, it gives me an error because Bootstrap.php is not run prior to running UserTest.php. All of the files are correct, because if I cd to /myproject/module/User/tests/ and run phpunit within the Terminal, it works fine.

我希望它能够使用配置(从而引导)每个模块。我尝试使用带有相对路径的 - configuration 选项,但我无法使其工作。

I would like it to use the configuration (and thereby bootstrap) within each module. I tried to use the --configuration option with a relative path, but I couldn't get it to work.

这是我当前的配置:

有关如何在测试模块时运行配置文件(和引导程序)的任何指示?也就是说,模块有自己的配置文件和引导程序。

Any pointers on how I can run the configuration file (and bootstrap) when a module is being tested? That is, a module has its own configuration file and bootstrap.

提前致谢。

推荐答案

PHP Storm 7假设您只需要一个默认的bootstrap文件,因此不会为每个PHPUnit测试配置直接启用单个的bootsrap文件。

PHP Storm 7 assumes that you will only need ONE default bootstrap file and thus does not enable individual bootsrap files DIRECTLY for each PHPUnit test configuration.

但是,zf2基于每个模块进行测试。因此,在将默认值设置为第一个模块后,其他模块将不起作用。解决这个问题的方法是

However, zf2 conducts tests on a per module basis. Thus, after you set the defaults to the first module the other modules don't work. The way around this is to


  1. 删除文件|设置中的默认选项| PHP | PHPUnit
    你不要必须删除默认配置文件,但您必须EMPTY OUT并取消选中默认引导程序文件。只需取消选中就不够了

  1. Remove the default options in File|Settings|PHP|PHPUnit You don't have to remove the default configuration file but you must EMPTY OUT and uncheck the default bootstrap file. Just unchecking will not be enough

Go Run | Edit Configurations(此框还有其他快捷方式)
对于每个模块,您必须创建一个测试配置。例如,您将拥有标准的应用程序模块,因此可以使用应用程序模块测试,可能是管理模块,然后是管理模块测试,

Go Run|Edit Configurations (there are other shortcuts to this box) For each module you have to create a test configuration. For example, you'll have the standard Application Module and thus an "Application Module Test" for it, maybe an Admin Module and then an "Admin Module Test" for that

对于每个测试(假设标准的zf2目录结构)

For each test (assuming standard zf2 directory structure)

a。测试范围:目录
b。目录:C:\wamp \ www \ PROJECT-NAME \module \ MODULE-NAME \ test
c。选中使用备用配置文件:
d。输入C:\wamp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\在Test Runner options中,输入--bootstrap C:\ wamp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ >

a. Test Scope: Directory b. Directory: C:\wamp\www\PROJECT-NAME\module\MODULE-NAME\test c. Check "Use alternative configuration file:" d. Enter C:\wamp\www\PROJECT-NAME\module\MODULE-NAME\test\MODULE-NAMETest\phpunit.xml.dist e. In "Test Runner options", enter "--bootstrap C:\wamp\www\PROJECT-NAME\module\MODULE-NAME\test\MODULE-NAMETest\Bootstrap.php"


  1. 重复下一个模块

这里的问题是只要默认的bootsrap字段有一个条目,phpstorm将默认添加为--bootstrap选项,无论你放入特定情况下的Test Runner选项。因此,无论你做什么,每次都会运行错误的bootstrap文件,除了第一个/默认测试用例

The issue here is that as long as the default bootsrap field has an entry, phpstorm will add that as default as a --bootstrap option AFTER whatever you put in the case specific Test Runner options. So, no matter what you do, you end up running the wrong bootstrap file everytime except for the first/default test case

希望这有帮助

这篇关于PhpStorm中的PHPUnit引导程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆