Test your Traits in PHPUnit

Code
<?php

use PHPUnit\Framework\TestCase;

trait 
MyTrait
{
    public function 
traitMethod(int $int) : int
    
{
        return 
$int 2;
    }
}

class 
TraitsTest extends TestCase
{
    public function 
testMyMethod() : void
    
{
        
$mock $this->getMockBuilder('MyTrait')
            ->
getMockForTrait();
        
        
$this->assertSame(6$mock->traitMethod(3));
        
        
$mock2 $this->getMockBuilder('MyTrait')
            ->
setMethods(['traitMethod'])
            ->
getMockForTrait();
            
        
$mock2->expects($this->once())
            ->
method('traitMethod')
            ->
will($this->returnValue(3));
        
        
$this->assertSame(3$mock2->traitMethod(3));
    }
}
Result
Time: 00:00.007, Memory: 18.00 MB

OK (1 test, 0 assertions)
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8