Created
June 16, 2017 10:00
-
-
Save mouson/47742cb6def1166fa76b815246f46a83 to your computer and use it in GitHub Desktop.
Use Mockery mock class and alias static method
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 StaticClassTest extends TestCase | |
{ | |
protected function tearDown() | |
{ | |
m::close(); | |
} | |
/** | |
* @test | |
*/ | |
public function testStaticClass() | |
{ | |
$mock = m::mock('alias:SomeStaticClass'); | |
$mock->shouldReceive('doSomething') | |
->once() | |
->andReturn('bar'); | |
$target = new SomeClassUsedStatic; | |
$this->assertEquals('bar', $target->useStaticMethod()); | |
} | |
} | |
//class SomeStaticClass | |
//{ | |
// public static function doSomething() | |
// { | |
// return 'foo'; | |
// } | |
//} | |
class SomeClassUsedStatic | |
{ | |
public function useStaticMethod() | |
{ | |
return SomeStaticClass::doSomething(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment