PHPUnit-Skelgen 1.2.0 不创建命名空间

标签 php testing phpunit

我附加了一个示例类,当我尝试为其生成测试文件时,在 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 方法。

最佳答案

您可以像这样为生成的测试类提供命名空间。

>phpunit-skelgen --test -- lib\Parameters\COMMAND_LINE COMMAND_LINE.class lib\Parameters\COMMAND_LINE_Test COMMAND_LINE.class.test

关于PHPUnit-Skelgen 1.2.0 不创建命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14697570/

相关文章:

php - 在函数中模拟 Propel 查询 (Symfony2)

javascript - SVG/矢量图室内导航路由

testing - 内联 Kotlin 方法没有覆盖报告

testing - Cucumber 和 JUnit 测试

phpunit xml 文件 (phpunit.xml)

PHP 代码覆盖率和 Selenium

php - Mysql查询从3个不同的表中获取一个用户ID的数据

php - 使用 .do 扩展名作为所有 php 文件的 .php 扩展名

php - 从 session 中的数组中取消设置项目

java - 如何测试 jdbc 中的更新方法