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: 245 ms, Memory: 14.00 MB

OK (1 test, 0 assertions)
Used Versions
PHP 7.3, Zend 3.0, Symfony 4.3, Laravel 5.8, PHPUnit 8.0, Doctrine 2.10