3

私はプレースホルダー用に時々空の関数を使用するのが好きです(私のチームは常にどこかにコンストラクターが存在する必要があることを知っているので、コンストラクターの偶発的な重複を避けるのに役立つため、主に空のコンストラクターです)。

また、クラスのすべてのメソッドに対して少なくとも1つのテストを行うのが好きです(主に、チームを相手にするのは簡単なルールだからです)。

私の質問は単純です。「テストなし」の警告を防ぐために、これらの空のテストメソッドに何を入れるべきか。

$ this-> assertTrue(true)を実行するだけで、問題なく動作することがわかっています。しかし、もっと公式で適切なものがあるかどうか疑問に思いました(できれば、実行されたテストの数にメソッドがカウントされず、人為的に少し膨らませるようなものが望ましいです)。

ありがとう。

4

2 に答える 2

4

これを試して :

/**
 * @covers Controllers\AdminController::authenticate
 * @todo   Implement testAuthenticate().
 */
public function testAuthenticate()
{
    // Remove the following lines when you implement this test.
    $this->markTestIncomplete(
      'This test has not been implemented yet.'
    );
}
于 2013-01-30T22:52:51.163 に答える
0

関数でリフレクションクラスを試し、メソッドがそこにあることを確認します。次に、テストは、メソッドが存在する(空であるかどうかに関係なく)ことである可能性があり、警告なしで合格します。

class MethodExistsTest extends \PHPUnit_Framework_TestCase
{
    protected $FOO;

    protected function setUp()
    {
        $this->FOO = new \FOO();
    }

    /**
     * @covers \FOO::Bar
     */
    public function testEmptyMethodBarExists()
    {
        $ReflectionObject = new \ReflectionObject($this->FOO);
        $this->assertTrue($ReflectionObject->getMethod('Bar'));
    }

    /**
     * @covers \FOO::__construct
     */
    public function testConstructorExists()
    {
        $ReflectionObject = new \ReflectionObject($this->FOO);
        $this->assertNotNull($ReflectionObject->getConstructor());
    }
}
于 2013-01-31T15:50:10.817 に答える