Passing parameters to PHPUnit(将参数传递给 PHPUnit)
问题描述
我开始编写 PHPUnit 测试,我希望在开发人员的机器和我们的服务器上运行这些测试.开发人员机器的设置与服务器不同,甚至彼此不同.
I'm starting to write PHPUnit tests and I'd like the tests to be run from developers machines as well as from our servers. Developers machines are set up differently than the servers and even differently from each other.
要在这些不同的地方运行,运行测试的人似乎必须指出运行的位置.然后测试可以查找运行它的机器的正确配置.
To run in these different places it seems to be the person that runs the test is going to have to indicate where it's being run. The test can then look up the proper config of the machine it's running on.
我在想象这样的事情:
phpunit.bat -X johns_laptop unittest.php
phpunit.bat -X johns_laptop unittest.php
或在 alpha 服务器上:
or on the alpha server:
phpunit -X alpha unittest.php
phpunit -X alpha unittest.php
在测试中,如果是X"(或其他)参数,我将能够获取该值,并且例如知道这台机器的应用程序根路径是什么.
In the test I would be able to get the value if the 'X' (or whatever it is) parameter and know, for example, what the path to the app root is for this machine.
命令行似乎不允许这样做 - 还是我错过了什么?
It doesn't look like the command line allows for that - or have I missed something?
推荐答案
一种方法是检查 $argv 和 $argc.比如:
One way would be for you to inspect $argv and $argc. Something like:
<?php
require_once 'PHPUnit/Framework/TestCase.php';
class EnvironmentTest extends PHPUnit_Framework_TestCase {
public function testHasParam() {
global $argv, $argc;
$this->assertGreaterThan(2, $argc, 'No environment name passed');
$environment = $argv[2];
}
}
然后你可以像这样调用你的 phpunittest:
Then you can call your phpunittest like this:
phpunit EnvironmentTest.php my-computer
这篇关于将参数传递给 PHPUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将参数传递给 PHPUnit
基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01