trait MyTrait
{
public function myTraitMethod()
{
return 'my trait method';
}
}
class MyClass
{
use MyTrait;
public function myClassMethod()
{
return $this->myTraitMethod();
}
}
class MyClassTest extends TestCase
{
public function test_myClassMethod()
{
$myMock = new class extends MyClass {
public function myTraitMethod()
{
return 'my mocked method';
}
};
static::assertSame('my mocked method', $myMock->myClassMethod());
}
}