0

サンプルクラスを添付しました。PHP5.4.11でPHPUnit-Skelgen1.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メソッドのみが見つかります。

4

1 に答える 1

1

このように、生成されたテストクラスに名前空間を与えることができます。

>phpunit-skelgen --test -- lib\Parameters\COMMAND_LINE COMMAND_LINE.class lib\Parameters\COMMAND_LINE_Test COMMAND_LINE.class.test
于 2013-02-19T07:31:23.000 に答える