Test your Traits in PHPUnit

Code
<?php

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

class 
TraitsTest extends PHPUnit_Framework_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: 183 ms, Memory: 2.00MB

OK (1 test, 0 assertions)
Used Versions
PHP 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6