Test your Traits in PHPUnit

Code
<?php

use PHPUnit\Framework\TestCase;

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

class 
TraitsTest extends TestCase
{
    public function 
testMyMethod()
    {
        
$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: 168 ms, Memory: 12.00MB

OK (1 test, 0 assertions)
Used Versions
PHP 7.2, Zend 3.0, Symfony 4.0, Laravel 5.6, PHPUnit 6.5, Doctrine 2.8