PHPUnit - Use $this or self for static methods?

前端 未结 3 1573
执念已碎
执念已碎 2020-12-09 08:49

I don\'t want to write a long text, because it is a short question. PHPUnit tests contain several methods that are static. For example all those \\PHPUnit\\Framework\\Assert

3条回答
  •  天命终不由人
    2020-12-09 09:23

    PHPUnit 4.8.9: vendor/phpunit/phpunit/src/Framework/Assert.php:

    /**
     * Asserts that a condition is true.
     *
     * @param bool   $condition
     * @param string $message
     *
     * @throws PHPUnit_Framework_AssertionFailedError
     */
    public static function assertTrue($condition, $message = '')
    {
        self::assertThat($condition, self::isTrue(), $message);
    }
    

    Technically static::assertTrue() is correct, but the common usage of the assert methods is $this->assertTrue().

提交回复
热议问题