Created
August 23, 2019 06:23
-
-
Save mouson/75230aa7c41c00622059ac8f59466632 to your computer and use it in GitHub Desktop.
SampleTraitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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