将参数传递给PHPUnit(Passing parameters to PHPUnit)

编程入门 行业动态 更新时间:2024-10-25 20:29:39
参数传递给PHPUnit(Passing parameters to PHPUnit)

我开始编写PHPUnit测试,我希望测试从开发者机器以及从我们的服务器运行。 开发者机器的设置与服务器不同,甚至彼此不同。

要运行在这些不同的地方,似乎是运行测试的人将要指出它在哪里运行。 然后,测试可以查找正在运行的机器的正确配置。

我想象的是:

phpunit.bat -X johns_laptop unittest.php

或在Alpha服务器上:

phpunit -X alpha unittest.php

在测试中,如果“X”(或任何它)是参数,并且知道例如该机器的应用程序根目录的路径,我将能够获得该值。

它不像命令行允许 - 或者我错过了什么?

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.

I'm imagining something like:

phpunit.bat -X johns_laptop unittest.php

or on the alpha server:

phpunit -X alpha unittest.php

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。 就像是:

<?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:

phpunit EnvironmentTest.php my-computer

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]; } }

Then you can call your phpunittest like this:

phpunit EnvironmentTest.php my-computer

更多推荐

本文发布于:2023-07-27 05:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1285477.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   PHPUnit   parameters   Passing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!