我附加了一个示例类,当我尝试使用 PHP 5.4.11 上的 PHPUnit-Skelgen 1.2.0 为其生成测试文件时,我没有将命名空间添加到文件中,因此测试失败。但是,所有方法都被拾取。
源文件:
<?php
namespace lib\Parameters;
class COMMAND_LINE implements \Iterator
{
private $CommandLineOptions_ = array();
/**
* Create the Command Line Options Class
* @param boolean $AddHelpOption - Optionally add the -h/--help option automatically
*/
public function __construct($AddHelpOption = TRUE)
{
if( $AddHelpOption == TRUE)
{
}
}
/**
* An internal pointer to the current position in the Command Line Options
* @var integer
*/
protected $Position = 0;
/**
* This method takes the pointer back to the beginning of the dataset to restart the iteration
*/
public function rewind()
{
$this->Position = 0;
}
/**
* This method returns the value at the current position of the dataset
* @return COMMAND_LINE_OPTION
*/
public function current()
{
return $this->CommandLineOptions_[$this->Position];
}
/**
* Return the current value of the pointer
* @return integer
*/
public function key()
{
return $this->Position;
}
/**
* Move the pointer to the next element
*/
public function next()
{
++ $this->Position;
}
/**
* Returns where the next item is valid or not
* @return boolean
*/
public function valid()
{
return isset($this->CommandLineOptions_[$this->Position]);
}
}
?>
命令行,当前目录中的类:
>phpunit-skelgen --test -- lib\Parameters\COMMAND_LINE COMMAND_LINE.class COMMAND_LINE_Test COMMAND_LINE.class.test
PHPUnit Skeleton Generator 1.2.0 by Sebastian Bergmann.
Wrote skeleton for "COMMAND_LINE_Test" to "COMMAND_LINE.class.test".
创建的测试类具有功能,但没有命名空间:
<?php
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-04 at 17:50:23.
*/
class COMMAND_LINE_Test extends PHPUnit_Framework_TestCase
{
/**
* @var COMMAND_LINE
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new COMMAND_LINE;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @covers lib\Parameters\COMMAND_LINE::rewind
* @todo Implement testRewind().
*/
public function testRewind()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers lib\Parameters\COMMAND_LINE::current
* @todo Implement testCurrent().
*/
public function testCurrent()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers lib\Parameters\COMMAND_LINE::key
* @todo Implement testKey().
*/
public function testKey()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers lib\Parameters\COMMAND_LINE::next
* @todo Implement testNext().
*/
public function testNext()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers lib\Parameters\COMMAND_LINE::valid
* @todo Implement testValid().
*/
public function testValid()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}
从具有相对文件路径的根目录尝试它也不起作用。如果我使用完全限定的命名空间(我不能,因为我需要是相对的),则找不到该类,并且只找到 setUp 和 tearDown 方法。