Skip to content

Instantly share code, notes, and snippets.

@mouson
Created August 23, 2019 06:23
Show Gist options
  • Save mouson/75230aa7c41c00622059ac8f59466632 to your computer and use it in GitHub Desktop.
Save mouson/75230aa7c41c00622059ac8f59466632 to your computer and use it in GitHub Desktop.
SampleTraitTest.php
<?php
use Mockery as m;
use PHPUnit\Framework\TestCase;
class SampleTest extends TestCase
{
protected function setUp()
{
parent::setUp();
}
protected function tearDown()
{
m::close();
}
/**
* @test
*/
public function testTrait()
{
/** @var SampleTraitDemo|m\Mock $target */
$target = m::mock(SampleTraitDemo::class)
->makePartial()
->shouldAllowMockingProtectedMethods();
$target->shouldReceive('thisIsATrait')
->andReturn('i am mock');
$expected = 'use Trait - i am mock';
$actual = $target->useTrait();
$this->assertSame($expected, $actual);
/** Assert */
}
}
trait ATrait
{
protected function thisIsATrait()
{
return 'a real trait';
}
}
class SampleTraitDemo
{
use ATrait;
public function useTrait()
{
return ('use Trait - ' . $this->thisIsATrait());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment