The assertion methods are declared static and can be invoked from any context using PHPUnit\Framework\Assert::assertTrue(), for instance, or using $this->assertTrue() or self::assertTrue(), for instance, in a class that extends PHPUnit\Framework\TestCase.
A common question, especially from developers new to PHPUnit, is whether using $this->assertTrue() or self::assertTrue(), for instance, is “the right way” to invoke an assertion. The short answer is: there is no right way. And there is no wrong way, either. It is a matter of personal preference.
I see self::assert* more and more I even reverted some PR’s because of it to enforce consistency at least in the same package. Today I asked @mwop what to do in zendframework. This was his answer:
Whenever I see
self::, I just change those to
So basically the PR’s are like a ping pong game. Some are changing it to
self:: and the next PR others are changing it to
$this-> and vice versa.
self:: is used all over the place.
Without an official statement we can’t tell contributors what to use in their PR’s. And from experience I know a quote from a private slack group is not good enough to stop the discussion