<?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));
}
}