我开始编写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-computerOne 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更多推荐
发布评论