PHPUnit 中的全局常量

发布于 2024-09-27 03:18:13 字数 329 浏览 0 评论 0原文

有没有一种方法可以在 PHPUnit 中定义可在所有测试套件中使用的常量?例如,假设我希望能够有时在 jason.dev.mysite.com 上进行测试,有时在 jim.dev.mysite.com 上进行测试,并且可能会指定当我在要测试的站点上运行命令时。这样的事情可能吗?

我发现的最接近的是: http://www.phpunit.de /manual/3.4/en/appendixes.configuration.html

Is there a way to define constants in PHPUnit that can be used in all your test suites? For example, say I want to be able to test on jason.dev.mysite.com sometimes and jim.dev.mysite.com sometimes, and maybe specify when I run the command on which site I want to test. Is anything like this possible?

The closest thing I found was this: http://www.phpunit.de/manual/3.4/en/appendixes.configuration.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一梦等七年七年为一梦 2024-10-04 03:18:13

这应该在引导文件中。

检查此处:http://www.phpunit.de/manual/current/en/ textui.h​​tml 用于引导文件选项。

您还可以查看 setUp()setUpBeforeClass() 方法,但它们仅与一个测试类相关。

This should be in the bootstrap file.

Check here : http://www.phpunit.de/manual/current/en/textui.html for the bootstrap file option.

You can also check out the setUp() and setUpBeforeClass() methods, but they are related to one test class only.

森林很绿却致人迷途 2024-10-04 03:18:13

对于那些已经有了引导程序并且想要单独定义常量的人,请检查 XML 配置文件。该链接似乎会随着版本更新而定期更改,因此示例如下:

<phpunit bootstrap="../libraries/global/bootstrap.lib.php">
    <php>
        <env name="db_user" value="admin"/>
        <env name="db_pass" value="admin"/>
        <env name="db_host" value="127.0.0.1"/>
        <env name="db_port" value="1433"/>
        <const name="DEBUG" value="FALSE"/>
    </php>
    <testsuites>
        <testsuite name="role">
            <file>modules/role/role.test.php</file>
        </testsuite>
    </testsuites>
</phpunit>

For those who already have a bootstrap and are wanting to define a constant separately checkout the <php> tag in the XML Configuration file. The link seem to change on a regular basis with version updates so an example is:

<phpunit bootstrap="../libraries/global/bootstrap.lib.php">
    <php>
        <env name="db_user" value="admin"/>
        <env name="db_pass" value="admin"/>
        <env name="db_host" value="127.0.0.1"/>
        <env name="db_port" value="1433"/>
        <const name="DEBUG" value="FALSE"/>
    </php>
    <testsuites>
        <testsuite name="role">
            <file>modules/role/role.test.php</file>
        </testsuite>
    </testsuites>
</phpunit>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文