Skip to content

Instantly share code, notes, and snippets.

@mouson
Created June 16, 2017 10:00
Show Gist options
  • Save mouson/47742cb6def1166fa76b815246f46a83 to your computer and use it in GitHub Desktop.
Save mouson/47742cb6def1166fa76b815246f46a83 to your computer and use it in GitHub Desktop.
Use Mockery mock class and alias static method
<?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